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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/net/wake_on_wifi_manager.cc
diff --git a/chrome/browser/chromeos/net/wake_on_wifi_manager.cc b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
index d163378aee122cb6ae06ed0dbc691713dbaddac3..6233784a9e3d945c232a270325f87cee62430773 100644
--- a/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
+++ b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
@@ -51,12 +51,19 @@ std::string WakeOnWifiFeatureToString(
return kWakeOnSsid;
case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID:
return kWakeOnPacketAndSsid;
+ case WakeOnWifiManager::INVALID:
+ return std::string();
}
NOTREACHED() << "Unknown wake on wifi feature: " << feature;
return std::string();
}
+bool IsWakeOnPacketEnabled(WakeOnWifiManager::WakeOnWifiFeature feature) {
+ return feature == WakeOnWifiManager::WAKE_ON_PACKET ||
+ feature == WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID;
+}
+
// Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos.
WakeOnWifiManager* g_wake_on_wifi_manager = NULL;
@@ -129,7 +136,8 @@ WakeOnWifiManager* WakeOnWifiManager::Get() {
return g_wake_on_wifi_manager;
}
-WakeOnWifiManager::WakeOnWifiManager() {
+WakeOnWifiManager::WakeOnWifiManager()
+ : current_feature_(WakeOnWifiManager::INVALID) {
// This class must be constructed before any users are logged in, i.e., before
// any profiles are created or added to the ProfileManager. Additionally,
// IsUserLoggedIn always returns true when we are not running on a Chrome OS
@@ -164,6 +172,11 @@ WakeOnWifiManager::~WakeOnWifiManager() {
void WakeOnWifiManager::OnPreferenceChanged(
WakeOnWifiManager::WakeOnWifiFeature feature) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (feature == current_feature_)
+ return;
+
+ current_feature_ = feature;
+
const DeviceState* device =
NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
NetworkTypePattern::WiFi());
@@ -179,6 +192,14 @@ void WakeOnWifiManager::OnPreferenceChanged(
base::StringValue(feature_string),
base::Bind(&base::DoNothing),
network_handler::ErrorCallback());
+
+ bool wake_from_suspend = IsWakeOnPacketEnabled(current_feature_);
+ for (const auto& kv_pair : connection_observers_) {
+ Profile* profile = kv_pair.first;
+ gcm::GCMProfileServiceFactory::GetForProfile(profile)
+ ->driver()
+ ->WakeFromSuspendForHeartbeat(wake_from_suspend);
+ }
}
void WakeOnWifiManager::Observe(int type,
@@ -200,10 +221,18 @@ void WakeOnWifiManager::Observe(int type,
void WakeOnWifiManager::OnProfileAdded(Profile* profile) {
// add will do nothing if |profile| already exists in |connection_observers_|.
- connection_observers_.add(
+ auto result = connection_observers_.add(
profile,
make_scoped_ptr(
new WakeOnWifiManager::WakeOnPacketConnectionObserver(profile)));
+
+ if (result.second) {
+ // This is a profile we haven't seen before.
+ gcm::GCMProfileServiceFactory::GetForProfile(profile)
+ ->driver()
+ ->WakeFromSuspendForHeartbeat(
+ IsWakeOnPacketEnabled(current_feature_));
+ }
}
void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) {
« 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