| 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 #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" | 5 #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 NetworkChangeNotifierChromeos* parent_; | 58 NetworkChangeNotifierChromeos* parent_; |
| 59 bool is_online_; | 59 bool is_online_; |
| 60 bool should_report_; | 60 bool should_report_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() | 63 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() |
| 64 : has_active_network_(false), | 64 : has_active_network_(false), |
| 65 connection_state_(chromeos::STATE_UNKNOWN), | 65 connection_state_(chromeos::STATE_UNKNOWN), |
| 66 online_notification_task_(NULL) { | 66 online_notification_task_(NULL) { |
| 67 | 67 |
| 68 chromeos::NetworkLibrary* net = | |
| 69 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 70 net->AddNetworkManagerObserver(this); | |
| 71 | |
| 72 chromeos::PowerLibrary* power = | |
| 73 chromeos::CrosLibrary::Get()->GetPowerLibrary(); | |
| 74 power->AddObserver(this); | |
| 75 | |
| 76 UpdateNetworkState(net); | |
| 77 BrowserThread::PostDelayedTask( | 68 BrowserThread::PostDelayedTask( |
| 78 BrowserThread::UI, FROM_HERE, | 69 BrowserThread::UI, FROM_HERE, |
| 79 base::Bind( | 70 base::Bind( |
| 80 &NetworkChangeNotifierChromeos::UpdateInitialState, this), | 71 &NetworkChangeNotifierChromeos::UpdateInitialState, this), |
| 81 kInitialNotificationCheckDelayMS); | 72 kInitialNotificationCheckDelayMS); |
| 82 } | 73 } |
| 83 | 74 |
| 84 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { | 75 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { |
| 85 if (online_notification_task_) { | 76 if (online_notification_task_) { |
| 86 online_notification_task_->Cancel(); | 77 online_notification_task_->Cancel(); |
| 87 online_notification_task_ = NULL; | 78 online_notification_task_ = NULL; |
| 88 } | 79 } |
| 89 if (!chromeos::CrosLibrary::Get()) | 80 if (!chromeos::CrosLibrary::Get()) |
| 90 return; | 81 return; |
| 91 chromeos::NetworkLibrary* lib = | 82 chromeos::NetworkLibrary* lib = |
| 92 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 83 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 93 lib->RemoveNetworkManagerObserver(this); | 84 lib->RemoveNetworkManagerObserver(this); |
| 94 lib->RemoveObserverForAllNetworks(this); | 85 lib->RemoveObserverForAllNetworks(this); |
| 95 | 86 |
| 96 chromeos::PowerLibrary* power = | 87 chromeos::PowerLibrary* power = |
| 97 chromeos::CrosLibrary::Get()->GetPowerLibrary(); | 88 chromeos::CrosLibrary::Get()->GetPowerLibrary(); |
| 98 power->RemoveObserver(this); | 89 power->RemoveObserver(this); |
| 99 } | 90 } |
| 100 | 91 |
| 92 void NetworkChangeNotifierChromeos::Init() { |
| 93 chromeos::NetworkLibrary* network_library = |
| 94 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 95 network_library->AddNetworkManagerObserver(this); |
| 96 |
| 97 chromeos::CrosLibrary::Get()->GetPowerLibrary() |
| 98 ->AddObserver(this); |
| 99 |
| 100 UpdateNetworkState(network_library); |
| 101 } |
| 102 |
| 101 void NetworkChangeNotifierChromeos::PowerChanged( | 103 void NetworkChangeNotifierChromeos::PowerChanged( |
| 102 const PowerSupplyStatus& status) { | 104 const PowerSupplyStatus& status) { |
| 103 } | 105 } |
| 104 | 106 |
| 105 void NetworkChangeNotifierChromeos::SystemResumed() { | 107 void NetworkChangeNotifierChromeos::SystemResumed() { |
| 106 // Force invalidation of various net resources on system resume. | 108 // Force invalidation of various net resources on system resume. |
| 107 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 108 BrowserThread::IO, FROM_HERE, | 110 BrowserThread::IO, FROM_HERE, |
| 109 base::Bind( | 111 base::Bind( |
| 110 &NetworkChangeNotifier::NotifyObserversOfIPAddressChange)); | 112 &NetworkChangeNotifier::NotifyObserversOfIPAddressChange)); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 252 } |
| 251 | 253 |
| 252 // static | 254 // static |
| 253 void NetworkChangeNotifierChromeos::UpdateInitialState( | 255 void NetworkChangeNotifierChromeos::UpdateInitialState( |
| 254 NetworkChangeNotifierChromeos* self) { | 256 NetworkChangeNotifierChromeos* self) { |
| 255 chromeos::NetworkLibrary* net = | 257 chromeos::NetworkLibrary* net = |
| 256 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 258 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 257 self->UpdateNetworkState(net); | 259 self->UpdateNetworkState(net); |
| 258 } | 260 } |
| 259 | 261 |
| 260 } // namespace net | 262 } // namespace chromeos |
| OLD | NEW |