OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_NETWORK_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/scoped_ptr.h" | |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/timer.h" | 18 #include "base/timer.h" |
18 #include "third_party/cros/chromeos_network.h" | 19 #include "third_party/cros/chromeos_network.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class DictionaryValue; | 22 class DictionaryValue; |
22 class Value; | 23 class Value; |
23 } | 24 } |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 | 27 |
28 class NativeNetworkParser; | |
29 class NativeNetworkDeviceParser; | |
30 | |
31 // This is the list of all implementation classes that are allowed | |
32 // access to the internals of the network library classes. | |
33 #define NETWORK_LIBRARY_IMPL_FRIENDS \ | |
34 friend class NetworkLibraryImplBase; \ | |
35 friend class NetworkLibraryImplCros; \ | |
36 friend class NetworkLibraryImplStub; | |
37 | |
38 // This is the list of all parsers that are allowed access to the | |
39 // internals of all the network library classes. All parsers should | |
40 // still access the internals through the set_ functions to allow | |
41 // these classes to evolve without also having to change all of the | |
42 // parsers. If you add a parser subclass, then you'll need to add it | |
43 // to this list. Subclasses that only need access to a particular | |
44 // class (e.g. WifiNetwork) should go under that class. | |
45 #define NETWORK_LIBRARY_PARSER_FRIENDS \ | |
46 friend class NetworkParser; \ | |
47 friend class NetworkDeviceParser; \ | |
48 friend class NativeNetworkParser; \ | |
49 friend class NativeNetworkDeviceParser; | |
50 | |
51 // This enumerates the various property indices that can be found in a | |
52 // dictionary being parsed. | |
53 enum PropertyIndex { | |
54 PROPERTY_INDEX_ACTIVATION_STATE, | |
55 PROPERTY_INDEX_ACTIVE_PROFILE, | |
56 PROPERTY_INDEX_ARP_GATEWAY, | |
57 PROPERTY_INDEX_AUTO_CONNECT, | |
58 PROPERTY_INDEX_AVAILABLE_TECHNOLOGIES, | |
59 PROPERTY_INDEX_CARRIER, | |
60 PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING, | |
61 PROPERTY_INDEX_CELLULAR_APN, | |
62 PROPERTY_INDEX_CELLULAR_APN_LIST, | |
63 PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN, | |
64 PROPERTY_INDEX_CHECK_PORTAL_LIST, | |
65 PROPERTY_INDEX_CONNECTABLE, | |
66 PROPERTY_INDEX_CONNECTED_TECHNOLOGIES, | |
67 PROPERTY_INDEX_CONNECTIVITY_STATE, | |
68 PROPERTY_INDEX_DEFAULT_TECHNOLOGY, | |
69 PROPERTY_INDEX_DEVICE, | |
70 PROPERTY_INDEX_DEVICES, | |
71 PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY, | |
72 PROPERTY_INDEX_EAP_CA_CERT, | |
73 PROPERTY_INDEX_EAP_CA_CERT_ID, | |
74 PROPERTY_INDEX_EAP_CA_CERT_NSS, | |
75 PROPERTY_INDEX_EAP_CERT_ID, | |
76 PROPERTY_INDEX_EAP_CLIENT_CERT, | |
77 PROPERTY_INDEX_EAP_CLIENT_CERT_NSS, | |
78 PROPERTY_INDEX_EAP_IDENTITY, | |
79 PROPERTY_INDEX_EAP_KEY_ID, | |
80 PROPERTY_INDEX_EAP_KEY_MGMT, | |
81 PROPERTY_INDEX_EAP_METHOD, | |
82 PROPERTY_INDEX_EAP_PASSWORD, | |
83 PROPERTY_INDEX_EAP_PHASE_2_AUTH, | |
84 PROPERTY_INDEX_EAP_PIN, | |
85 PROPERTY_INDEX_EAP_PRIVATE_KEY, | |
86 PROPERTY_INDEX_EAP_PRIVATE_KEY_PASSWORD, | |
87 PROPERTY_INDEX_EAP_USE_SYSTEM_CAS, | |
88 PROPERTY_INDEX_ENABLED_TECHNOLOGIES, | |
89 PROPERTY_INDEX_ERROR, | |
90 PROPERTY_INDEX_ESN, | |
91 PROPERTY_INDEX_FAVORITE, | |
92 PROPERTY_INDEX_FIRMWARE_REVISION, | |
93 PROPERTY_INDEX_FOUND_NETWORKS, | |
94 PROPERTY_INDEX_GUID, | |
95 PROPERTY_INDEX_HARDWARE_REVISION, | |
96 PROPERTY_INDEX_HOME_PROVIDER, | |
97 PROPERTY_INDEX_HOST, | |
98 PROPERTY_INDEX_IDENTITY, | |
99 PROPERTY_INDEX_IMEI, | |
100 PROPERTY_INDEX_IMSI, | |
101 PROPERTY_INDEX_IS_ACTIVE, | |
102 PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS, | |
103 PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_ID, | |
104 PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_SLOT, | |
105 PROPERTY_INDEX_L2TPIPSEC_PASSWORD, | |
106 PROPERTY_INDEX_L2TPIPSEC_PIN, | |
107 PROPERTY_INDEX_L2TPIPSEC_PSK, | |
108 PROPERTY_INDEX_L2TPIPSEC_USER, | |
109 PROPERTY_INDEX_MANUFACTURER, | |
110 PROPERTY_INDEX_MDN, | |
111 PROPERTY_INDEX_MEID, | |
112 PROPERTY_INDEX_MIN, | |
113 PROPERTY_INDEX_MODE, | |
114 PROPERTY_INDEX_MODEL_ID, | |
115 PROPERTY_INDEX_NAME, | |
116 PROPERTY_INDEX_NETWORKS, | |
117 PROPERTY_INDEX_NETWORK_TECHNOLOGY, | |
118 PROPERTY_INDEX_OFFLINE_MODE, | |
119 PROPERTY_INDEX_OPERATOR_CODE, | |
120 PROPERTY_INDEX_OPERATOR_NAME, | |
121 PROPERTY_INDEX_PASSPHRASE, | |
122 PROPERTY_INDEX_PASSPHRASE_REQUIRED, | |
123 PROPERTY_INDEX_PAYMENT_URL, | |
124 PROPERTY_INDEX_PORTAL_URL, | |
125 PROPERTY_INDEX_POWERED, | |
126 PROPERTY_INDEX_PRIORITY, | |
127 PROPERTY_INDEX_PRL_VERSION, | |
128 PROPERTY_INDEX_PROFILE, | |
129 PROPERTY_INDEX_PROFILES, | |
130 PROPERTY_INDEX_PROVIDER, | |
131 PROPERTY_INDEX_PROXY_CONFIG, | |
132 PROPERTY_INDEX_ROAMING_STATE, | |
133 PROPERTY_INDEX_SAVE_CREDENTIALS, | |
134 PROPERTY_INDEX_SCANNING, | |
135 PROPERTY_INDEX_SECURITY, | |
136 PROPERTY_INDEX_SELECTED_NETWORK, | |
137 PROPERTY_INDEX_SERVICES, | |
138 PROPERTY_INDEX_SERVICE_WATCH_LIST, | |
139 PROPERTY_INDEX_SERVING_OPERATOR, | |
140 PROPERTY_INDEX_SIGNAL_STRENGTH, | |
141 PROPERTY_INDEX_SIM_LOCK, | |
142 PROPERTY_INDEX_STATE, | |
143 PROPERTY_INDEX_SUPPORT_NETWORK_SCAN, | |
144 PROPERTY_INDEX_TECHNOLOGY_FAMILY, | |
145 PROPERTY_INDEX_TYPE, | |
146 PROPERTY_INDEX_UNKNOWN, | |
147 PROPERTY_INDEX_USAGE_URL, | |
148 PROPERTY_INDEX_WIFI_AUTH_MODE, | |
149 PROPERTY_INDEX_WIFI_FREQUENCY, | |
150 PROPERTY_INDEX_WIFI_HEX_SSID, | |
151 PROPERTY_INDEX_WIFI_HIDDEN_SSID, | |
152 PROPERTY_INDEX_WIFI_PHY_MODE, | |
153 }; | |
154 | |
27 // Connection enums (see flimflam/include/service.h) | 155 // Connection enums (see flimflam/include/service.h) |
28 enum ConnectionType { | 156 enum ConnectionType { |
29 TYPE_UNKNOWN = 0, | 157 TYPE_UNKNOWN = 0, |
30 TYPE_ETHERNET = 1, | 158 TYPE_ETHERNET = 1, |
31 TYPE_WIFI = 2, | 159 TYPE_WIFI = 2, |
32 TYPE_WIMAX = 3, | 160 TYPE_WIMAX = 3, |
33 TYPE_BLUETOOTH = 4, | 161 TYPE_BLUETOOTH = 4, |
34 TYPE_CELLULAR = 5, | 162 TYPE_CELLULAR = 5, |
35 TYPE_VPN = 6, | 163 TYPE_VPN = 6, |
36 }; | 164 }; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 ROAMING_STATE_ROAMING = 2, | 222 ROAMING_STATE_ROAMING = 2, |
95 }; | 223 }; |
96 | 224 |
97 // Device enums (see flimflam/include/device.h) | 225 // Device enums (see flimflam/include/device.h) |
98 enum TechnologyFamily { | 226 enum TechnologyFamily { |
99 TECHNOLOGY_FAMILY_UNKNOWN = 0, | 227 TECHNOLOGY_FAMILY_UNKNOWN = 0, |
100 TECHNOLOGY_FAMILY_CDMA = 1, | 228 TECHNOLOGY_FAMILY_CDMA = 1, |
101 TECHNOLOGY_FAMILY_GSM = 2 | 229 TECHNOLOGY_FAMILY_GSM = 2 |
102 }; | 230 }; |
103 | 231 |
232 // Type of a pending SIM operation. | |
233 enum SimOperationType { | |
234 SIM_OPERATION_NONE = 0, | |
235 SIM_OPERATION_CHANGE_PIN = 1, | |
236 SIM_OPERATION_CHANGE_REQUIRE_PIN = 2, | |
237 SIM_OPERATION_ENTER_PIN = 3, | |
238 SIM_OPERATION_UNBLOCK_PIN = 4, | |
239 }; | |
240 | |
104 // SIMLock states (see gobi-cromo-plugin/gobi_gsm_modem.cc) | 241 // SIMLock states (see gobi-cromo-plugin/gobi_gsm_modem.cc) |
105 enum SIMLockState { | 242 enum SimLockState { |
106 SIM_UNKNOWN = 0, | 243 SIM_UNKNOWN = 0, |
107 SIM_UNLOCKED = 1, | 244 SIM_UNLOCKED = 1, |
108 SIM_LOCKED_PIN = 2, | 245 SIM_LOCKED_PIN = 2, |
109 SIM_LOCKED_PUK = 3, // also when SIM is blocked, then retries = 0. | 246 SIM_LOCKED_PUK = 3, // also when SIM is blocked, then retries = 0. |
110 }; | 247 }; |
111 | 248 |
112 // SIM PinRequire states. Since PinRequire current state is not exposed as a | 249 // SIM PinRequire states. Since PinRequire current state is not exposed as a |
113 // cellular property, we initialize it's value based on the SIMLockState | 250 // cellular property, we initialize it's value based on the SimLockState |
114 // initial value. | 251 // initial value. |
115 // SIM_PIN_REQUIRE_UNKNOWN - SIM card is absent or SIMLockState initial value | 252 // SIM_PIN_REQUIRE_UNKNOWN - SIM card is absent or SimLockState initial value |
116 // hasn't been received yet. | 253 // hasn't been received yet. |
117 // SIM_PIN_REQUIRED - SIM card is locked when booted/wake from sleep and | 254 // SIM_PIN_REQUIRED - SIM card is locked when booted/wake from sleep and |
118 // requires user to enter PIN. | 255 // requires user to enter PIN. |
119 // SIM_PIN_NOT_REQUIRED - SIM card is unlocked all the time and requires PIN | 256 // SIM_PIN_NOT_REQUIRED - SIM card is unlocked all the time and requires PIN |
120 // only on certain operations, such as ChangeRequirePin, ChangePin, EnterPin. | 257 // only on certain operations, such as ChangeRequirePin, ChangePin, EnterPin. |
121 enum SIMPinRequire { | 258 enum SimPinRequire { |
122 SIM_PIN_REQUIRE_UNKNOWN = 0, | 259 SIM_PIN_REQUIRE_UNKNOWN = 0, |
123 SIM_PIN_NOT_REQUIRED = 1, | 260 SIM_PIN_NOT_REQUIRED = 1, |
124 SIM_PIN_REQUIRED = 2, | 261 SIM_PIN_REQUIRED = 2, |
125 }; | 262 }; |
126 | 263 |
127 // Any PIN operation result (EnterPin, UnblockPin etc.). | 264 // Any PIN operation result (EnterPin, UnblockPin etc.). |
128 enum PinOperationError { | 265 enum PinOperationError { |
129 PIN_ERROR_NONE = 0, | 266 PIN_ERROR_NONE = 0, |
130 PIN_ERROR_UNKNOWN = 1, | 267 PIN_ERROR_UNKNOWN = 1, |
131 PIN_ERROR_INCORRECT_CODE = 2, // Either PIN/PUK specified is incorrect. | 268 PIN_ERROR_INCORRECT_CODE = 2, // Either PIN/PUK specified is incorrect. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 EAP_PHASE_2_AUTH_CHAP = 5 | 307 EAP_PHASE_2_AUTH_CHAP = 5 |
171 }; | 308 }; |
172 | 309 |
173 // Misc enums | 310 // Misc enums |
174 enum NetworkProfileType { | 311 enum NetworkProfileType { |
175 PROFILE_NONE, // Not in any profile (not remembered). | 312 PROFILE_NONE, // Not in any profile (not remembered). |
176 PROFILE_SHARED, // In the local profile, shared by all users on device. | 313 PROFILE_SHARED, // In the local profile, shared by all users on device. |
177 PROFILE_USER // In the user provile, not visible to other users. | 314 PROFILE_USER // In the user provile, not visible to other users. |
178 }; | 315 }; |
179 | 316 |
317 // Virtual Network provider type. | |
318 enum ProviderType { | |
319 PROVIDER_TYPE_L2TP_IPSEC_PSK, | |
320 PROVIDER_TYPE_L2TP_IPSEC_USER_CERT, | |
321 PROVIDER_TYPE_OPEN_VPN, | |
322 // Add new provider types before PROVIDER_TYPE_MAX. | |
323 PROVIDER_TYPE_MAX, | |
324 }; | |
325 | |
180 // Simple wrapper for property Cellular.FoundNetworks. | 326 // Simple wrapper for property Cellular.FoundNetworks. |
181 struct FoundCellularNetwork { | 327 struct FoundCellularNetwork { |
182 FoundCellularNetwork(); | 328 FoundCellularNetwork(); |
183 ~FoundCellularNetwork(); | 329 ~FoundCellularNetwork(); |
184 | 330 |
185 std::string status; | 331 std::string status; |
186 std::string network_id; | 332 std::string network_id; |
187 std::string short_name; | 333 std::string short_name; |
188 std::string long_name; | 334 std::string long_name; |
189 std::string technology; | 335 std::string technology; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 // e.g. ethernet, wifi, cellular. | 374 // e.g. ethernet, wifi, cellular. |
229 // TODO(dpolukhin): refactor to make base class and device specific derivatives. | 375 // TODO(dpolukhin): refactor to make base class and device specific derivatives. |
230 class NetworkDevice { | 376 class NetworkDevice { |
231 public: | 377 public: |
232 explicit NetworkDevice(const std::string& device_path); | 378 explicit NetworkDevice(const std::string& device_path); |
233 ~NetworkDevice(); | 379 ~NetworkDevice(); |
234 | 380 |
235 // Device info. | 381 // Device info. |
236 const std::string& device_path() const { return device_path_; } | 382 const std::string& device_path() const { return device_path_; } |
237 const std::string& name() const { return name_; } | 383 const std::string& name() const { return name_; } |
384 const std::string& unique_id() const { return unique_id_; } | |
238 ConnectionType type() const { return type_; } | 385 ConnectionType type() const { return type_; } |
239 bool scanning() const { return scanning_; } | 386 bool scanning() const { return scanning_; } |
240 const std::string& meid() const { return MEID_; } | 387 const std::string& meid() const { return meid_; } |
241 const std::string& imei() const { return IMEI_; } | 388 const std::string& imei() const { return imei_; } |
242 const std::string& imsi() const { return IMSI_; } | 389 const std::string& imsi() const { return imsi_; } |
243 const std::string& esn() const { return ESN_; } | 390 const std::string& esn() const { return esn_; } |
244 const std::string& mdn() const { return MDN_; } | 391 const std::string& mdn() const { return mdn_; } |
245 const std::string& min() const { return MIN_; } | 392 const std::string& min() const { return min_; } |
246 const std::string& model_id() const { return model_id_; } | 393 const std::string& model_id() const { return model_id_; } |
247 const std::string& manufacturer() const { return manufacturer_; } | 394 const std::string& manufacturer() const { return manufacturer_; } |
248 SIMLockState sim_lock_state() const { return sim_lock_state_; } | 395 SimLockState sim_lock_state() const { return sim_lock_state_; } |
249 bool is_sim_locked() const { | 396 bool is_sim_locked() const { |
250 return sim_lock_state_ == SIM_LOCKED_PIN || | 397 return sim_lock_state_ == SIM_LOCKED_PIN || |
251 sim_lock_state_ == SIM_LOCKED_PUK; | 398 sim_lock_state_ == SIM_LOCKED_PUK; |
252 } | 399 } |
253 const int sim_retries_left() const { return sim_retries_left_; } | 400 const int sim_retries_left() const { return sim_retries_left_; } |
254 SIMPinRequire sim_pin_required() const { return sim_pin_required_; } | 401 SimPinRequire sim_pin_required() const { return sim_pin_required_; } |
255 const std::string& firmware_revision() const { return firmware_revision_; } | 402 const std::string& firmware_revision() const { return firmware_revision_; } |
256 const std::string& hardware_revision() const { return hardware_revision_; } | 403 const std::string& hardware_revision() const { return hardware_revision_; } |
257 const unsigned int prl_version() const { return PRL_version_; } | 404 const unsigned int prl_version() const { return prl_version_; } |
258 const std::string& home_provider() const { return home_provider_; } | 405 const std::string& home_provider() const { return home_provider_; } |
259 const std::string& home_provider_code() const { return home_provider_code_; } | 406 const std::string& home_provider_code() const { return home_provider_code_; } |
260 const std::string& home_provider_country() const { | 407 const std::string& home_provider_country() const { |
261 return home_provider_country_; | 408 return home_provider_country_; |
262 } | 409 } |
263 const std::string& home_provider_id() const { return home_provider_id_; } | 410 const std::string& home_provider_id() const { return home_provider_id_; } |
264 const std::string& home_provider_name() const { return home_provider_name_; } | 411 const std::string& home_provider_name() const { return home_provider_name_; } |
265 const std::string& selected_cellular_network() const { | 412 const std::string& selected_cellular_network() const { |
266 return selected_cellular_network_; | 413 return selected_cellular_network_; |
267 } | 414 } |
268 const CellularNetworkList& found_cellular_networks() const { | 415 const CellularNetworkList& found_cellular_networks() const { |
269 return found_cellular_networks_; | 416 return found_cellular_networks_; |
270 } | 417 } |
271 bool data_roaming_allowed() const { return data_roaming_allowed_; } | 418 bool data_roaming_allowed() const { return data_roaming_allowed_; } |
272 bool support_network_scan() const { return support_network_scan_; } | 419 bool support_network_scan() const { return support_network_scan_; } |
273 enum TechnologyFamily technology_family() const { return technology_family_; } | 420 enum TechnologyFamily technology_family() const { return technology_family_; } |
274 const CellularApnList& provider_apn_list() const { | 421 const CellularApnList& provider_apn_list() const { |
275 return provider_apn_list_; | 422 return provider_apn_list_; |
276 } | 423 } |
277 | 424 |
425 // Updates the property specified by |key| with the contents of | |
426 // |value|. Returns false on failure. Upon success, returns the | |
427 // PropertyIndex that was updated in |index|. |index| may be NULL | |
428 // if not needed. | |
429 virtual bool UpdateStatus(const std::string& key, | |
430 const Value& value, | |
431 PropertyIndex *index); | |
432 | |
433 NativeNetworkDeviceParser* device_parser() { return device_parser_.get(); } | |
434 | |
435 protected: | |
436 void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; } | |
437 | |
278 private: | 438 private: |
279 bool ParseValue(int index, const base::Value* value); | 439 // This allows NetworkDeviceParser and its subclasses access to |
280 void ParseInfo(const base::DictionaryValue* info); | 440 // device privates so that they can be reconstituted during parsing. |
441 // The parsers only access things through the private set_ functions | |
442 // so that this class can evolve without having to change all the | |
443 // parsers. | |
444 NETWORK_LIBRARY_PARSER_FRIENDS; | |
445 friend class NativeEthernetNetworkParser; | |
446 friend class NativeWirelessNetworkParser; | |
447 friend class NativeWifiNetworkParser; | |
448 friend class NativeCellularNetworkParser; | |
449 friend class NativeVirtualNetworkParser; | |
stevenjb
2011/08/12 21:32:37
I am curious why network parsers are modifying Net
Greg Spencer (Chromium)
2011/08/12 23:45:19
OK, turns out they're not. I've fixed all of thes
stevenjb
2011/08/13 00:01:45
Awesome, this looks much better to me.
| |
450 | |
451 // This allows the implementation classes access to privates in the | |
452 // same fashion. | |
453 NETWORK_LIBRARY_IMPL_FRIENDS; | |
454 | |
455 // Use these functions at your peril. They are used by the various | |
456 // parsers to set state, and really shouldn't be used by anyone | |
457 // else. | |
458 void set_device_path(const std::string& device_path) { | |
459 device_path_ = device_path; | |
460 } | |
461 void set_name(const std::string& name) { name_ = name; } | |
462 void set_type(ConnectionType type) { type_ = type; } | |
463 void set_scanning(bool scanning) { scanning_ = scanning; } | |
464 void set_meid(const std::string& meid) { meid_ = meid; } | |
465 void set_imei(const std::string& imei) { imei_ = imei; } | |
466 void set_imsi(const std::string& imsi) { imsi_ = imsi; } | |
467 void set_esn(const std::string& esn) { esn_ = esn; } | |
468 void set_mdn(const std::string& mdn) { mdn_ = mdn; } | |
469 void set_min(const std::string& min) { min_ = min; } | |
470 void set_technology_family(TechnologyFamily technology_family) { | |
471 technology_family_ = technology_family; | |
472 } | |
473 void set_carrier(const std::string& carrier) { carrier_ = carrier; } | |
474 void set_home_provider(const std::string& home_provider) { | |
475 home_provider_ = home_provider; | |
476 } | |
477 void set_home_provider_code(const std::string& home_provider_code) { | |
478 home_provider_code_ = home_provider_code; | |
479 } | |
480 void set_home_provider_country(const std::string& home_provider_country) { | |
481 home_provider_country_ = home_provider_country; | |
482 } | |
483 void set_home_provider_id(const std::string& home_provider_id) { | |
484 home_provider_id_ = home_provider_id; | |
485 } | |
486 void set_home_provider_name(const std::string& home_provider_name) { | |
487 home_provider_name_ = home_provider_name; | |
488 } | |
489 void set_model_id(const std::string& model_id) { model_id_ = model_id; } | |
490 void set_manufacturer(const std::string& manufacturer) { | |
491 manufacturer_ = manufacturer; | |
492 } | |
493 void set_prl_version(int prl_version) { | |
494 prl_version_ = prl_version; | |
495 } | |
496 void set_sim_lock_state(SimLockState sim_lock_state) { | |
497 sim_lock_state_ = sim_lock_state; | |
498 } | |
499 void set_sim_retries_left(int sim_retries_left) { | |
500 sim_retries_left_ = sim_retries_left; | |
501 } | |
502 void set_sim_pin_required(SimPinRequire sim_pin_required) { | |
503 sim_pin_required_ = sim_pin_required; | |
504 } | |
505 void set_firmware_revision(const std::string& firmware_revision) { | |
506 firmware_revision_ = firmware_revision; | |
507 } | |
508 void set_hardware_revision(const std::string& hardware_revision) { | |
509 hardware_revision_ = hardware_revision; | |
510 } | |
511 void set_selected_cellular_network( | |
512 const std::string& selected_cellular_network) { | |
513 selected_cellular_network_ = selected_cellular_network; | |
514 } | |
515 void set_found_cellular_networks( | |
516 const CellularNetworkList& found_cellular_networks) { | |
517 found_cellular_networks_ = found_cellular_networks; | |
518 } | |
519 void set_data_roaming_allowed(bool data_roaming_allowed) { | |
520 data_roaming_allowed_ = data_roaming_allowed; | |
521 } | |
522 void set_support_network_scan(bool support_network_scan) { | |
523 support_network_scan_ = support_network_scan; | |
524 } | |
525 void set_provider_apn_list(const CellularApnList& provider_apn_list) { | |
526 provider_apn_list_ = provider_apn_list; | |
527 } | |
528 | |
529 void ParseInfo(const base::DictionaryValue& info); | |
281 | 530 |
282 // General device info. | 531 // General device info. |
283 std::string device_path_; | 532 std::string device_path_; |
284 std::string name_; | 533 std::string name_; |
534 std::string unique_id_; | |
285 ConnectionType type_; | 535 ConnectionType type_; |
286 bool scanning_; | 536 bool scanning_; |
287 // Cellular specific device info. | 537 // Cellular specific device info. |
288 TechnologyFamily technology_family_; | 538 TechnologyFamily technology_family_; |
289 std::string carrier_; | 539 std::string carrier_; |
290 std::string home_provider_; | 540 std::string home_provider_; |
291 std::string home_provider_code_; | 541 std::string home_provider_code_; |
292 std::string home_provider_country_; | 542 std::string home_provider_country_; |
293 std::string home_provider_id_; | 543 std::string home_provider_id_; |
294 std::string home_provider_name_; | 544 std::string home_provider_name_; |
295 std::string MEID_; | 545 std::string meid_; |
296 std::string IMEI_; | 546 std::string imei_; |
297 std::string IMSI_; | 547 std::string imsi_; |
298 std::string ESN_; | 548 std::string esn_; |
299 std::string MDN_; | 549 std::string mdn_; |
300 std::string MIN_; | 550 std::string min_; |
301 std::string model_id_; | 551 std::string model_id_; |
302 std::string manufacturer_; | 552 std::string manufacturer_; |
303 SIMLockState sim_lock_state_; | 553 SimLockState sim_lock_state_; |
304 int sim_retries_left_; | 554 int sim_retries_left_; |
305 SIMPinRequire sim_pin_required_; | 555 SimPinRequire sim_pin_required_; |
306 std::string firmware_revision_; | 556 std::string firmware_revision_; |
307 std::string hardware_revision_; | 557 std::string hardware_revision_; |
308 int PRL_version_; | 558 int prl_version_; |
309 std::string selected_cellular_network_; | 559 std::string selected_cellular_network_; |
310 CellularNetworkList found_cellular_networks_; | 560 CellularNetworkList found_cellular_networks_; |
311 bool data_roaming_allowed_; | 561 bool data_roaming_allowed_; |
312 bool support_network_scan_; | 562 bool support_network_scan_; |
313 CellularApnList provider_apn_list_; | 563 CellularApnList provider_apn_list_; |
314 | 564 |
315 friend class NetworkLibraryImplBase; | 565 // This is the parser we use to parse messages from the native |
316 friend class NetworkLibraryImplCros; | 566 // network layer. |
317 friend class NetworkLibraryImplStub; | 567 scoped_ptr<NativeNetworkDeviceParser> device_parser_; |
568 | |
318 DISALLOW_COPY_AND_ASSIGN(NetworkDevice); | 569 DISALLOW_COPY_AND_ASSIGN(NetworkDevice); |
319 }; | 570 }; |
320 | 571 |
321 // Contains data common to all network service types. | 572 // Contains data common to all network service types. |
322 class Network { | 573 class Network { |
323 public: | 574 public: |
324 virtual ~Network(); | 575 virtual ~Network(); |
325 | 576 |
326 const std::string& service_path() const { return service_path_; } | 577 const std::string& service_path() const { return service_path_; } |
327 const std::string& name() const { return name_; } | 578 const std::string& name() const { return name_; } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 state == STATE_CARRIER); | 648 state == STATE_CARRIER); |
398 } | 649 } |
399 static bool IsDisconnectedState(ConnectionState state) { | 650 static bool IsDisconnectedState(ConnectionState state) { |
400 return (state == STATE_UNKNOWN || | 651 return (state == STATE_UNKNOWN || |
401 state == STATE_IDLE || | 652 state == STATE_IDLE || |
402 state == STATE_DISCONNECT || | 653 state == STATE_DISCONNECT || |
403 state == STATE_FAILURE || | 654 state == STATE_FAILURE || |
404 state == STATE_ACTIVATION_FAILURE); | 655 state == STATE_ACTIVATION_FAILURE); |
405 } | 656 } |
406 | 657 |
658 virtual bool UpdateStatus(const std::string& key, | |
659 const Value& value, | |
660 PropertyIndex* index); | |
661 | |
407 protected: | 662 protected: |
408 Network(const std::string& service_path, ConnectionType type); | 663 Network(const std::string& service_path, |
664 ConnectionType type, | |
665 NativeNetworkParser* parser); | |
666 | |
667 // Set the state and update flags if necessary. | |
668 void SetState(ConnectionState state); | |
409 | 669 |
410 // Parse name/value pairs from libcros. | 670 // Parse name/value pairs from libcros. |
411 virtual bool ParseValue(int index, const base::Value* value); | 671 virtual void ParseInfo(const base::DictionaryValue& info); |
412 virtual void ParseInfo(const base::DictionaryValue* info); | |
413 | 672 |
414 // Erase cached credentials, used when "Save password" is unchecked. | 673 // Erase cached credentials, used when "Save password" is unchecked. |
415 virtual void EraseCredentials(); | 674 virtual void EraseCredentials(); |
416 | 675 |
417 // Calculate a unique identifier for the network. | 676 // Calculate a unique identifier for the network. |
418 virtual void CalculateUniqueId(); | 677 virtual void CalculateUniqueId(); |
419 | 678 |
420 // Methods to asynchronously set network service properties | 679 // Methods to asynchronously set network service properties |
421 virtual void SetStringProperty(const char* prop, const std::string& str, | 680 virtual void SetStringProperty(const char* prop, const std::string& str, |
422 std::string* dest); | 681 std::string* dest); |
423 virtual void SetBooleanProperty(const char* prop, bool b, bool* dest); | 682 virtual void SetBooleanProperty(const char* prop, bool b, bool* dest); |
424 virtual void SetIntegerProperty(const char* prop, int i, int* dest); | 683 virtual void SetIntegerProperty(const char* prop, int i, int* dest); |
425 virtual void SetValueProperty(const char* prop, base::Value* val); | 684 virtual void SetValueProperty(const char* prop, base::Value* val); |
426 virtual void ClearProperty(const char* prop); | 685 virtual void ClearProperty(const char* prop); |
427 | 686 |
428 // This will clear the property if string is empty. Otherwise, it will set it. | 687 // This will clear the property if string is empty. Otherwise, it will set it. |
429 virtual void SetOrClearStringProperty(const char* prop, | 688 virtual void SetOrClearStringProperty(const char* prop, |
430 const std::string& str, | 689 const std::string& str, |
431 std::string* dest); | 690 std::string* dest); |
432 | 691 |
433 std::string device_path_; | 692 NativeNetworkParser* network_parser() { return network_parser_.get(); } |
434 std::string name_; | |
435 std::string ip_address_; | |
436 ConnectionMode mode_; | |
437 ConnectionState state_; | |
438 ConnectionError error_; | |
439 bool connectable_; | |
440 bool is_active_; | |
441 int priority_; // determines order in network list. | |
442 bool auto_connect_; | |
443 bool save_credentials_; // save passphrase and EAP credentials to disk. | |
444 std::string proxy_config_; | |
445 | 693 |
446 // Unique identifier, set the first time the network is parsed. | 694 void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; } |
447 std::string unique_id_; | |
448 | 695 |
449 private: | 696 private: |
697 // This allows NetworkParser and its subclasses access to device | |
698 // privates so that they can be reconstituted during parsing. The | |
699 // parsers only access things through the private set_ functions so | |
700 // that this class can evolve without having to change all the | |
701 // parsers. | |
702 NETWORK_LIBRARY_PARSER_FRIENDS; | |
703 friend class NativeEthernetNetworkParser; | |
704 friend class NativeWirelessNetworkParser; | |
705 friend class NativeWifiNetworkParser; | |
706 friend class NativeCellularNetworkParser; | |
707 friend class NativeVirtualNetworkParser; | |
stevenjb
2011/08/12 21:32:37
In theory, it seems like only NativeNetworkParser(
Greg Spencer (Chromium)
2011/08/12 23:45:19
I tried that approach, and it leads to a lot of pr
stevenjb
2011/08/13 00:01:45
This is fine I think now that we are down to a mor
| |
708 | |
709 // This allows the implementation classes access to privates in the | |
710 // same fashion. | |
711 NETWORK_LIBRARY_IMPL_FRIENDS; | |
712 | |
713 // Use these functions at your peril. They are used by the various | |
714 // parsers to set state, and really shouldn't be used by anything else | |
715 // because they don't do the error checking and sending to the | |
716 // network layer that the other setters do. | |
717 void set_device_path(const std::string& device_path) { | |
718 device_path_ = device_path; | |
719 } | |
450 void set_name(const std::string& name) { name_ = name; } | 720 void set_name(const std::string& name) { name_ = name; } |
721 void set_mode(ConnectionMode mode) { mode_ = mode; } | |
451 void set_connecting(bool connecting) { | 722 void set_connecting(bool connecting) { |
452 state_ = (connecting ? STATE_ASSOCIATION : STATE_IDLE); | 723 state_ = (connecting ? STATE_ASSOCIATION : STATE_IDLE); |
453 } | 724 } |
454 void set_connected(bool connected) { | 725 void set_connected(bool connected) { |
455 state_ = (connected ? STATE_ONLINE : STATE_IDLE); | 726 state_ = (connected ? STATE_ONLINE : STATE_IDLE); |
456 } | 727 } |
457 void set_connectable(bool connectable) { connectable_ = connectable; } | 728 void set_connectable(bool connectable) { connectable_ = connectable; } |
458 void set_active(bool is_active) { is_active_ = is_active; } | 729 void set_is_active(bool is_active) { is_active_ = is_active; } |
459 void set_error(ConnectionError error) { error_ = error; } | 730 void set_error(ConnectionError error) { error_ = error; } |
460 void set_added(bool added) { added_ = added; } | 731 void set_added(bool added) { added_ = added; } |
732 void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; } | |
733 void set_save_credentials(bool save_credentials) { | |
734 save_credentials_ = save_credentials; | |
735 } | |
461 void set_profile_path(const std::string& path) { profile_path_ = path; } | 736 void set_profile_path(const std::string& path) { profile_path_ = path; } |
462 void set_profile_type(NetworkProfileType type) { profile_type_ = type; } | 737 void set_profile_type(NetworkProfileType type) { profile_type_ = type; } |
463 | 738 |
464 // Set the state and update flags if necessary. | 739 std::string device_path_; |
465 void SetState(ConnectionState state); | 740 std::string name_; |
741 std::string ip_address_; | |
742 ConnectionMode mode_; | |
743 ConnectionState state_; | |
744 ConnectionError error_; | |
745 bool connectable_; | |
746 bool is_active_; | |
747 int priority_; // determines order in network list. | |
748 bool auto_connect_; | |
749 bool save_credentials_; // save passphrase and EAP credentials to disk. | |
750 std::string proxy_config_; | |
751 | |
752 // Unique identifier, set the first time the network is parsed. | |
753 std::string unique_id_; | |
466 | 754 |
467 // Set the profile path and update the flimfalm property. | 755 // Set the profile path and update the flimfalm property. |
468 void SetProfilePath(const std::string& profile_path); | 756 void SetProfilePath(const std::string& profile_path); |
469 | 757 |
470 // Initialize the IP address field | 758 // Initialize the IP address field |
471 void InitIPAddress(); | 759 void InitIPAddress(); |
472 | 760 |
473 // Priority value, corresponds to index in list from flimflam (0 = first) | 761 // Priority value, corresponds to index in list from flimflam (0 = first) |
474 int priority_order_; | 762 int priority_order_; |
475 | 763 |
476 // Set to true if the UI requested this as a new network. | 764 // Set to true if the UI requested this as a new network. |
477 bool added_; | 765 bool added_; |
478 | 766 |
479 // Set to true when a new connection failure occurs; cleared when observers | 767 // Set to true when a new connection failure occurs; cleared when observers |
480 // are notified. | 768 // are notified. |
481 bool notify_failure_; | 769 bool notify_failure_; |
482 | 770 |
483 // Profile path for networks. | 771 // Profile path for networks. |
484 std::string profile_path_; | 772 std::string profile_path_; |
485 | 773 |
486 // Set to profile type based on profile_path_. | 774 // Set to profile type based on profile_path_. |
487 NetworkProfileType profile_type_; | 775 NetworkProfileType profile_type_; |
488 | 776 |
489 // These must not be modified after construction. | 777 // These must not be modified after construction. |
490 std::string service_path_; | 778 std::string service_path_; |
491 ConnectionType type_; | 779 ConnectionType type_; |
492 | 780 |
493 friend class NetworkLibraryImplBase; | 781 // This is the parser we use to parse messages from the native |
494 friend class NetworkLibraryImplCros; | 782 // network layer. |
495 friend class NetworkLibraryImplStub; | 783 scoped_ptr<NativeNetworkParser> network_parser_; |
784 | |
496 DISALLOW_COPY_AND_ASSIGN(Network); | 785 DISALLOW_COPY_AND_ASSIGN(Network); |
497 }; | 786 }; |
498 | 787 |
499 // Class for networks of TYPE_ETHERNET. | 788 // Class for networks of TYPE_ETHERNET. |
500 class EthernetNetwork : public Network { | 789 class EthernetNetwork : public Network { |
501 public: | 790 public: |
502 explicit EthernetNetwork(const std::string& service_path) : | 791 explicit EthernetNetwork(const std::string& service_path); |
503 Network(service_path, TYPE_ETHERNET) { | |
504 } | |
505 private: | 792 private: |
506 friend class NetworkLibraryImplBase; | 793 // This allows NetworkParser and its subclasses access to device |
507 friend class NetworkLibraryImplCros; | 794 // privates so that they can be reconstituted during parsing. The |
508 friend class NetworkLibraryImplStub; | 795 // parsers only access things through the private set_ functions so |
796 // that this class can evolve without having to change all the | |
797 // parsers. | |
798 NETWORK_LIBRARY_PARSER_FRIENDS; | |
799 friend class NativeEthernetNetworkParser; | |
800 | |
801 // This allows the implementation classes access to privates in the | |
802 // same fashion. | |
803 NETWORK_LIBRARY_IMPL_FRIENDS; | |
804 | |
509 DISALLOW_COPY_AND_ASSIGN(EthernetNetwork); | 805 DISALLOW_COPY_AND_ASSIGN(EthernetNetwork); |
510 }; | 806 }; |
511 | 807 |
512 // Class for networks of TYPE_VPN. | 808 // Class for networks of TYPE_VPN. |
513 class VirtualNetwork : public Network { | 809 class VirtualNetwork : public Network { |
514 public: | 810 public: |
515 enum ProviderType { | |
516 PROVIDER_TYPE_L2TP_IPSEC_PSK, | |
517 PROVIDER_TYPE_L2TP_IPSEC_USER_CERT, | |
518 PROVIDER_TYPE_OPEN_VPN, | |
519 // Add new provider types before PROVIDER_TYPE_MAX. | |
520 PROVIDER_TYPE_MAX, | |
521 }; | |
522 | |
523 explicit VirtualNetwork(const std::string& service_path); | 811 explicit VirtualNetwork(const std::string& service_path); |
524 virtual ~VirtualNetwork(); | 812 virtual ~VirtualNetwork(); |
525 | 813 |
526 const std::string& server_hostname() const { return server_hostname_; } | 814 const std::string& server_hostname() const { return server_hostname_; } |
527 ProviderType provider_type() const { return provider_type_; } | 815 ProviderType provider_type() const { return provider_type_; } |
528 const std::string& ca_cert_nss() const { return ca_cert_nss_; } | 816 const std::string& ca_cert_nss() const { return ca_cert_nss_; } |
529 const std::string& psk_passphrase() const { return psk_passphrase_; } | 817 const std::string& psk_passphrase() const { return psk_passphrase_; } |
530 const std::string& client_cert_id() const { return client_cert_id_; } | 818 const std::string& client_cert_id() const { return client_cert_id_; } |
531 const std::string& username() const { return username_; } | 819 const std::string& username() const { return username_; } |
532 const std::string& user_passphrase() const { return user_passphrase_; } | 820 const std::string& user_passphrase() const { return user_passphrase_; } |
(...skipping 11 matching lines...) Expand all Loading... | |
544 std::string GetProviderTypeString() const; | 832 std::string GetProviderTypeString() const; |
545 | 833 |
546 // Public setters. | 834 // Public setters. |
547 void SetCACertNSS(const std::string& ca_cert_nss); | 835 void SetCACertNSS(const std::string& ca_cert_nss); |
548 void SetPSKPassphrase(const std::string& psk_passphrase); | 836 void SetPSKPassphrase(const std::string& psk_passphrase); |
549 void SetClientCertID(const std::string& cert_id); | 837 void SetClientCertID(const std::string& cert_id); |
550 void SetUsername(const std::string& username); | 838 void SetUsername(const std::string& username); |
551 void SetUserPassphrase(const std::string& user_passphrase); | 839 void SetUserPassphrase(const std::string& user_passphrase); |
552 | 840 |
553 private: | 841 private: |
554 // Network overrides. | 842 // This allows NetworkParser and its subclasses access to device |
555 virtual bool ParseValue(int index, const base::Value* value); | 843 // privates so that they can be reconstituted during parsing. The |
556 virtual void ParseInfo(const base::DictionaryValue* info); | 844 // parsers only access things through the private set_ functions so |
557 virtual void EraseCredentials(); | 845 // that this class can evolve without having to change all the |
558 virtual void CalculateUniqueId(); | 846 // parsers. |
847 NETWORK_LIBRARY_PARSER_FRIENDS; | |
848 friend class NativeVirtualNetworkParser; | |
559 | 849 |
560 // VirtualNetwork private methods. | 850 // This allows the implementation classes access to privates in the |
561 bool ParseProviderValue(int index, const base::Value* value); | 851 // same fashion. |
852 NETWORK_LIBRARY_IMPL_FRIENDS; | |
562 | 853 |
854 // Use these functions at your peril. They are used by the various | |
855 // parsers to set state, and really shouldn't be used by anything else | |
856 // because they don't do the error checking and sending to the | |
857 // network layer that the other setters do. | |
563 void set_server_hostname(const std::string& server_hostname) { | 858 void set_server_hostname(const std::string& server_hostname) { |
564 server_hostname_ = server_hostname; | 859 server_hostname_ = server_hostname; |
565 } | 860 } |
566 void set_provider_type(ProviderType provider_type) { | 861 void set_provider_type(ProviderType provider_type) { |
567 provider_type_ = provider_type; | 862 provider_type_ = provider_type; |
568 } | 863 } |
569 void set_ca_cert_nss(const std::string& ca_cert_nss) { | 864 void set_ca_cert_nss(const std::string& ca_cert_nss) { |
570 ca_cert_nss_ = ca_cert_nss; | 865 ca_cert_nss_ = ca_cert_nss; |
571 } | 866 } |
572 void set_psk_passphrase(const std::string& psk_passphrase) { | 867 void set_psk_passphrase(const std::string& psk_passphrase) { |
573 psk_passphrase_ = psk_passphrase; | 868 psk_passphrase_ = psk_passphrase; |
574 } | 869 } |
575 void set_client_cert_id(const std::string& client_cert_id) { | 870 void set_client_cert_id(const std::string& client_cert_id) { |
576 client_cert_id_ = client_cert_id; | 871 client_cert_id_ = client_cert_id; |
577 } | 872 } |
578 void set_username(const std::string& username) { | 873 void set_username(const std::string& username) { username_ = username; } |
579 username_ = username; | |
580 } | |
581 void set_user_passphrase(const std::string& user_passphrase) { | 874 void set_user_passphrase(const std::string& user_passphrase) { |
582 user_passphrase_ = user_passphrase; | 875 user_passphrase_ = user_passphrase; |
583 } | 876 } |
584 | 877 |
878 // Network overrides. | |
879 virtual void EraseCredentials() OVERRIDE; | |
880 virtual void CalculateUniqueId() OVERRIDE; | |
881 | |
882 // VirtualNetwork private methods. | |
883 bool ParseProviderValue(int index, const base::Value* value); | |
884 | |
585 std::string server_hostname_; | 885 std::string server_hostname_; |
586 ProviderType provider_type_; | 886 ProviderType provider_type_; |
587 // NSS nickname for server CA certificate. | 887 // NSS nickname for server CA certificate. |
588 std::string ca_cert_nss_; | 888 std::string ca_cert_nss_; |
589 std::string psk_passphrase_; | 889 std::string psk_passphrase_; |
590 // PKCS#11 ID for client certificate. | 890 // PKCS#11 ID for client certificate. |
591 std::string client_cert_id_; | 891 std::string client_cert_id_; |
592 std::string username_; | 892 std::string username_; |
593 std::string user_passphrase_; | 893 std::string user_passphrase_; |
594 | |
595 friend class NetworkLibraryImplBase; | |
596 friend class NetworkLibraryImplCros; | |
597 friend class NetworkLibraryImplStub; | |
598 DISALLOW_COPY_AND_ASSIGN(VirtualNetwork); | 894 DISALLOW_COPY_AND_ASSIGN(VirtualNetwork); |
599 }; | 895 }; |
600 typedef std::vector<VirtualNetwork*> VirtualNetworkVector; | 896 typedef std::vector<VirtualNetwork*> VirtualNetworkVector; |
601 | 897 |
602 // Base class for networks of TYPE_WIFI or TYPE_CELLULAR. | 898 // Base class for networks of TYPE_WIFI or TYPE_CELLULAR. |
603 class WirelessNetwork : public Network { | 899 class WirelessNetwork : public Network { |
604 public: | 900 public: |
605 int strength() const { return strength_; } | 901 int strength() const { return strength_; } |
606 | 902 |
607 protected: | 903 protected: |
608 WirelessNetwork(const std::string& service_path, ConnectionType type) | 904 WirelessNetwork(const std::string& service_path, |
609 : Network(service_path, type), | 905 ConnectionType type, |
610 strength_(0) {} | 906 NativeNetworkParser* parser) |
907 : Network(service_path, type, parser), strength_(0) {} | |
908 private: | |
909 // This allows NetworkParser and its subclasses access to device | |
910 // privates so that they can be reconstituted during parsing. The | |
911 // parsers only access things through the private set_ functions so | |
912 // that this class can evolve without having to change all the | |
913 // parsers. | |
914 NETWORK_LIBRARY_PARSER_FRIENDS; | |
915 friend class NativeWirelessNetworkParser; | |
916 friend class NativeWifiNetworkParser; | |
917 friend class NativeCellularNetworkParser; | |
918 | |
919 // This allows the implementation classes access to privates in the | |
920 // same fashion. | |
921 NETWORK_LIBRARY_IMPL_FRIENDS; | |
922 | |
923 // The friend parsers use this. | |
924 void set_strength(int strength) { strength_ = strength; } | |
925 | |
611 int strength_; // 0-100 | 926 int strength_; // 0-100 |
612 | 927 |
613 // Network overrides. | |
614 virtual bool ParseValue(int index, const base::Value* value); | |
615 | |
616 private: | |
617 void set_strength(int strength) { strength_ = strength; } | |
618 | |
619 friend class NetworkLibraryImplBase; | |
620 friend class NetworkLibraryImplCros; | |
621 friend class NetworkLibraryImplStub; | |
622 DISALLOW_COPY_AND_ASSIGN(WirelessNetwork); | 928 DISALLOW_COPY_AND_ASSIGN(WirelessNetwork); |
623 }; | 929 }; |
624 | 930 |
625 // Class for networks of TYPE_CELLULAR. | 931 // Class for networks of TYPE_CELLULAR. |
626 class CellularDataPlan; | 932 class CellularDataPlan; |
627 | 933 |
628 class CellularNetwork : public WirelessNetwork { | 934 class CellularNetwork : public WirelessNetwork { |
629 public: | 935 public: |
630 enum DataLeft { | 936 enum DataLeft { |
631 DATA_UNKNOWN, | 937 DATA_UNKNOWN, |
(...skipping 27 matching lines...) Expand all Loading... | |
659 && connected() && activated(); | 965 && connected() && activated(); |
660 } | 966 } |
661 const std::string& operator_name() const { return operator_name_; } | 967 const std::string& operator_name() const { return operator_name_; } |
662 const std::string& operator_code() const { return operator_code_; } | 968 const std::string& operator_code() const { return operator_code_; } |
663 const std::string& operator_country() const { return operator_country_; } | 969 const std::string& operator_country() const { return operator_country_; } |
664 const std::string& payment_url() const { return payment_url_; } | 970 const std::string& payment_url() const { return payment_url_; } |
665 const std::string& usage_url() const { return usage_url_; } | 971 const std::string& usage_url() const { return usage_url_; } |
666 DataLeft data_left() const { return data_left_; } | 972 DataLeft data_left() const { return data_left_; } |
667 const CellularApn& apn() const { return apn_; } | 973 const CellularApn& apn() const { return apn_; } |
668 const CellularApn& last_good_apn() const { return last_good_apn_; } | 974 const CellularApn& last_good_apn() const { return last_good_apn_; } |
975 | |
669 // Sets the APN to use in establishing data connections. Only | 976 // Sets the APN to use in establishing data connections. Only |
670 // the fields of the APN that are needed for making connections | 977 // the fields of the APN that are needed for making connections |
671 // are passed to flimflam. The name, localized_name, and language | 978 // are passed to flimflam. The name, localized_name, and language |
672 // fields are ignored. | 979 // fields are ignored. |
673 void SetApn(const CellularApn& apn); | 980 void SetApn(const CellularApn& apn); |
674 | 981 |
675 // Returns true if network supports activation. | 982 // Returns true if network supports activation. |
676 // Current implementation returns same as SupportsDataPlan(). | 983 // Current implementation returns same as SupportsDataPlan(). |
677 bool SupportsActivation() const; | 984 bool SupportsActivation() const; |
678 | 985 |
679 // Returns true if one of the usage_url_ / payment_url_ (or both) is defined. | 986 // Returns true if one of the usage_url_ / payment_url_ (or both) is defined. |
680 bool SupportsDataPlan() const; | 987 bool SupportsDataPlan() const; |
681 | 988 |
682 // Return a string representation of network technology. | 989 // Return a string representation of network technology. |
683 std::string GetNetworkTechnologyString() const; | 990 std::string GetNetworkTechnologyString() const; |
684 // Return a string representation of activation state. | 991 // Return a string representation of activation state. |
685 std::string GetActivationStateString() const; | 992 std::string GetActivationStateString() const; |
686 // Return a string representation of roaming state. | 993 // Return a string representation of roaming state. |
687 std::string GetRoamingStateString() const; | 994 std::string GetRoamingStateString() const; |
688 | 995 |
689 // Return a string representation of |activation_state|. | 996 // Return a string representation of |activation_state|. |
690 static std::string ActivationStateToString(ActivationState activation_state); | 997 static std::string ActivationStateToString(ActivationState activation_state); |
691 | 998 |
692 protected: | 999 private: |
693 // WirelessNetwork overrides. | 1000 // This allows NetworkParser and its subclasses access to device |
694 virtual bool ParseValue(int index, const base::Value* value); | 1001 // privates so that they can be reconstituted during parsing. The |
1002 // parsers only access things through the private set_ functions so | |
1003 // that this class can evolve without having to change all the | |
1004 // parsers. | |
1005 NETWORK_LIBRARY_PARSER_FRIENDS; | |
1006 friend class NativeWirelessNetworkParser; | |
1007 friend class NativeCellularNetworkParser; | |
1008 | |
1009 // This allows the implementation classes access to privates in the | |
1010 // same fashion. | |
1011 NETWORK_LIBRARY_IMPL_FRIENDS; | |
1012 | |
1013 // Use these functions at your peril. They are used by the various | |
1014 // parsers to set state, and really shouldn't be used by anything else | |
1015 // because they don't do the error checking and sending to the | |
1016 // network layer that the other setters do. | |
1017 void set_activation_state(ActivationState activation_state) { | |
1018 activation_state_ = activation_state; | |
1019 } | |
1020 void set_network_technology(NetworkTechnology network_technology) { | |
1021 network_technology_ = network_technology; | |
1022 } | |
1023 void set_roaming_state(NetworkRoamingState roaming_state) { | |
1024 roaming_state_ = roaming_state; | |
1025 } | |
1026 void set_operator_name(const std::string& operator_name) { | |
1027 operator_name_ = operator_name; | |
1028 } | |
1029 void set_operator_code(const std::string& operator_code) { | |
1030 operator_code_ = operator_code; | |
1031 } | |
1032 void set_operator_country(const std::string& operator_country) { | |
1033 operator_country_ = operator_country; | |
1034 } | |
1035 void set_payment_url(const std::string& payment_url) { | |
1036 payment_url_ = payment_url; | |
1037 } | |
1038 void set_usage_url(const std::string& usage_url) { usage_url_ = usage_url; } | |
1039 void set_data_left(DataLeft data_left) { data_left_ = data_left; } | |
1040 void set_apn(const DictionaryValue& apn) { apn_.Set(apn); } | |
1041 void set_last_good_apn(const DictionaryValue& last_good_apn) { | |
1042 last_good_apn_.Set(last_good_apn); | |
1043 } | |
695 | 1044 |
696 ActivationState activation_state_; | 1045 ActivationState activation_state_; |
697 NetworkTechnology network_technology_; | 1046 NetworkTechnology network_technology_; |
698 NetworkRoamingState roaming_state_; | 1047 NetworkRoamingState roaming_state_; |
699 // Carrier Info | 1048 // Carrier Info |
700 std::string operator_name_; | 1049 std::string operator_name_; |
701 std::string operator_code_; | 1050 std::string operator_code_; |
702 std::string operator_country_; | 1051 std::string operator_country_; |
703 std::string payment_url_; | 1052 std::string payment_url_; |
704 std::string usage_url_; | 1053 std::string usage_url_; |
705 // Cached values | 1054 // Cached values |
706 DataLeft data_left_; // Updated when data plans are updated. | 1055 DataLeft data_left_; // Updated when data plans are updated. |
707 CellularApn apn_; | 1056 CellularApn apn_; |
708 CellularApn last_good_apn_; | 1057 CellularApn last_good_apn_; |
709 | 1058 |
710 private: | |
711 void set_activation_state(ActivationState state) { | |
712 activation_state_ = state; | |
713 } | |
714 void set_payment_url(const std::string& url) { payment_url_ = url; } | |
715 void set_usage_url(const std::string& url) { usage_url_ = url; } | |
716 void set_network_technology(NetworkTechnology technology) { | |
717 network_technology_ = technology; | |
718 } | |
719 void set_roaming_state(NetworkRoamingState state) { roaming_state_ = state; } | |
720 void set_data_left(DataLeft data_left) { data_left_ = data_left; } | |
721 void set_apn(const CellularApn& apn) { apn_ = apn; } | |
722 void set_last_good_apn(const CellularApn& apn) { last_good_apn_ = apn; } | |
723 | |
724 friend class NetworkLibraryImplBase; | |
725 friend class NetworkLibraryImplCros; | |
726 friend class NetworkLibraryImplStub; | |
727 DISALLOW_COPY_AND_ASSIGN(CellularNetwork); | 1059 DISALLOW_COPY_AND_ASSIGN(CellularNetwork); |
728 }; | 1060 }; |
729 typedef std::vector<CellularNetwork*> CellularNetworkVector; | 1061 typedef std::vector<CellularNetwork*> CellularNetworkVector; |
730 | 1062 |
731 // Class for networks of TYPE_WIFI. | 1063 // Class for networks of TYPE_WIFI. |
732 class WifiNetwork : public WirelessNetwork { | 1064 class WifiNetwork : public WirelessNetwork { |
733 public: | 1065 public: |
734 explicit WifiNetwork(const std::string& service_path); | 1066 explicit WifiNetwork(const std::string& service_path); |
735 virtual ~WifiNetwork(); | 1067 virtual ~WifiNetwork(); |
736 | 1068 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 virtual bool RequiresUserProfile() const; | 1108 virtual bool RequiresUserProfile() const; |
777 | 1109 |
778 // Return a string representation of the encryption code. | 1110 // Return a string representation of the encryption code. |
779 // This not translated and should be only used for debugging purposes. | 1111 // This not translated and should be only used for debugging purposes. |
780 std::string GetEncryptionString() const; | 1112 std::string GetEncryptionString() const; |
781 | 1113 |
782 // Return true if a passphrase or other input is required to connect. | 1114 // Return true if a passphrase or other input is required to connect. |
783 bool IsPassphraseRequired() const; | 1115 bool IsPassphraseRequired() const; |
784 | 1116 |
785 private: | 1117 private: |
786 // Network overrides. | 1118 // This allows NetworkParser and its subclasses access to device |
787 virtual void EraseCredentials(); | 1119 // privates so that they can be reconstituted during parsing. The |
788 virtual void CalculateUniqueId(); | 1120 // parsers only access things through the private set_ functions so |
1121 // that this class can evolve without having to change all the | |
1122 // parsers. | |
1123 NETWORK_LIBRARY_PARSER_FRIENDS; | |
1124 friend class NativeWirelessNetworkParser; | |
1125 friend class NativeWifiNetworkParser; | |
789 | 1126 |
790 // WirelessNetwork overrides. | 1127 // This allows the implementation classes access to privates in the |
791 virtual bool ParseValue(int index, const base::Value* value); | 1128 // same fashion. |
1129 NETWORK_LIBRARY_IMPL_FRIENDS; | |
792 | 1130 |
1131 // Use these functions at your peril. They are used by the various | |
1132 // parsers to set state, and really shouldn't be used by anything else | |
1133 // because they don't do the error checking and sending to the | |
1134 // network layer that the other setters do. | |
793 void set_encryption(ConnectionSecurity encryption) { | 1135 void set_encryption(ConnectionSecurity encryption) { |
794 encryption_ = encryption; | 1136 encryption_ = encryption; |
795 } | 1137 } |
796 void set_passphrase(const std::string& passphrase) { | 1138 void set_passphrase(const std::string& passphrase) { |
797 passphrase_ = passphrase; | 1139 passphrase_ = passphrase; |
1140 user_passphrase_ = passphrase; | |
798 } | 1141 } |
799 void set_passphrase_required(bool passphrase_required) { | 1142 void set_passphrase_required(bool passphrase_required) { |
800 passphrase_required_ = passphrase_required; | 1143 passphrase_required_ = passphrase_required; |
801 } | 1144 } |
802 void set_identity(const std::string& identity) { | 1145 void set_identity(const std::string& identity) { |
803 identity_ = identity; | 1146 identity_ = identity; |
804 } | 1147 } |
1148 void set_eap_method(EAPMethod eap_method) { eap_method_ = eap_method; } | |
1149 void set_eap_phase_2_auth(EAPPhase2Auth eap_phase_2_auth) { | |
1150 eap_phase_2_auth_ = eap_phase_2_auth; | |
1151 } | |
1152 void set_eap_server_ca_cert_nss_nickname( | |
1153 const std::string& eap_server_ca_cert_nss_nickname) { | |
1154 eap_server_ca_cert_nss_nickname_ = eap_server_ca_cert_nss_nickname; | |
1155 } | |
1156 void set_eap_client_cert_pkcs11_id( | |
1157 const std::string& eap_client_cert_pkcs11_id) { | |
1158 eap_client_cert_pkcs11_id_ = eap_client_cert_pkcs11_id; | |
1159 } | |
1160 void set_eap_use_system_cas(bool eap_use_system_cas) { | |
1161 eap_use_system_cas_ = eap_use_system_cas; | |
1162 } | |
1163 void set_eap_identity(const std::string& eap_identity) { | |
1164 eap_identity_ = eap_identity; | |
1165 } | |
1166 void set_eap_anonymous_identity(const std::string& eap_anonymous_identity) { | |
1167 eap_anonymous_identity_ = eap_anonymous_identity; | |
1168 } | |
1169 void set_eap_passphrase(const std::string& eap_passphrase) { | |
1170 eap_passphrase_ = eap_passphrase; | |
1171 } | |
1172 | |
1173 // Network overrides. | |
1174 virtual void EraseCredentials() OVERRIDE; | |
1175 virtual void CalculateUniqueId() OVERRIDE; | |
1176 | |
805 ConnectionSecurity encryption_; | 1177 ConnectionSecurity encryption_; |
806 std::string passphrase_; | 1178 std::string passphrase_; |
807 bool passphrase_required_; | 1179 bool passphrase_required_; |
808 std::string identity_; | 1180 std::string identity_; |
809 | 1181 |
810 EAPMethod eap_method_; | 1182 EAPMethod eap_method_; |
811 EAPPhase2Auth eap_phase_2_auth_; | 1183 EAPPhase2Auth eap_phase_2_auth_; |
812 std::string eap_server_ca_cert_nss_nickname_; | 1184 std::string eap_server_ca_cert_nss_nickname_; |
813 std::string eap_client_cert_pkcs11_id_; | 1185 std::string eap_client_cert_pkcs11_id_; |
814 bool eap_use_system_cas_; | 1186 bool eap_use_system_cas_; |
815 std::string eap_identity_; | 1187 std::string eap_identity_; |
816 std::string eap_anonymous_identity_; | 1188 std::string eap_anonymous_identity_; |
817 std::string eap_passphrase_; | 1189 std::string eap_passphrase_; |
818 | 1190 |
819 // Internal state (not stored in flimflam). | 1191 // Internal state (not stored in flimflam). |
820 // Passphrase set by user (stored for UI). | 1192 // Passphrase set by user (stored for UI). |
821 std::string user_passphrase_; | 1193 std::string user_passphrase_; |
822 | 1194 |
823 friend class NetworkLibraryImplBase; | |
824 friend class NetworkLibraryImplCros; | |
825 friend class NetworkLibraryImplStub; | |
826 DISALLOW_COPY_AND_ASSIGN(WifiNetwork); | 1195 DISALLOW_COPY_AND_ASSIGN(WifiNetwork); |
827 }; | 1196 }; |
828 typedef std::vector<WifiNetwork*> WifiNetworkVector; | 1197 typedef std::vector<WifiNetwork*> WifiNetworkVector; |
829 | 1198 |
830 // Cellular Data Plan management. | 1199 // Cellular Data Plan management. |
831 class CellularDataPlan { | 1200 class CellularDataPlan { |
832 public: | 1201 public: |
833 CellularDataPlan(); | 1202 CellularDataPlan(); |
834 explicit CellularDataPlan(const CellularDataPlanInfo &plan); | 1203 explicit CellularDataPlan(const CellularDataPlanInfo &plan); |
835 ~CellularDataPlan(); | 1204 ~CellularDataPlan(); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 virtual void SwitchToPreferredNetwork() = 0; | 1669 virtual void SwitchToPreferredNetwork() = 0; |
1301 | 1670 |
1302 // Factory function, creates a new instance and returns ownership. | 1671 // Factory function, creates a new instance and returns ownership. |
1303 // For normal usage, access the singleton via CrosLibrary::Get(). | 1672 // For normal usage, access the singleton via CrosLibrary::Get(). |
1304 static NetworkLibrary* GetImpl(bool stub); | 1673 static NetworkLibrary* GetImpl(bool stub); |
1305 }; | 1674 }; |
1306 | 1675 |
1307 } // namespace chromeos | 1676 } // namespace chromeos |
1308 | 1677 |
1309 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 1678 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
OLD | NEW |