1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75

ash / components / arc / net / arc_wifi_host_impl.h [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_COMPONENTS_ARC_NET_ARC_WIFI_HOST_IMPL_H_
#define ASH_COMPONENTS_ARC_NET_ARC_WIFI_HOST_IMPL_H_

#include "ash/components/arc/mojom/arc_wifi.mojom.h"
#include "ash/components/arc/session/connection_observer.h"
#include "base/files/scoped_file.h"
#include "base/threading/thread_checker.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
#include "components/keyed_service/core/keyed_service.h"

namespace content {
class BrowserContext;
}  // namespace content

namespace arc {

class ArcBridgeService;

// Private implementation of ArcWifiHost.
class ArcWifiHostImpl : public KeyedService,
                        public ConnectionObserver<mojom::ArcWifiInstance>,
                        public ash::NetworkStateHandlerObserver,
                        public mojom::ArcWifiHost {
 public:
  // Returns singleton instance for the given BrowserContext,
  // or nullptr if the browser |context| is not allowed to use ARC.
  static ArcWifiHostImpl* GetForBrowserContext(
      content::BrowserContext* context);
  static ArcWifiHostImpl* GetForBrowserContextForTesting(
      content::BrowserContext* context);

  // The constructor will register an Observer with ArcBridgeService.
  ArcWifiHostImpl(content::BrowserContext* context,
                  ArcBridgeService* arc_bridge_service);

  ArcWifiHostImpl(const ArcWifiHostImpl&) = delete;
  ArcWifiHostImpl& operator=(const ArcWifiHostImpl&) = delete;

  ~ArcWifiHostImpl() override;

  // Overridden from mojom::ArcWifiHost.
  void GetWifiEnabledState(GetWifiEnabledStateCallback callback) override;
  void SetWifiEnabledState(bool is_enabled,
                           SetWifiEnabledStateCallback callback) override;
  void StartScan() override;
  void GetScanResults(GetScanResultsCallback callback) override;

  // Overridden from ash::NetworkStateHandlerObserver.
  void ScanCompleted(const ash::DeviceState* /*unused*/) override;
  void OnShuttingDown() override;
  // This method is triggered when WiFi enabled state changes, while note that
  // different from the method name suggests, normally the WiFi Device is never
  // removed in the platform in spite of WiFi enabled states.
  void DeviceListChanged() override;

  // Overridden from ConnectionObserver<mojom::ArcWifiInstance>:
  void OnConnectionReady() override;
  void OnConnectionClosed() override;

  static void EnsureFactoryBuilt();

 private:
  const raw_ptr<ArcBridgeService>
      arc_bridge_service_;  // Owned by ArcServiceManager.

  THREAD_CHECKER(thread_checker_);
};

}  // namespace arc

#endif  // ASH_COMPONENTS_ARC_NET_ARC_WIFI_HOST_IMPL_H_