OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wake_on_wifi_manager.h" | 5 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 // static | 135 // static |
136 WakeOnWifiManager* WakeOnWifiManager::Get() { | 136 WakeOnWifiManager* WakeOnWifiManager::Get() { |
137 DCHECK(g_wake_on_wifi_manager); | 137 DCHECK(g_wake_on_wifi_manager); |
138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
139 return g_wake_on_wifi_manager; | 139 return g_wake_on_wifi_manager; |
140 } | 140 } |
141 | 141 |
142 WakeOnWifiManager::WakeOnWifiManager() | 142 WakeOnWifiManager::WakeOnWifiManager() |
143 : current_feature_(WakeOnWifiManager::INVALID), | 143 : current_feature_(WakeOnWifiManager::INVALID), |
| 144 extension_event_observer_(new ExtensionEventObserver()), |
144 weak_ptr_factory_(this) { | 145 weak_ptr_factory_(this) { |
145 // This class must be constructed before any users are logged in, i.e., before | 146 // This class must be constructed before any users are logged in, i.e., before |
146 // any profiles are created or added to the ProfileManager. Additionally, | 147 // any profiles are created or added to the ProfileManager. Additionally, |
147 // IsUserLoggedIn always returns true when we are not running on a Chrome OS | 148 // IsUserLoggedIn always returns true when we are not running on a Chrome OS |
148 // device so this check should only run on real devices. | 149 // device so this check should only run on real devices. |
149 CHECK(!base::SysInfo::IsRunningOnChromeOS() || | 150 CHECK(!base::SysInfo::IsRunningOnChromeOS() || |
150 !LoginState::Get()->IsUserLoggedIn()); | 151 !LoginState::Get()->IsUserLoggedIn()); |
151 DCHECK(!g_wake_on_wifi_manager); | 152 DCHECK(!g_wake_on_wifi_manager); |
152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
153 | 154 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 std::string feature_string(WakeOnWifiFeatureToString(feature)); | 210 std::string feature_string(WakeOnWifiFeatureToString(feature)); |
210 DCHECK(!feature_string.empty()); | 211 DCHECK(!feature_string.empty()); |
211 | 212 |
212 NetworkHandler::Get()->network_device_handler()->SetDeviceProperty( | 213 NetworkHandler::Get()->network_device_handler()->SetDeviceProperty( |
213 device->path(), | 214 device->path(), |
214 shill::kWakeOnWiFiFeaturesEnabledProperty, | 215 shill::kWakeOnWiFiFeaturesEnabledProperty, |
215 base::StringValue(feature_string), | 216 base::StringValue(feature_string), |
216 base::Bind(&base::DoNothing), | 217 base::Bind(&base::DoNothing), |
217 network_handler::ErrorCallback()); | 218 network_handler::ErrorCallback()); |
218 | 219 |
219 bool wake_from_suspend = IsWakeOnPacketEnabled(current_feature_); | 220 bool wake_on_packet_enabled = IsWakeOnPacketEnabled(current_feature_); |
220 for (const auto& kv_pair : connection_observers_) { | 221 for (const auto& kv_pair : connection_observers_) { |
221 Profile* profile = kv_pair.first; | 222 Profile* profile = kv_pair.first; |
222 gcm::GCMProfileServiceFactory::GetForProfile(profile) | 223 gcm::GCMProfileServiceFactory::GetForProfile(profile) |
223 ->driver() | 224 ->driver() |
224 ->WakeFromSuspendForHeartbeat(wake_from_suspend); | 225 ->WakeFromSuspendForHeartbeat(wake_on_packet_enabled); |
225 } | 226 } |
| 227 |
| 228 extension_event_observer_->SetShouldDelaySuspend(wake_on_packet_enabled); |
226 } | 229 } |
227 | 230 |
228 bool WakeOnWifiManager::WakeOnWifiSupported() { | 231 bool WakeOnWifiManager::WakeOnWifiSupported() { |
229 return current_feature_ != NOT_SUPPORTED && current_feature_ != INVALID; | 232 return current_feature_ != NOT_SUPPORTED && current_feature_ != INVALID; |
230 } | 233 } |
231 | 234 |
232 void WakeOnWifiManager::GetDevicePropertiesCallback( | 235 void WakeOnWifiManager::GetDevicePropertiesCallback( |
233 const std::string& device_path, | 236 const std::string& device_path, |
234 const base::DictionaryValue& properties) { | 237 const base::DictionaryValue& properties) { |
235 if (!properties.HasKey(shill::kWakeOnWiFiFeaturesEnabledProperty)) | 238 if (!properties.HasKey(shill::kWakeOnWiFiFeaturesEnabledProperty)) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ->WakeFromSuspendForHeartbeat( | 276 ->WakeFromSuspendForHeartbeat( |
274 IsWakeOnPacketEnabled(current_feature_)); | 277 IsWakeOnPacketEnabled(current_feature_)); |
275 } | 278 } |
276 } | 279 } |
277 | 280 |
278 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) { | 281 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) { |
279 connection_observers_.erase(profile); | 282 connection_observers_.erase(profile); |
280 } | 283 } |
281 | 284 |
282 } // namespace chromeos | 285 } // namespace chromeos |
OLD | NEW |