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

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

Issue 745123002: Link GCM heartbeat with wake on wifi preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing include Created 6 years 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" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 WakeOnWifiManager::WakeOnWifiFeature feature) { 44 WakeOnWifiManager::WakeOnWifiFeature feature) {
45 switch (feature) { 45 switch (feature) {
46 case WakeOnWifiManager::WAKE_ON_NONE: 46 case WakeOnWifiManager::WAKE_ON_NONE:
47 return kWakeOnNone; 47 return kWakeOnNone;
48 case WakeOnWifiManager::WAKE_ON_PACKET: 48 case WakeOnWifiManager::WAKE_ON_PACKET:
49 return kWakeOnPacket; 49 return kWakeOnPacket;
50 case WakeOnWifiManager::WAKE_ON_SSID: 50 case WakeOnWifiManager::WAKE_ON_SSID:
51 return kWakeOnSsid; 51 return kWakeOnSsid;
52 case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID: 52 case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID:
53 return kWakeOnPacketAndSsid; 53 return kWakeOnPacketAndSsid;
54 case WakeOnWifiManager::INVALID:
55 return std::string();
54 } 56 }
55 57
56 NOTREACHED() << "Unknown wake on wifi feature: " << feature; 58 NOTREACHED() << "Unknown wake on wifi feature: " << feature;
57 return std::string(); 59 return std::string();
58 } 60 }
59 61
62 bool IsWakeOnPacketEnabled(WakeOnWifiManager::WakeOnWifiFeature feature) {
63 return feature == WakeOnWifiManager::WAKE_ON_PACKET ||
64 feature == WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID;
65 }
66
60 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos. 67 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos.
61 WakeOnWifiManager* g_wake_on_wifi_manager = NULL; 68 WakeOnWifiManager* g_wake_on_wifi_manager = NULL;
62 69
63 } // namespace 70 } // namespace
64 71
65 // Simple class that listens for a connection to the GCM server and passes the 72 // Simple class that listens for a connection to the GCM server and passes the
66 // connection information down to shill. Each profile gets its own instance of 73 // connection information down to shill. Each profile gets its own instance of
67 // this class. 74 // this class.
68 class WakeOnWifiManager::WakeOnPacketConnectionObserver 75 class WakeOnWifiManager::WakeOnPacketConnectionObserver
69 : public gcm::GCMConnectionObserver { 76 : public gcm::GCMConnectionObserver {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DISALLOW_COPY_AND_ASSIGN(WakeOnPacketConnectionObserver); 129 DISALLOW_COPY_AND_ASSIGN(WakeOnPacketConnectionObserver);
123 }; 130 };
124 131
125 // static 132 // static
126 WakeOnWifiManager* WakeOnWifiManager::Get() { 133 WakeOnWifiManager* WakeOnWifiManager::Get() {
127 DCHECK(g_wake_on_wifi_manager); 134 DCHECK(g_wake_on_wifi_manager);
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
129 return g_wake_on_wifi_manager; 136 return g_wake_on_wifi_manager;
130 } 137 }
131 138
132 WakeOnWifiManager::WakeOnWifiManager() { 139 WakeOnWifiManager::WakeOnWifiManager()
140 : current_feature_(WakeOnWifiManager::INVALID) {
133 // This class must be constructed before any users are logged in, i.e., before 141 // This class must be constructed before any users are logged in, i.e., before
134 // any profiles are created or added to the ProfileManager. Additionally, 142 // any profiles are created or added to the ProfileManager. Additionally,
135 // IsUserLoggedIn always returns true when we are not running on a Chrome OS 143 // IsUserLoggedIn always returns true when we are not running on a Chrome OS
136 // device so this check should only run on real devices. 144 // device so this check should only run on real devices.
137 CHECK(!base::SysInfo::IsRunningOnChromeOS() || 145 CHECK(!base::SysInfo::IsRunningOnChromeOS() ||
138 !LoginState::Get()->IsUserLoggedIn()); 146 !LoginState::Get()->IsUserLoggedIn());
139 DCHECK(!g_wake_on_wifi_manager); 147 DCHECK(!g_wake_on_wifi_manager);
140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
141 149
142 g_wake_on_wifi_manager = this; 150 g_wake_on_wifi_manager = this;
(...skipping 14 matching lines...) Expand all
157 165
158 WakeOnWifiManager::~WakeOnWifiManager() { 166 WakeOnWifiManager::~WakeOnWifiManager() {
159 DCHECK(g_wake_on_wifi_manager); 167 DCHECK(g_wake_on_wifi_manager);
160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
161 g_wake_on_wifi_manager = NULL; 169 g_wake_on_wifi_manager = NULL;
162 } 170 }
163 171
164 void WakeOnWifiManager::OnPreferenceChanged( 172 void WakeOnWifiManager::OnPreferenceChanged(
165 WakeOnWifiManager::WakeOnWifiFeature feature) { 173 WakeOnWifiManager::WakeOnWifiFeature feature) {
166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
175 if (feature == current_feature_)
176 return;
177
178 current_feature_ = feature;
179
167 const DeviceState* device = 180 const DeviceState* device =
168 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( 181 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
169 NetworkTypePattern::WiFi()); 182 NetworkTypePattern::WiFi());
170 if (!device) 183 if (!device)
171 return; 184 return;
172 185
173 std::string feature_string(WakeOnWifiFeatureToString(feature)); 186 std::string feature_string(WakeOnWifiFeatureToString(feature));
174 DCHECK(!feature_string.empty()); 187 DCHECK(!feature_string.empty());
175 188
176 NetworkHandler::Get()->network_device_handler()->SetDeviceProperty( 189 NetworkHandler::Get()->network_device_handler()->SetDeviceProperty(
177 device->path(), 190 device->path(),
178 shill::kWakeOnWiFiFeaturesEnabledProperty, 191 shill::kWakeOnWiFiFeaturesEnabledProperty,
179 base::StringValue(feature_string), 192 base::StringValue(feature_string),
180 base::Bind(&base::DoNothing), 193 base::Bind(&base::DoNothing),
181 network_handler::ErrorCallback()); 194 network_handler::ErrorCallback());
195
196 bool wake_from_suspend = IsWakeOnPacketEnabled(current_feature_);
197 for (const auto& kv_pair : connection_observers_) {
198 Profile* profile = kv_pair.first;
199 gcm::GCMProfileServiceFactory::GetForProfile(profile)
200 ->driver()
201 ->WakeFromSuspendForHeartbeat(wake_from_suspend);
202 }
182 } 203 }
183 204
184 void WakeOnWifiManager::Observe(int type, 205 void WakeOnWifiManager::Observe(int type,
185 const content::NotificationSource& source, 206 const content::NotificationSource& source,
186 const content::NotificationDetails& details) { 207 const content::NotificationDetails& details) {
187 switch (type) { 208 switch (type) {
188 case chrome::NOTIFICATION_PROFILE_ADDED: { 209 case chrome::NOTIFICATION_PROFILE_ADDED: {
189 OnProfileAdded(content::Source<Profile>(source).ptr()); 210 OnProfileAdded(content::Source<Profile>(source).ptr());
190 break; 211 break;
191 } 212 }
192 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 213 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
193 OnProfileDestroyed(content::Source<Profile>(source).ptr()); 214 OnProfileDestroyed(content::Source<Profile>(source).ptr());
194 break; 215 break;
195 } 216 }
196 default: 217 default:
197 NOTREACHED(); 218 NOTREACHED();
198 } 219 }
199 } 220 }
200 221
201 void WakeOnWifiManager::OnProfileAdded(Profile* profile) { 222 void WakeOnWifiManager::OnProfileAdded(Profile* profile) {
202 // add will do nothing if |profile| already exists in |connection_observers_|. 223 // add will do nothing if |profile| already exists in |connection_observers_|.
203 connection_observers_.add( 224 auto result = connection_observers_.add(
204 profile, 225 profile,
205 make_scoped_ptr( 226 make_scoped_ptr(
206 new WakeOnWifiManager::WakeOnPacketConnectionObserver(profile))); 227 new WakeOnWifiManager::WakeOnPacketConnectionObserver(profile)));
228
229 if (result.second) {
230 // This is a profile we haven't seen before.
231 gcm::GCMProfileServiceFactory::GetForProfile(profile)
232 ->driver()
233 ->WakeFromSuspendForHeartbeat(
234 IsWakeOnPacketEnabled(current_feature_));
235 }
207 } 236 }
208 237
209 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) { 238 void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) {
210 connection_observers_.erase(profile); 239 connection_observers_.erase(profile);
211 } 240 }
212 241
213 } // namespace chromeos 242 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/wake_on_wifi_manager.h ('k') | components/gcm_driver/fake_gcm_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698