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

Side by Side Diff: chrome/browser/chromeos/net/wake_on_wifi_manager.cc

Issue 811973002: Enable lucid sleep (wake on wi-fi SSID) and add to Privacy options. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add function to chromeos::switches. rebase Created 5 years, 12 months 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 unified diff | Download patch
OLDNEW
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/command_line.h"
11 #include "base/containers/scoped_ptr_hash_map.h" 10 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/sys_info.h" 14 #include "base/sys_info.h"
15 #include "base/values.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/services/gcm/gcm_profile_service.h" 18 #include "chrome/browser/services/gcm/gcm_profile_service.h"
19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
20 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/login/login_state.h" 21 #include "chromeos/login/login_state.h"
21 #include "chromeos/network/device_state.h" 22 #include "chromeos/network/device_state.h"
22 #include "chromeos/network/network_device_handler.h" 23 #include "chromeos/network/network_device_handler.h"
23 #include "chromeos/network/network_handler.h" 24 #include "chromeos/network/network_handler.h"
24 #include "chromeos/network/network_state_handler.h" 25 #include "chromeos/network/network_state_handler.h"
25 #include "chromeos/network/network_type_pattern.h" 26 #include "chromeos/network/network_type_pattern.h"
26 #include "components/gcm_driver/gcm_connection_observer.h" 27 #include "components/gcm_driver/gcm_connection_observer.h"
27 #include "components/gcm_driver/gcm_driver.h" 28 #include "components/gcm_driver/gcm_driver.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
(...skipping 16 matching lines...) Expand all
46 case WakeOnWifiManager::WAKE_ON_NONE: 47 case WakeOnWifiManager::WAKE_ON_NONE:
47 return kWakeOnNone; 48 return kWakeOnNone;
48 case WakeOnWifiManager::WAKE_ON_PACKET: 49 case WakeOnWifiManager::WAKE_ON_PACKET:
49 return kWakeOnPacket; 50 return kWakeOnPacket;
50 case WakeOnWifiManager::WAKE_ON_SSID: 51 case WakeOnWifiManager::WAKE_ON_SSID:
51 return kWakeOnSsid; 52 return kWakeOnSsid;
52 case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID: 53 case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID:
53 return kWakeOnPacketAndSsid; 54 return kWakeOnPacketAndSsid;
54 case WakeOnWifiManager::INVALID: 55 case WakeOnWifiManager::INVALID:
55 return std::string(); 56 return std::string();
57 case WakeOnWifiManager::NOT_SUPPORTED:
58 NOTREACHED();
59 return std::string();
56 } 60 }
57 61
58 NOTREACHED() << "Unknown wake on wifi feature: " << feature; 62 NOTREACHED() << "Unknown wake on wifi feature: " << feature;
59 return std::string(); 63 return std::string();
60 } 64 }
61 65
62 bool IsWakeOnPacketEnabled(WakeOnWifiManager::WakeOnWifiFeature feature) { 66 bool IsWakeOnPacketEnabled(WakeOnWifiManager::WakeOnWifiFeature feature) {
63 return feature == WakeOnWifiManager::WAKE_ON_PACKET || 67 return feature & WakeOnWifiManager::WAKE_ON_PACKET;
64 feature == WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID;
65 } 68 }
66 69
67 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos. 70 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos.
68 WakeOnWifiManager* g_wake_on_wifi_manager = NULL; 71 WakeOnWifiManager* g_wake_on_wifi_manager = NULL;
69 72
70 } // namespace 73 } // namespace
71 74
72 // Simple class that listens for a connection to the GCM server and passes the 75 // Simple class that listens for a connection to the GCM server and passes the
73 // connection information down to shill. Each profile gets its own instance of 76 // connection information down to shill. Each profile gets its own instance of
74 // this class. 77 // this class.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 }; 133 };
131 134
132 // static 135 // static
133 WakeOnWifiManager* WakeOnWifiManager::Get() { 136 WakeOnWifiManager* WakeOnWifiManager::Get() {
134 DCHECK(g_wake_on_wifi_manager); 137 DCHECK(g_wake_on_wifi_manager);
135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
136 return g_wake_on_wifi_manager; 139 return g_wake_on_wifi_manager;
137 } 140 }
138 141
139 WakeOnWifiManager::WakeOnWifiManager() 142 WakeOnWifiManager::WakeOnWifiManager()
140 : current_feature_(WakeOnWifiManager::INVALID) { 143 : current_feature_(WakeOnWifiManager::INVALID),
144 weak_ptr_factory_(this) {
141 // This class must be constructed before any users are logged in, i.e., before 145 // This class must be constructed before any users are logged in, i.e., before
142 // any profiles are created or added to the ProfileManager. Additionally, 146 // any profiles are created or added to the ProfileManager. Additionally,
143 // IsUserLoggedIn always returns true when we are not running on a Chrome OS 147 // IsUserLoggedIn always returns true when we are not running on a Chrome OS
144 // device so this check should only run on real devices. 148 // device so this check should only run on real devices.
145 CHECK(!base::SysInfo::IsRunningOnChromeOS() || 149 CHECK(!base::SysInfo::IsRunningOnChromeOS() ||
146 !LoginState::Get()->IsUserLoggedIn()); 150 !LoginState::Get()->IsUserLoggedIn());
147 DCHECK(!g_wake_on_wifi_manager); 151 DCHECK(!g_wake_on_wifi_manager);
148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
149 153
150 g_wake_on_wifi_manager = this; 154 g_wake_on_wifi_manager = this;
151 155
152 registrar_.Add(this, 156 registrar_.Add(this,
153 chrome::NOTIFICATION_PROFILE_ADDED, 157 chrome::NOTIFICATION_PROFILE_ADDED,
154 content::NotificationService::AllBrowserContextsAndSources()); 158 content::NotificationService::AllBrowserContextsAndSources());
155 registrar_.Add(this, 159 registrar_.Add(this,
156 chrome::NOTIFICATION_PROFILE_DESTROYED, 160 chrome::NOTIFICATION_PROFILE_DESTROYED,
157 content::NotificationService::AllBrowserContextsAndSources()); 161 content::NotificationService::AllBrowserContextsAndSources());
158 162
159 NetworkHandler::Get() 163 NetworkHandler::Get()
160 ->network_device_handler() 164 ->network_device_handler()
161 ->RemoveAllWifiWakeOnPacketConnections( 165 ->RemoveAllWifiWakeOnPacketConnections(
162 base::Bind(&base::DoNothing), 166 base::Bind(&base::DoNothing),
163 network_handler::ErrorCallback()); 167 network_handler::ErrorCallback());
168
169 if (!switches::WakeOnWifiEnabled())
170 return;
171
172 const DeviceState* device =
173 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
174 NetworkTypePattern::WiFi());
175 if (!device)
176 return;
177 // Get device properties to check whether wake-on-wifi is supported.
178 NetworkHandler::Get()->network_device_handler()->GetDeviceProperties(
179 device->path(),
180 base::Bind(&WakeOnWifiManager::GetDevicePropertiesCallback,
181 weak_ptr_factory_.GetWeakPtr()),
182 network_handler::ErrorCallback());
164 } 183 }
165 184
166 WakeOnWifiManager::~WakeOnWifiManager() { 185 WakeOnWifiManager::~WakeOnWifiManager() {
167 DCHECK(g_wake_on_wifi_manager); 186 DCHECK(g_wake_on_wifi_manager);
168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 187 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
169 g_wake_on_wifi_manager = NULL; 188 g_wake_on_wifi_manager = NULL;
170 } 189 }
171 190
172 void WakeOnWifiManager::OnPreferenceChanged( 191 void WakeOnWifiManager::OnPreferenceChanged(
173 WakeOnWifiManager::WakeOnWifiFeature feature) { 192 WakeOnWifiManager::WakeOnWifiFeature feature) {
174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
194 if (current_feature_ == NOT_SUPPORTED)
195 return;
196 if (!switches::WakeOnWifiEnabled())
197 feature = WAKE_ON_NONE;
175 if (feature == current_feature_) 198 if (feature == current_feature_)
176 return; 199 return;
177 200
178 current_feature_ = feature; 201 current_feature_ = feature;
179 202
180 const DeviceState* device = 203 const DeviceState* device =
181 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( 204 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
182 NetworkTypePattern::WiFi()); 205 NetworkTypePattern::WiFi());
183 if (!device) 206 if (!device)
184 return; 207 return;
(...skipping 10 matching lines...) Expand all
195 218
196 bool wake_from_suspend = IsWakeOnPacketEnabled(current_feature_); 219 bool wake_from_suspend = IsWakeOnPacketEnabled(current_feature_);
197 for (const auto& kv_pair : connection_observers_) { 220 for (const auto& kv_pair : connection_observers_) {
198 Profile* profile = kv_pair.first; 221 Profile* profile = kv_pair.first;
199 gcm::GCMProfileServiceFactory::GetForProfile(profile) 222 gcm::GCMProfileServiceFactory::GetForProfile(profile)
200 ->driver() 223 ->driver()
201 ->WakeFromSuspendForHeartbeat(wake_from_suspend); 224 ->WakeFromSuspendForHeartbeat(wake_from_suspend);
202 } 225 }
203 } 226 }
204 227
228 bool WakeOnWifiManager::WakeOnWifiSupported() {
229 return current_feature_ != NOT_SUPPORTED && current_feature_ != INVALID;
230 }
231
232 void WakeOnWifiManager::GetDevicePropertiesCallback(
233 const std::string& device_path,
234 const base::DictionaryValue& properties) {
235 if (!properties.HasKey(shill::kWakeOnWiFiFeaturesEnabledProperty))
236 return;
237 std::string enabled;
238 if (properties.GetString(shill::kWakeOnWiFiFeaturesEnabledProperty,
239 &enabled) &&
240 enabled == shill::kWakeOnWiFiFeaturesEnabledNotSupported) {
241 current_feature_ = NOT_SUPPORTED;
242 }
243 }
244
205 void WakeOnWifiManager::Observe(int type, 245 void WakeOnWifiManager::Observe(int type,
206 const content::NotificationSource& source, 246 const content::NotificationSource& source,
207 const content::NotificationDetails& details) { 247 const content::NotificationDetails& details) {
208 switch (type) { 248 switch (type) {
209 case chrome::NOTIFICATION_PROFILE_ADDED: { 249 case chrome::NOTIFICATION_PROFILE_ADDED: {
210 OnProfileAdded(content::Source<Profile>(source).ptr()); 250 OnProfileAdded(content::Source<Profile>(source).ptr());
211 break; 251 break;
212 } 252 }
213 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 253 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
214 OnProfileDestroyed(content::Source<Profile>(source).ptr()); 254 OnProfileDestroyed(content::Source<Profile>(source).ptr());
(...skipping 18 matching lines...) Expand all
233 ->WakeFromSuspendForHeartbeat( 273 ->WakeFromSuspendForHeartbeat(
234 IsWakeOnPacketEnabled(current_feature_)); 274 IsWakeOnPacketEnabled(current_feature_));
235 } 275 }
236 } 276 }
237 277
238 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) { 278 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) {
239 connection_observers_.erase(profile); 279 connection_observers_.erase(profile);
240 } 280 }
241 281
242 } // namespace chromeos 282 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/wake_on_wifi_manager.h ('k') | chrome/browser/chromeos/preferences.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698