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

Unified Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 11367048: This is the first pass at making GetIPConfigs asynchronous. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/cros/network_library.cc
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index ba81959f9ca67c62995c2401e8004f193d89b7ea..7fe99f24042d75010f71607cf3f411eba73fef12 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -227,7 +227,8 @@ Network::Network(const std::string& service_path,
notify_failure_(false),
profile_type_(PROFILE_NONE),
service_path_(service_path),
- type_(type) {
+ type_(type),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) {
}
Network::~Network() {
@@ -320,7 +321,6 @@ void Network::SetState(ConnectionState new_state) {
} else if (new_state != STATE_UNKNOWN) {
notify_failure_ = false;
// State changed, so refresh IP address.
- // Note: blocking DBus call. TODO(stevenjb): refactor this.
InitIPAddress();
}
VLOG(1) << name() << ".State [" << service_path() << "]: " << GetStateString()
@@ -515,15 +515,20 @@ void Network::InitIPAddress() {
return;
// If connected, get ip config.
if (connected() && !device_path_.empty()) {
- NetworkIPConfigVector ipconfigs;
- if (CrosListIPConfigs(device_path_, &ipconfigs, NULL, NULL)) {
- for (size_t i = 0; i < ipconfigs.size(); ++i) {
- const NetworkIPConfig& ipconfig = ipconfigs[i];
- if (ipconfig.address.size() > 0) {
- ip_address_ = ipconfig.address;
- break;
- }
- }
+ CrosListIPConfigs(device_path_,
+ base::Bind(&Network::InitIPAddressCallback,
+ weak_pointer_factory_.GetWeakPtr()));
stevenjb 2012/11/05 23:22:58 I'd actually rather avoid the overhead of a WeakPt
+ }
+}
+
+void Network::InitIPAddressCallback(
+ const NetworkIPConfigVector& ip_configs,
+ const std::string& hardware_address) {
+ for (size_t i = 0; i < ip_configs.size(); ++i) {
+ const NetworkIPConfig& ipconfig = ip_configs[i];
+ if (ipconfig.address.size() > 0) {
+ ip_address_ = ipconfig.address;
+ break;
}
}
}
@@ -1313,8 +1318,7 @@ void WifiNetwork::MatchCertificatePattern(bool allow_enroll,
WimaxNetwork::WimaxNetwork(const std::string& service_path)
: WirelessNetwork(service_path, TYPE_WIMAX),
- passphrase_required_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) {
+ passphrase_required_(false) {
}
WimaxNetwork::~WimaxNetwork() {

Powered by Google App Engine
This is Rietveld 408576698