Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / local_discovery / wifi / wifi_manager.h
blobe39c9faa42a1fa199ec63cf2fc5a74ad1dafffe5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/wifi/network_properties.h"
15 namespace local_discovery {
17 namespace wifi {
19 // Convenience definition for users of this header, since ::wifi and
20 // local_discovery::wifi may conflict.
21 using ::wifi::NetworkProperties;
23 typedef std::vector<NetworkProperties> NetworkPropertiesList;
25 // Credentials for WiFi networks. Currently only supports PSK-based networks.
26 // TODO(noamsml): Support for 802.11X and other authentication methods.
27 struct WifiCredentials {
28 static WifiCredentials FromPSK(const std::string& psk);
30 std::string psk;
33 class WifiManagerFactory;
35 // Observer for the network list. Classes may implement this interface and call
36 // |AddNetworkListObserver| to be notified of changes to the visible network
37 // list.
38 class NetworkListObserver {
39 public:
40 virtual ~NetworkListObserver() {}
42 virtual void OnNetworkListChanged(const NetworkPropertiesList& ssid) = 0;
45 // A class to manage listing, connecting to, and getting the credentials of WiFi
46 // networks.
47 class WifiManager {
48 public:
49 typedef base::Callback<void(const NetworkPropertiesList& ssids)>
50 SSIDListCallback;
51 typedef base::Callback<void(bool success)> SuccessCallback;
52 typedef base::Callback<
53 void(bool success, const std::string& ssid, const std::string& password)>
54 CredentialsCallback;
56 virtual ~WifiManager() {}
58 static scoped_ptr<WifiManager> Create();
60 static void SetFactory(WifiManagerFactory* factory);
62 // Start the wifi manager. This must be called before any other method calls.
63 virtual void Start() = 0;
65 // Get the list of visible SSIDs in the vicinity. This does not initiate a
66 // scan, but merely gets the list of networks from the system.
67 virtual void GetSSIDList(const SSIDListCallback& callback) = 0;
69 // Request a scan for networks nearby.
70 virtual void RequestScan() = 0;
72 // Configure and connect to a network with a given SSID and
73 // credentials. |callback| will be called once the network is connected or
74 // after it has failed to connect.
75 virtual void ConfigureAndConnectNetwork(const std::string& ssid,
76 const WifiCredentials& credentials,
77 const SuccessCallback& callback) = 0;
79 // Connect to a configured network with a given network ID. |callback| will be
80 // called once the network is connected or after it has failed to connect.
81 virtual void ConnectToNetworkByID(const std::string& ssid,
82 const SuccessCallback& callback) = 0;
84 // Reequest the credentials for a network with a given network ID from the
85 // system. |callback| will be called with credentials if they can be
86 // retrieved. Depending on platform, this may bring up a confirmation dialog
87 // or password prompt.
88 virtual void RequestNetworkCredentials(
89 const std::string& internal_id,
90 const CredentialsCallback& callback) = 0;
92 // Add a network list observer. This observer will be notified every time the
93 // network list changes.
94 virtual void AddNetworkListObserver(NetworkListObserver* observer) = 0;
96 // Remove a network list observer.
97 virtual void RemoveNetworkListObserver(NetworkListObserver* observer) = 0;
99 private:
100 static scoped_ptr<WifiManager> CreateDefault();
103 class WifiManagerFactory {
104 public:
105 virtual ~WifiManagerFactory() {}
107 virtual scoped_ptr<WifiManager> CreateWifiManager() = 0;
110 } // namespace wifi
112 } // namespace local_discovery
114 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_