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

Side by Side Diff: chromeos/network/cros_network_functions.h

Issue 11756002: Move cros_network_functions.cc to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes Created 7 years, 11 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
« no previous file with comments | « chromeos/chromeos.gyp ('k') | chromeos/network/cros_network_functions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CROS_NETWORK_FUNCTIONS_H_ 5 #ifndef CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_CROS_NETWORK_FUNCTIONS_H_ 6 #define CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
7 7
8 // This header is introduced to make it easy to switch from chromeos_network.cc 8 // This header is introduced to make it easy to switch from chromeos_network.cc
9 // to Chrome's own DBus code. crosbug.com/16557 9 // to Chrome's own DBus code. crosbug.com/16557
10 //
10 // All calls to functions in chromeos_network.h should be made through 11 // All calls to functions in chromeos_network.h should be made through
11 // functions provided by this header. 12 // functions provided by this header.
13 //
14 // DO NOT INCLUDE THIS HEADER DIRECTLY, THESE FUNCTIONS ARE BEING DEPRECATED.
15 // Contact stevenjb@chromium.org and/or see crbug.com/154852
12 16
13 #include <vector> 17 #include <vector>
14 18
15 #include "base/callback.h" 19 #include "base/callback.h"
16 #include "base/time.h" 20 #include "chromeos/chromeos_export.h"
17 #include "chrome/browser/chromeos/cros/network_ip_config.h" 21 #include "chromeos/network/network_ip_config.h"
22 #include "chromeos/network/network_util.h"
18 23
19 namespace base { 24 namespace base {
20 25
21 class DictionaryValue; 26 class DictionaryValue;
22 class Value; 27 class Value;
23 28
24 } // namespace base 29 } // namespace base
25 30
26 namespace chromeos { 31 namespace chromeos {
27 32
28 // Describes whether there is an error and whether the error came from
29 // the local system or from the server implementing the connect
30 // method.
31 enum NetworkMethodErrorType {
32 NETWORK_METHOD_ERROR_NONE = 0,
33 NETWORK_METHOD_ERROR_LOCAL = 1,
34 NETWORK_METHOD_ERROR_REMOTE = 2,
35 };
36
37 // Struct to represent a SMS.
38 struct SMS {
39 SMS();
40 ~SMS();
41 base::Time timestamp;
42 std::string number;
43 std::string text;
44 std::string smsc; // optional; empty if not present in message.
45 int32 validity; // optional; -1 if not present in message.
46 int32 msgclass; // optional; -1 if not present in message.
47 };
48
49 // Callback to be called when receiving a SMS. 33 // Callback to be called when receiving a SMS.
50 typedef base::Callback<void(const std::string& modem_device_path, 34 typedef base::Callback<void(const std::string& modem_device_path,
51 const SMS& message)> MonitorSMSCallback; 35 const SMS& message)> MonitorSMSCallback;
52 36
53 // Callback for asynchronous getters. 37 // Callback for asynchronous getters.
54 typedef base::Callback<void( 38 typedef base::Callback<void(
55 const std::string& path, 39 const std::string& path,
56 const base::DictionaryValue* properties)> NetworkPropertiesCallback; 40 const base::DictionaryValue* properties)> NetworkPropertiesCallback;
57 41
58 // Callback for network properties watchers. 42 // Callback for network properties watchers.
59 typedef base::Callback<void( 43 typedef base::Callback<void(
60 const std::string& path, 44 const std::string& path,
61 const std::string& key, 45 const std::string& key,
62 const base::Value& value)> NetworkPropertiesWatcherCallback; 46 const base::Value& value)> NetworkPropertiesWatcherCallback;
63 47
64 // Callback for methods that initiate an operation and return no data.
65 typedef base::Callback<void(
66 const std::string& path,
67 NetworkMethodErrorType error,
68 const std::string& error_message)> NetworkOperationCallback;
69
70 // Base class of signal watchers. 48 // Base class of signal watchers.
71 class CrosNetworkWatcher { 49 class CHROMEOS_EXPORT CrosNetworkWatcher {
72 public: 50 public:
73 virtual ~CrosNetworkWatcher() {} 51 virtual ~CrosNetworkWatcher() {}
74 52
75 protected: 53 protected:
76 CrosNetworkWatcher() {} 54 CrosNetworkWatcher() {}
77 }; 55 };
78 56
79 struct WifiAccessPoint {
80 WifiAccessPoint();
81
82 std::string mac_address; // The mac address of the WiFi node.
83 std::string name; // The SSID of the WiFi node.
84 base::Time timestamp; // Timestamp when this AP was detected.
85 int signal_strength; // Radio signal strength measured in dBm.
86 int signal_to_noise; // Current signal to noise ratio measured in dB.
87 int channel; // Wifi channel number.
88 };
89
90 typedef std::vector<WifiAccessPoint> WifiAccessPointVector;
91
92 // Activates the cellular modem specified by |service_path| with carrier 57 // Activates the cellular modem specified by |service_path| with carrier
93 // specified by |carrier|. 58 // specified by |carrier|.
94 // |carrier| is NULL or an empty string, this will activate with the currently 59 // |carrier| is NULL or an empty string, this will activate with the currently
95 // active carrier. 60 // active carrier.
96 // Returns false on failure and true on success. 61 // Returns false on failure and true on success.
97 bool CrosActivateCellularModem(const std::string& service_path, 62 CHROMEOS_EXPORT bool CrosActivateCellularModem(const std::string& service_path,
98 const std::string& carrier); 63 const std::string& carrier);
99 64
100 65
101 // Sets a property of a service to the provided value. 66 // Sets a property of a service to the provided value.
102 // Success is indicated by the receipt of a matching PropertyChanged signal. 67 // Success is indicated by the receipt of a matching PropertyChanged signal.
103 void CrosSetNetworkServiceProperty(const std::string& service_path, 68 CHROMEOS_EXPORT void CrosSetNetworkServiceProperty(
104 const std::string& property, 69 const std::string& service_path,
105 const base::Value& value); 70 const std::string& property,
71 const base::Value& value);
106 72
107 // Clears a property of a service. 73 // Clears a property of a service.
108 void CrosClearNetworkServiceProperty(const std::string& service_path, 74 CHROMEOS_EXPORT void CrosClearNetworkServiceProperty(
109 const std::string& property); 75 const std::string& service_path,
76 const std::string& property);
110 77
111 // Sets a property of a device to the provided value. 78 // Sets a property of a device to the provided value.
112 // Success is indicated by the receipt of a matching PropertyChanged signal. 79 // Success is indicated by the receipt of a matching PropertyChanged signal.
113 void CrosSetNetworkDeviceProperty(const std::string& device_path, 80 CHROMEOS_EXPORT void CrosSetNetworkDeviceProperty(
114 const std::string& property, 81 const std::string& device_path,
115 const base::Value& value); 82 const std::string& property,
83 const base::Value& value);
116 84
117 // Sets a property of an ip config to the provided value. 85 // Sets a property of an ip config to the provided value.
118 // Success is indicated by the receipt of a matching PropertyChanged signal. 86 // Success is indicated by the receipt of a matching PropertyChanged signal.
119 void CrosSetNetworkIPConfigProperty(const std::string& ipconfig_path, 87 CHROMEOS_EXPORT void CrosSetNetworkIPConfigProperty(
120 const std::string& property, 88 const std::string& ipconfig_path,
121 const base::Value& value); 89 const std::string& property,
90 const base::Value& value);
122 91
123 // Sets a property of a manager to the provided value. 92 // Sets a property of a manager to the provided value.
124 // Success is indicated by the receipt of a matching PropertyChanged signal. 93 // Success is indicated by the receipt of a matching PropertyChanged signal.
125 void CrosSetNetworkManagerProperty(const std::string& property, 94 CHROMEOS_EXPORT void CrosSetNetworkManagerProperty(const std::string& property,
126 const base::Value& value); 95 const base::Value& value);
127 96
128 // Deletes a remembered service from a profile. 97 // Deletes a remembered service from a profile.
129 void CrosDeleteServiceFromProfile(const std::string& profile_path, 98 CHROMEOS_EXPORT void CrosDeleteServiceFromProfile(
130 const std::string& service_path); 99 const std::string& profile_path,
100 const std::string& service_path);
131 101
132 // Sets up monitoring of the PropertyChanged signal on the shill manager. 102 // Sets up monitoring of the PropertyChanged signal on the shill manager.
133 // The provided |callback| will be called whenever a manager property changes. 103 // The provided |callback| will be called whenever a manager property changes.
134 CrosNetworkWatcher* CrosMonitorNetworkManagerProperties( 104 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkManagerProperties(
135 const NetworkPropertiesWatcherCallback& callback); 105 const NetworkPropertiesWatcherCallback& callback);
136 106
137 // Similar to MonitorNetworkManagerProperties for a specified network service. 107 // Similar to MonitorNetworkManagerProperties for a specified network service.
138 CrosNetworkWatcher* CrosMonitorNetworkServiceProperties( 108 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkServiceProperties(
139 const NetworkPropertiesWatcherCallback& callback, 109 const NetworkPropertiesWatcherCallback& callback,
140 const std::string& service_path); 110 const std::string& service_path);
141 111
142 // Similar to MonitorNetworkManagerProperties for a specified network device. 112 // Similar to MonitorNetworkManagerProperties for a specified network device.
143 CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties( 113 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
144 const NetworkPropertiesWatcherCallback& callback, 114 const NetworkPropertiesWatcherCallback& callback,
145 const std::string& device_path); 115 const std::string& device_path);
146 116
147 // Similar to MonitorNetworkManagerProperties for a specified network device. 117 // Similar to MonitorNetworkManagerProperties for a specified network device.
148 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, 118 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorSMS(
149 MonitorSMSCallback callback); 119 const std::string& modem_device_path,
120 MonitorSMSCallback callback);
150 121
151 // Connects to the service with the |service_path|. 122 // Connects to the service with the |service_path|.
152 // Service parameters such as authentication must already be configured. 123 // Service parameters such as authentication must already be configured.
153 // Note, a successful invocation of the callback only indicates that 124 // Note, a successful invocation of the callback only indicates that
154 // the connection process has started. You will have to query the 125 // the connection process has started. You will have to query the
155 // connection state to determine if the connection was established 126 // connection state to determine if the connection was established
156 // successfully. 127 // successfully.
157 void CrosRequestNetworkServiceConnect(const std::string& service_path, 128 CHROMEOS_EXPORT void CrosRequestNetworkServiceConnect(
158 const NetworkOperationCallback& callback); 129 const std::string& service_path,
130 const NetworkOperationCallback& callback);
159 131
160 // Retrieves the latest info for the manager. 132 // Retrieves the latest info for the manager.
161 void CrosRequestNetworkManagerProperties( 133 CHROMEOS_EXPORT void CrosRequestNetworkManagerProperties(
162 const NetworkPropertiesCallback& callback); 134 const NetworkPropertiesCallback& callback);
163 135
164 // Retrieves the latest info for a service. 136 // Retrieves the latest info for a service.
165 void CrosRequestNetworkServiceProperties( 137 CHROMEOS_EXPORT void CrosRequestNetworkServiceProperties(
166 const std::string& service_path, 138 const std::string& service_path,
167 const NetworkPropertiesCallback& callback); 139 const NetworkPropertiesCallback& callback);
168 140
169 // Retrieves the latest info for a particular device. 141 // Retrieves the latest info for a particular device.
170 void CrosRequestNetworkDeviceProperties( 142 CHROMEOS_EXPORT void CrosRequestNetworkDeviceProperties(
171 const std::string& device_path, 143 const std::string& device_path,
172 const NetworkPropertiesCallback& callback); 144 const NetworkPropertiesCallback& callback);
173 145
174 // Retrieves the list of remembered services for a profile. 146 // Retrieves the list of remembered services for a profile.
175 void CrosRequestNetworkProfileProperties( 147 CHROMEOS_EXPORT void CrosRequestNetworkProfileProperties(
176 const std::string& profile_path, 148 const std::string& profile_path,
177 const NetworkPropertiesCallback& callback); 149 const NetworkPropertiesCallback& callback);
178 150
179 // Retrieves the latest info for a profile service entry. 151 // Retrieves the latest info for a profile service entry.
180 void CrosRequestNetworkProfileEntryProperties( 152 CHROMEOS_EXPORT void CrosRequestNetworkProfileEntryProperties(
181 const std::string& profile_path, 153 const std::string& profile_path,
182 const std::string& profile_entry_path, 154 const std::string& profile_entry_path,
183 const NetworkPropertiesCallback& callback); 155 const NetworkPropertiesCallback& callback);
184 156
185 // Requests a wifi service not in the network list (i.e. hidden). 157 // Requests a wifi service not in the network list (i.e. hidden).
186 void CrosRequestHiddenWifiNetworkProperties( 158 CHROMEOS_EXPORT void CrosRequestHiddenWifiNetworkProperties(
187 const std::string& ssid, 159 const std::string& ssid,
188 const std::string& security, 160 const std::string& security,
189 const NetworkPropertiesCallback& callback); 161 const NetworkPropertiesCallback& callback);
190 162
191 // Requests a new VPN service. 163 // Requests a new VPN service.
192 void CrosRequestVirtualNetworkProperties( 164 CHROMEOS_EXPORT void CrosRequestVirtualNetworkProperties(
193 const std::string& service_name, 165 const std::string& service_name,
194 const std::string& server_hostname, 166 const std::string& server_hostname,
195 const std::string& provider_type, 167 const std::string& provider_type,
196 const NetworkPropertiesCallback& callback); 168 const NetworkPropertiesCallback& callback);
197 169
198 // Disconnects from network service asynchronously. 170 // Disconnects from network service asynchronously.
199 void CrosRequestNetworkServiceDisconnect(const std::string& service_path); 171 CHROMEOS_EXPORT void CrosRequestNetworkServiceDisconnect(
172 const std::string& service_path);
200 173
201 // Removes an exisiting network service (e.g. after forgetting a VPN). 174 // Removes an exisiting network service (e.g. after forgetting a VPN).
202 void CrosRequestRemoveNetworkService(const std::string& service_path); 175 CHROMEOS_EXPORT void CrosRequestRemoveNetworkService(
176 const std::string& service_path);
203 177
204 // Requests a scan of services of |type|. 178 // Requests a scan of services of |type|.
205 // |type| should be is a string recognized by shill's Manager API. 179 // |type| should be is a string recognized by shill's Manager API.
206 void CrosRequestNetworkScan(const std::string& network_type); 180 CHROMEOS_EXPORT void CrosRequestNetworkScan(const std::string& network_type);
207 181
208 // Requests enabling or disabling a device. 182 // Requests enabling or disabling a device.
209 void CrosRequestNetworkDeviceEnable(const std::string& network_type, 183 CHROMEOS_EXPORT void CrosRequestNetworkDeviceEnable(
210 bool enable); 184 const std::string& network_type,
185 bool enable);
211 186
212 // Enables or disables PIN protection for a SIM card. 187 // Enables or disables PIN protection for a SIM card.
213 void CrosRequestRequirePin(const std::string& device_path, 188 CHROMEOS_EXPORT void CrosRequestRequirePin(
214 const std::string& pin, 189 const std::string& device_path,
215 bool enable, 190 const std::string& pin,
216 const NetworkOperationCallback& callback); 191 bool enable,
192 const NetworkOperationCallback& callback);
217 193
218 // Enters a PIN to unlock a SIM card. 194 // Enters a PIN to unlock a SIM card.
219 void CrosRequestEnterPin(const std::string& device_path, 195 CHROMEOS_EXPORT void CrosRequestEnterPin(
220 const std::string& pin, 196 const std::string& device_path,
221 const NetworkOperationCallback& callback); 197 const std::string& pin,
198 const NetworkOperationCallback& callback);
222 199
223 // Enters a PUK to unlock a SIM card whose PIN has been entered 200 // Enters a PUK to unlock a SIM card whose PIN has been entered
224 // incorrectly too many times. A new |pin| must be supplied 201 // incorrectly too many times. A new |pin| must be supplied
225 // along with the |unblock_code| (PUK). 202 // along with the |unblock_code| (PUK).
226 void CrosRequestUnblockPin(const std::string& device_path, 203 CHROMEOS_EXPORT void CrosRequestUnblockPin(
227 const std::string& unblock_code, 204 const std::string& device_path,
228 const std::string& pin, 205 const std::string& unblock_code,
229 const NetworkOperationCallback& callback); 206 const std::string& pin,
207 const NetworkOperationCallback& callback);
230 208
231 // Changes the PIN used to unlock a SIM card. 209 // Changes the PIN used to unlock a SIM card.
232 void CrosRequestChangePin(const std::string& device_path, 210 CHROMEOS_EXPORT void CrosRequestChangePin(
233 const std::string& old_pin, 211 const std::string& device_path,
234 const std::string& new_pin, 212 const std::string& old_pin,
235 const NetworkOperationCallback& callback); 213 const std::string& new_pin,
214 const NetworkOperationCallback& callback);
236 215
237 // Proposes to trigger a scan transaction. For cellular networks scan result 216 // Proposes to trigger a scan transaction. For cellular networks scan result
238 // is set in the property Cellular.FoundNetworks. 217 // is set in the property Cellular.FoundNetworks.
239 void CrosProposeScan(const std::string& device_path); 218 CHROMEOS_EXPORT void CrosProposeScan(const std::string& device_path);
240 219
241 // Initiates registration on the network specified by network_id, which is in 220 // Initiates registration on the network specified by network_id, which is in
242 // the form MCCMNC. If the network ID is the empty string, then switch back to 221 // the form MCCMNC. If the network ID is the empty string, then switch back to
243 // automatic registration mode before initiating registration. 222 // automatic registration mode before initiating registration.
244 void CrosRequestCellularRegister(const std::string& device_path, 223 CHROMEOS_EXPORT void CrosRequestCellularRegister(
245 const std::string& network_id, 224 const std::string& device_path,
246 const NetworkOperationCallback& callback); 225 const std::string& network_id,
226 const NetworkOperationCallback& callback);
247 227
248 // Enables or disables the specific network device for connection. 228 // Enables or disables the specific network device for connection.
249 // Set offline mode. This will turn off all radios. 229 // Set offline mode. This will turn off all radios.
250 // Returns false on failure and true on success. 230 // Returns false on failure and true on success.
251 bool CrosSetOfflineMode(bool offline); 231 CHROMEOS_EXPORT bool CrosSetOfflineMode(bool offline);
252 232
253 // Gets a list of all the NetworkIPConfigs using a given device path, 233 // Gets a list of all the NetworkIPConfigs using a given device path,
254 // and returns the information via callback. 234 // and returns the information via callback.
255 void CrosListIPConfigs(const std::string& device_path, 235 CHROMEOS_EXPORT void CrosListIPConfigs(
256 const NetworkGetIPConfigsCallback& callback); 236 const std::string& device_path,
237 const NetworkGetIPConfigsCallback& callback);
257 238
258 // DEPRECATED, DO NOT USE: Use the asynchronous CrosListIPConfigs, above, 239 // DEPRECATED, DO NOT USE: Use the asynchronous CrosListIPConfigs, above,
259 // instead. 240 // instead.
260 // Gets a list of all the NetworkIPConfigs using a given device path. 241 // Gets a list of all the NetworkIPConfigs using a given device path.
261 // Optionally, you can get ipconfig-paths and the hardware address. Pass NULL as 242 // Optionally, you can get ipconfig-paths and the hardware address. Pass NULL as
262 // |ipconfig_paths| and |hardware_address| if you are not interested in these 243 // |ipconfig_paths| and |hardware_address| if you are not interested in these
263 // values. 244 // values.
264 bool CrosListIPConfigsAndBlock(const std::string& device_path, 245 CHROMEOS_EXPORT bool CrosListIPConfigsAndBlock(
265 NetworkIPConfigVector* ipconfig_vector, 246 const std::string& device_path,
266 std::vector<std::string>* ipconfig_paths, 247 NetworkIPConfigVector* ipconfig_vector,
267 std::string* hardware_address); 248 std::vector<std::string>* ipconfig_paths,
249 std::string* hardware_address);
268 250
269 // Refreshes the IP config |ipconfig_path| to pick up changes in 251 // Refreshes the IP config |ipconfig_path| to pick up changes in
270 // configuration, and renew the DHCP lease, if any. 252 // configuration, and renew the DHCP lease, if any.
271 void CrosRequestIPConfigRefresh(const std::string& ipconfig_path); 253 CHROMEOS_EXPORT void CrosRequestIPConfigRefresh(
254 const std::string& ipconfig_path);
272 255
273 // Reads out the results of the last wifi scan. These results are not 256 // Reads out the results of the last wifi scan. These results are not
274 // pre-cached in the library, so the call may block whilst the results are 257 // pre-cached in the library, so the call may block whilst the results are
275 // read over IPC. 258 // read over IPC.
276 // Returns false if an error occurred in reading the results. Note that 259 // Returns false if an error occurred in reading the results. Note that
277 // a true return code only indicates the result set was successfully read, 260 // a true return code only indicates the result set was successfully read,
278 // it does not imply a scan has successfully completed yet. 261 // it does not imply a scan has successfully completed yet.
279 bool CrosGetWifiAccessPoints(WifiAccessPointVector* result); 262 CHROMEOS_EXPORT bool CrosGetWifiAccessPoints(WifiAccessPointVector* result);
280 263
281 // Configures the network service specified by |properties|. 264 // Configures the network service specified by |properties|.
282 void CrosConfigureService(const base::DictionaryValue& properties); 265 CHROMEOS_EXPORT void CrosConfigureService(
283 266 const base::DictionaryValue& properties);
284 // Converts a |prefix_length| to a netmask. (for IPv4 only)
285 // e.g. a |prefix_length| of 24 is converted to a netmask of "255.255.255.0".
286 // Invalid prefix lengths will return the empty string.
287 std::string CrosPrefixLengthToNetmask(int32 prefix_length);
288
289 // Converts a |netmask| to a prefixlen. (for IPv4 only)
290 // e.g. a |netmask| of 255.255.255.0 is converted to a prefixlen of 24
291 int32 CrosNetmaskToPrefixLength(const std::string& netmask);
292 267
293 // Changes the active cellular carrier. 268 // Changes the active cellular carrier.
294 void CrosSetCarrier(const std::string& device_path, 269 CHROMEOS_EXPORT void CrosSetCarrier(const std::string& device_path,
295 const std::string& carrier, 270 const std::string& carrier,
296 const NetworkOperationCallback& callback); 271 const NetworkOperationCallback& callback);
297 272
298 } // namespace chromeos 273 } // namespace chromeos
299 274
300 #endif // CHROME_BROWSER_CHROMEOS_CROS_CROS_NETWORK_FUNCTIONS_H_ 275 #endif // CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
OLDNEW
« no previous file with comments | « chromeos/chromeos.gyp ('k') | chromeos/network/cros_network_functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698