| 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 "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 // Delay for online change notification reporting. | 14 // Delay for online change notification reporting. |
| 14 const int kOnlineNotificationDelayMS = 500; | 15 const int kOnlineNotificationDelayMS = 500; |
| 15 const int kInitialNotificationCheckDelayMS = 1000; | 16 const int kInitialNotificationCheckDelayMS = 1000; |
| 16 | 17 |
| 17 bool IsOnline(chromeos::ConnectionState state) { | 18 bool IsOnline(chromeos::ConnectionState state) { |
| 18 return state == chromeos::STATE_ONLINE || | 19 return state == chromeos::STATE_ONLINE || |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 61 |
| 61 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() | 62 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() |
| 62 : has_active_network_(false), | 63 : has_active_network_(false), |
| 63 connection_state_(chromeos::STATE_UNKNOWN), | 64 connection_state_(chromeos::STATE_UNKNOWN), |
| 64 online_notification_task_(NULL) { | 65 online_notification_task_(NULL) { |
| 65 | 66 |
| 66 chromeos::NetworkLibrary* net = | 67 chromeos::NetworkLibrary* net = |
| 67 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 68 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 68 net->AddNetworkManagerObserver(this); | 69 net->AddNetworkManagerObserver(this); |
| 69 | 70 |
| 70 chromeos::PowerLibrary* power = | 71 chromeos::PowerLibrary* power_lib = |
| 71 chromeos::CrosLibrary::Get()->GetPowerLibrary(); | 72 chromeos::CrosLibrary::Get()->GetPowerLibrary(); |
| 72 power->AddObserver(this); | 73 power_lib->AddObserver(this); |
| 74 |
| 75 chromeos::PowerManagerClient* power_client = |
| 76 chromeos::DBusThreadManager::Get()->power_manager_client(); |
| 77 power_client->AddObserver(this); |
| 73 | 78 |
| 74 UpdateNetworkState(net); | 79 UpdateNetworkState(net); |
| 75 BrowserThread::PostDelayedTask( | 80 BrowserThread::PostDelayedTask( |
| 76 BrowserThread::UI, FROM_HERE, | 81 BrowserThread::UI, FROM_HERE, |
| 77 base::Bind( | 82 base::Bind( |
| 78 &NetworkChangeNotifierChromeos::UpdateInitialState, this), | 83 &NetworkChangeNotifierChromeos::UpdateInitialState, this), |
| 79 kInitialNotificationCheckDelayMS); | 84 kInitialNotificationCheckDelayMS); |
| 80 } | 85 } |
| 81 | 86 |
| 82 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { | 87 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { |
| 83 if (online_notification_task_) { | 88 if (online_notification_task_) { |
| 84 online_notification_task_->Cancel(); | 89 online_notification_task_->Cancel(); |
| 85 online_notification_task_ = NULL; | 90 online_notification_task_ = NULL; |
| 86 } | 91 } |
| 87 if (!chromeos::CrosLibrary::Get()) | 92 if (!chromeos::CrosLibrary::Get()) |
| 88 return; | 93 return; |
| 89 chromeos::NetworkLibrary* lib = | 94 chromeos::NetworkLibrary* lib = |
| 90 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 95 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 91 lib->RemoveNetworkManagerObserver(this); | 96 lib->RemoveNetworkManagerObserver(this); |
| 92 lib->RemoveObserverForAllNetworks(this); | 97 lib->RemoveObserverForAllNetworks(this); |
| 93 | 98 |
| 94 chromeos::PowerLibrary* power = | 99 chromeos::PowerLibrary* power_lib = |
| 95 chromeos::CrosLibrary::Get()->GetPowerLibrary(); | 100 chromeos::CrosLibrary::Get()->GetPowerLibrary(); |
| 96 power->RemoveObserver(this); | 101 power_lib->RemoveObserver(this); |
| 102 |
| 103 chromeos::PowerManagerClient* power_client = |
| 104 chromeos::DBusThreadManager::Get()->power_manager_client(); |
| 105 power_client->RemoveObserver(this); |
| 97 } | 106 } |
| 98 | 107 |
| 99 void NetworkChangeNotifierChromeos::PowerChanged( | 108 void NetworkChangeNotifierChromeos::PowerChanged( |
| 100 const PowerSupplyStatus& status) { | 109 const PowerSupplyStatus& status) { |
| 101 } | 110 } |
| 102 | 111 |
| 103 void NetworkChangeNotifierChromeos::SystemResumed() { | 112 void NetworkChangeNotifierChromeos::SystemResumed() { |
| 104 // Force invalidation of various net resources on system resume. | 113 // Force invalidation of various net resources on system resume. |
| 105 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
| 106 BrowserThread::IO, FROM_HERE, | 115 BrowserThread::IO, FROM_HERE, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 258 |
| 250 // static | 259 // static |
| 251 void NetworkChangeNotifierChromeos::UpdateInitialState( | 260 void NetworkChangeNotifierChromeos::UpdateInitialState( |
| 252 NetworkChangeNotifierChromeos* self) { | 261 NetworkChangeNotifierChromeos* self) { |
| 253 chromeos::NetworkLibrary* net = | 262 chromeos::NetworkLibrary* net = |
| 254 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 263 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 255 self->UpdateNetworkState(net); | 264 self->UpdateNetworkState(net); |
| 256 } | 265 } |
| 257 | 266 |
| 258 } // namespace net | 267 } // namespace net |
| OLD | NEW |