Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: chrome/utility/wifi/wifi_service.h

Issue 22295002: Base infrastructure for Networking Private API on Windows and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed (some) codereview comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #ifndef CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
6 #define CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
7
8 #include <list>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/values.h"
14
15 namespace wifi {
16
17 // WiFiService interface used by implementation of chrome.networkingPrivate
18 // JavaScript extension API.
19 class WiFiService {
20 public:
21 enum ConnectionState {
22 kConnectionStateConnected,
23 kConnectionStateNotConnected
24 };
25
26 enum NetworkType {
27 kNetworkTypeAll,
28 kNetworkTypeNone,
29 kNetworkTypeEthernet,
30 kNetworkTypeWiFi,
31 kNetworkTypeVPN,
32 kNetworkTypeCellular
33 };
34
35 typedef int32 Frequency;
36 enum FrequencyEnum {
37 kFrequencyUnknown = 0,
38 kFrequency2400 = 2400,
39 kFrequency5000 = 5000
40 };
41
42 typedef std::list<Frequency> FrequencyList;
43
44 enum Security {
45 kSecurityNone,
46 kSecurityUnknown,
47 kSecurityWPA,
48 kSecurityWPA_PSK,
49 kSecurityWEP_PSK
50 };
51
52 // Network Properties, used as result of |GetProperties| and
53 // |GetVisibleNetworks|.
54 // TODO(mef): Replace with |DictionaryValue| once onc_constants are moved into
55 // src/components.
56 struct NetworkProperties {
57 NetworkProperties();
58 ~NetworkProperties();
59
60 ConnectionState connection_state;
61 std::string guid;
62 std::string name;
63 std::string ssid;
64 std::string bssid;
65 NetworkType type;
66 Frequency frequency;
67 Security security;
68 // WiFi Signal Strength. 0..100
69 int32 signal_strength;
70 bool auto_connect;
71 FrequencyList frequency_list;
72
73 std::string json_extra; // Extra JSON properties for unit tests
74
75 scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const;
76 bool UpdateFromValue(const base::DictionaryValue& value);
77 static std::string MacAddressAsString(const uint8 mac_as_int[6]);
78 static bool OrderByType(const NetworkProperties& l,
79 const NetworkProperties& r);
80 };
81
82 typedef std::list<NetworkProperties> NetworkList;
83 typedef std::list<std::string> NetworkGuidList;
84
85 // An error callback used by both the configuration handler and the state
86 // handler to receive error results from the API.
87 typedef base::Callback<void(const std::string& error_name,
88 scoped_ptr<base::DictionaryValue> error_data)>
89 ErrorCallback;
90
91 typedef base::Callback<void(const std::string& network_guid,
92 const base::DictionaryValue& dictionary)>
93 DictionaryResultCallback;
94
95 typedef base::Callback<void(const std::string& network_guid,
96 const NetworkProperties& properties)>
97 NetworkPropertiesCallback;
98
99 typedef base::Callback<void(const NetworkList& network_list)>
100 NetworkListCallback;
101
102 typedef base::Callback<void(const std::string& service_path)>
103 StringResultCallback;
104
105 typedef base::Callback<void(const NetworkGuidList& network_guid_list)>
106 NetworkGuidListCallback;
107
108 virtual ~WiFiService() {}
109
110 // Get Properties of network identified by |network_guid|. Run |callback| on
111 // success, |error_callback| on failure.
112 virtual void GetProperties(const std::string& network_guid,
113 const NetworkPropertiesCallback& callback,
114 const ErrorCallback& error_callback) = 0;
115
116 // Get State of network identified by |network_guid|. Run |callback| on
117 // success, |error_callback| on failure. Not implemented except unit tests.
118 virtual void GetState(const std::string& network_guid,
119 const NetworkPropertiesCallback& callback,
120 const ErrorCallback& error_callback) = 0;
121
122 // Get Managed Properties of network identified by |network_guid|.
123 // Run |callback| on success, |error_callback| on failure. Not implemented
124 // except unit tests.
125 virtual void GetManagedProperties(const std::string& network_guid,
126 const DictionaryResultCallback& callback,
127 const ErrorCallback& error_callback) = 0;
128
129 // Set Properties of network identified by |network_guid|. Run |callback| on
130 // success, |error_callback| on failure. Not implemented except unit tests.
131 virtual void SetProperties(const std::string& network_guid,
132 const base::DictionaryValue& properties,
133 const StringResultCallback& callback,
134 const ErrorCallback& error_callback) = 0;
135
136 // Get list of visible networks. Run |callback| on success, |error_callback|
137 // on failure.
138 virtual void GetVisibleNetworks(const NetworkListCallback& callback,
139 const ErrorCallback& error_callback) = 0;
140
141 // Request network scan. Send |NetworkListChanged| event on completion.
142 virtual void RequestNetworkScan() = 0;
143
144 // Start connect to network identified by |network_guid|. Run |callback| on
145 // success, |error_callback| on failure. Send |NetworksChanged| event
146 // on completion.
147 virtual void StartConnect(const std::string& network_guid,
148 const StringResultCallback& callback,
149 const ErrorCallback& error_callback) = 0;
150
151 // Start disconnect from network identified by |network_guid|. Run |callback|
152 // on success, |error_callback| on failure. Send |NetworksChanged| event on
153 // completion.
154 virtual void StartDisconnect(const std::string& network_guid,
155 const StringResultCallback& callback,
156 const ErrorCallback& error_callback) = 0;
157
158 // Set |observer| to run when |NetworksChanged| event needs to be sent.
159 virtual void SetNetworksChangedObserver(
160 const NetworkGuidListCallback& observer) = 0;
161
162 // Set |observer| to run when |NetworkListChanged| event needs to be sent.
163 virtual void SetNetworkListChangedObserver(
164 const NetworkGuidListCallback& observer) = 0;
165
166 // Create instance of |WiFiService| for normal use. Creates mock service on
167 // non-Windows system.
168 static WiFiService* CreateService();
169 // Create instance of |WiFiService| for unit test use.
170 static WiFiService* CreateServiceMock();
171
172 protected:
173 WiFiService() {}
174
175 private:
176 DISALLOW_COPY_AND_ASSIGN(WiFiService);
177 };
178 } // namespace wifi
179 #endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698