blob: e39c9faa42a1fa199ec63cf2fc5a74ad1dafffe5 (
plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_
#define CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "components/wifi/network_properties.h"
namespace local_discovery {
namespace wifi {
// Convenience definition for users of this header, since ::wifi and
// local_discovery::wifi may conflict.
using ::wifi::NetworkProperties;
typedef std::vector<NetworkProperties> NetworkPropertiesList;
// Credentials for WiFi networks. Currently only supports PSK-based networks.
// TODO(noamsml): Support for 802.11X and other authentication methods.
struct WifiCredentials {
static WifiCredentials FromPSK(const std::string& psk);
std::string psk;
};
class WifiManagerFactory;
// Observer for the network list. Classes may implement this interface and call
// |AddNetworkListObserver| to be notified of changes to the visible network
// list.
class NetworkListObserver {
public:
virtual ~NetworkListObserver() {}
virtual void OnNetworkListChanged(const NetworkPropertiesList& ssid) = 0;
};
// A class to manage listing, connecting to, and getting the credentials of WiFi
// networks.
class WifiManager {
public:
typedef base::Callback<void(const NetworkPropertiesList& ssids)>
SSIDListCallback;
typedef base::Callback<void(bool success)> SuccessCallback;
typedef base::Callback<
void(bool success, const std::string& ssid, const std::string& password)>
CredentialsCallback;
virtual ~WifiManager() {}
static scoped_ptr<WifiManager> Create();
static void SetFactory(WifiManagerFactory* factory);
// Start the wifi manager. This must be called before any other method calls.
virtual void Start() = 0;
// Get the list of visible SSIDs in the vicinity. This does not initiate a
// scan, but merely gets the list of networks from the system.
virtual void GetSSIDList(const SSIDListCallback& callback) = 0;
// Request a scan for networks nearby.
virtual void RequestScan() = 0;
// Configure and connect to a network with a given SSID and
// credentials. |callback| will be called once the network is connected or
// after it has failed to connect.
virtual void ConfigureAndConnectNetwork(const std::string& ssid,
const WifiCredentials& credentials,
const SuccessCallback& callback) = 0;
// Connect to a configured network with a given network ID. |callback| will be
// called once the network is connected or after it has failed to connect.
virtual void ConnectToNetworkByID(const std::string& ssid,
const SuccessCallback& callback) = 0;
// Reequest the credentials for a network with a given network ID from the
// system. |callback| will be called with credentials if they can be
// retrieved. Depending on platform, this may bring up a confirmation dialog
// or password prompt.
virtual void RequestNetworkCredentials(
const std::string& internal_id,
const CredentialsCallback& callback) = 0;
// Add a network list observer. This observer will be notified every time the
// network list changes.
virtual void AddNetworkListObserver(NetworkListObserver* observer) = 0;
// Remove a network list observer.
virtual void RemoveNetworkListObserver(NetworkListObserver* observer) = 0;
private:
static scoped_ptr<WifiManager> CreateDefault();
};
class WifiManagerFactory {
public:
virtual ~WifiManagerFactory() {}
virtual scoped_ptr<WifiManager> CreateWifiManager() = 0;
};
} // namespace wifi
} // namespace local_discovery
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_WIFI_MANAGER_H_
|