Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
| 10 #include "base/json/json_writer.h" // for debug output only. | 10 #include "base/json/json_writer.h" // for debug output only. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 connection_started_(false), | 220 connection_started_(false), |
| 221 is_active_(false), | 221 is_active_(false), |
| 222 priority_(kPriorityNotSet), | 222 priority_(kPriorityNotSet), |
| 223 auto_connect_(false), | 223 auto_connect_(false), |
| 224 save_credentials_(false), | 224 save_credentials_(false), |
| 225 priority_order_(0), | 225 priority_order_(0), |
| 226 added_(false), | 226 added_(false), |
| 227 notify_failure_(false), | 227 notify_failure_(false), |
| 228 profile_type_(PROFILE_NONE), | 228 profile_type_(PROFILE_NONE), |
| 229 service_path_(service_path), | 229 service_path_(service_path), |
| 230 type_(type) { | 230 type_(type), |
| 231 ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) { | |
| 231 } | 232 } |
| 232 | 233 |
| 233 Network::~Network() { | 234 Network::~Network() { |
| 234 for (PropertyMap::const_iterator props = property_map_.begin(); | 235 for (PropertyMap::const_iterator props = property_map_.begin(); |
| 235 props != property_map_.end(); ++props) { | 236 props != property_map_.end(); ++props) { |
| 236 delete props->second; | 237 delete props->second; |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 Network::ProxyOncConfig::ProxyOncConfig() : type(PROXY_ONC_DIRECT) {} | 241 Network::ProxyOncConfig::ProxyOncConfig() : type(PROXY_ONC_DIRECT) {} |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 } else if (new_state == STATE_IDLE && IsConnectingState(old_state) | 314 } else if (new_state == STATE_IDLE && IsConnectingState(old_state) |
| 314 && connection_started()) { | 315 && connection_started()) { |
| 315 // If we requested a connect and never went through a connected state, | 316 // If we requested a connect and never went through a connected state, |
| 316 // treat it as a failure. | 317 // treat it as a failure. |
| 317 VLOG(1) << service_path() << ": Inferring Failure state."; | 318 VLOG(1) << service_path() << ": Inferring Failure state."; |
| 318 notify_failure_ = true; | 319 notify_failure_ = true; |
| 319 error_ = ERROR_UNKNOWN; | 320 error_ = ERROR_UNKNOWN; |
| 320 } else if (new_state != STATE_UNKNOWN) { | 321 } else if (new_state != STATE_UNKNOWN) { |
| 321 notify_failure_ = false; | 322 notify_failure_ = false; |
| 322 // State changed, so refresh IP address. | 323 // State changed, so refresh IP address. |
| 323 // Note: blocking DBus call. TODO(stevenjb): refactor this. | |
| 324 InitIPAddress(); | 324 InitIPAddress(); |
| 325 } | 325 } |
| 326 VLOG(1) << name() << ".State [" << service_path() << "]: " << GetStateString() | 326 VLOG(1) << name() << ".State [" << service_path() << "]: " << GetStateString() |
| 327 << " (was: " << ConnectionStateString(old_state) << ")"; | 327 << " (was: " << ConnectionStateString(old_state) << ")"; |
| 328 if (!IsConnectingState(new_state) && new_state != STATE_UNKNOWN) | 328 if (!IsConnectingState(new_state) && new_state != STATE_UNKNOWN) |
| 329 set_connection_started(false); | 329 set_connection_started(false); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void Network::SetError(ConnectionError error) { | 332 void Network::SetError(ConnectionError error) { |
| 333 error_ = error; | 333 error_ = error; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 SetOrClearStringProperty( | 508 SetOrClearStringProperty( |
| 509 flimflam::kProxyConfigProperty, proxy_config, &proxy_config_); | 509 flimflam::kProxyConfigProperty, proxy_config, &proxy_config_); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void Network::InitIPAddress() { | 512 void Network::InitIPAddress() { |
| 513 ip_address_.clear(); | 513 ip_address_.clear(); |
| 514 if (!EnsureCrosLoaded()) | 514 if (!EnsureCrosLoaded()) |
| 515 return; | 515 return; |
| 516 // If connected, get ip config. | 516 // If connected, get ip config. |
| 517 if (connected() && !device_path_.empty()) { | 517 if (connected() && !device_path_.empty()) { |
| 518 NetworkIPConfigVector ipconfigs; | 518 CrosListIPConfigs(device_path_, |
| 519 if (CrosListIPConfigs(device_path_, &ipconfigs, NULL, NULL)) { | 519 base::Bind(&Network::InitIPAddressCallback, |
| 520 for (size_t i = 0; i < ipconfigs.size(); ++i) { | 520 weak_pointer_factory_.GetWeakPtr())); |
|
stevenjb
2012/11/05 23:22:58
I'd actually rather avoid the overhead of a WeakPt
| |
| 521 const NetworkIPConfig& ipconfig = ipconfigs[i]; | 521 } |
| 522 if (ipconfig.address.size() > 0) { | 522 } |
| 523 ip_address_ = ipconfig.address; | 523 |
| 524 break; | 524 void Network::InitIPAddressCallback( |
| 525 } | 525 const NetworkIPConfigVector& ip_configs, |
| 526 } | 526 const std::string& hardware_address) { |
| 527 for (size_t i = 0; i < ip_configs.size(); ++i) { | |
| 528 const NetworkIPConfig& ipconfig = ip_configs[i]; | |
| 529 if (ipconfig.address.size() > 0) { | |
| 530 ip_address_ = ipconfig.address; | |
| 531 break; | |
| 527 } | 532 } |
| 528 } | 533 } |
| 529 } | 534 } |
| 530 | 535 |
| 531 bool Network::UpdateStatus(const std::string& key, | 536 bool Network::UpdateStatus(const std::string& key, |
| 532 const Value& value, | 537 const Value& value, |
| 533 PropertyIndex* index) { | 538 PropertyIndex* index) { |
| 534 if (network_parser_.get()) | 539 if (network_parser_.get()) |
| 535 return network_parser_->UpdateStatus(key, value, this, index); | 540 return network_parser_->UpdateStatus(key, value, this, index); |
| 536 return false; | 541 return false; |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1306 } | 1311 } |
| 1307 } | 1312 } |
| 1308 connect.Run(); | 1313 connect.Run(); |
| 1309 } | 1314 } |
| 1310 | 1315 |
| 1311 //////////////////////////////////////////////////////////////////////////////// | 1316 //////////////////////////////////////////////////////////////////////////////// |
| 1312 // WimaxNetwork | 1317 // WimaxNetwork |
| 1313 | 1318 |
| 1314 WimaxNetwork::WimaxNetwork(const std::string& service_path) | 1319 WimaxNetwork::WimaxNetwork(const std::string& service_path) |
| 1315 : WirelessNetwork(service_path, TYPE_WIMAX), | 1320 : WirelessNetwork(service_path, TYPE_WIMAX), |
| 1316 passphrase_required_(false), | 1321 passphrase_required_(false) { |
| 1317 ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) { | |
| 1318 } | 1322 } |
| 1319 | 1323 |
| 1320 WimaxNetwork::~WimaxNetwork() { | 1324 WimaxNetwork::~WimaxNetwork() { |
| 1321 } | 1325 } |
| 1322 | 1326 |
| 1323 void WimaxNetwork::EraseCredentials() { | 1327 void WimaxNetwork::EraseCredentials() { |
| 1324 WipeString(&eap_passphrase_); | 1328 WipeString(&eap_passphrase_); |
| 1325 WipeString(&eap_identity_); | 1329 WipeString(&eap_identity_); |
| 1326 } | 1330 } |
| 1327 | 1331 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1358 NetworkLibrary* impl; | 1362 NetworkLibrary* impl; |
| 1359 if (stub) | 1363 if (stub) |
| 1360 impl = new NetworkLibraryImplStub(); | 1364 impl = new NetworkLibraryImplStub(); |
| 1361 else | 1365 else |
| 1362 impl = new NetworkLibraryImplCros(); | 1366 impl = new NetworkLibraryImplCros(); |
| 1363 impl->Init(); | 1367 impl->Init(); |
| 1364 return impl; | 1368 return impl; |
| 1365 } | 1369 } |
| 1366 | 1370 |
| 1367 } // namespace chromeos | 1371 } // namespace chromeos |
| OLD | NEW |