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

Unified Diff: google_apis/gcm/engine/heartbeat_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 | « google_apis/gcm/engine/heartbeat_manager.h ('k') | google_apis/gcm/engine/heartbeat_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/engine/heartbeat_manager.cc
diff --git a/google_apis/gcm/engine/heartbeat_manager.cc b/google_apis/gcm/engine/heartbeat_manager.cc
index b6b0e8892ebb91d357d54365054f6531a8086dfa..4467e0f4642953b9d229cb5400043b530c4b6901 100644
--- a/google_apis/gcm/engine/heartbeat_manager.cc
+++ b/google_apis/gcm/engine/heartbeat_manager.cc
@@ -4,7 +4,9 @@
#include "google_apis/gcm/engine/heartbeat_manager.h"
+#include "base/callback.h"
#include "base/metrics/histogram.h"
+#include "base/time/time.h"
#include "base/timer/timer.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/base/network_change_notifier.h"
@@ -24,11 +26,12 @@ const int64 kHeartbeatAckDefaultMs = 1000 * 60 * 1; // 1 minute.
const int kHeartbeatMissedCheckMs = 1000 * 60 * 5; // 5 minutes.
} // namespace
-HeartbeatManager::HeartbeatManager(scoped_ptr<base::Timer> heartbeat_timer)
+HeartbeatManager::HeartbeatManager()
: waiting_for_ack_(false),
heartbeat_interval_ms_(0),
server_interval_ms_(0),
- heartbeat_timer_(heartbeat_timer.Pass()),
+ heartbeat_timer_(new base::Timer(true /* retain_user_task */,
+ false /* is_repeating */)),
weak_ptr_factory_(this) {}
HeartbeatManager::~HeartbeatManager() {}
@@ -80,6 +83,19 @@ base::TimeTicks HeartbeatManager::GetNextHeartbeatTime() const {
return base::TimeTicks();
}
+void HeartbeatManager::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) {
+ bool was_running = heartbeat_timer_->IsRunning();
+ base::TimeDelta remaining_delay =
+ heartbeat_timer_->desired_run_time() - base::TimeTicks::Now();
+ base::Closure timer_task(heartbeat_timer_->user_task());
+
+ heartbeat_timer_->Stop();
+ heartbeat_timer_ = timer.Pass();
+
+ if (was_running)
+ heartbeat_timer_->Start(FROM_HERE, remaining_delay, timer_task);
+}
+
void HeartbeatManager::OnHeartbeatTriggered() {
// Reset the weak pointers used for heartbeat checks.
weak_ptr_factory_.InvalidateWeakPtrs();
« no previous file with comments | « google_apis/gcm/engine/heartbeat_manager.h ('k') | google_apis/gcm/engine/heartbeat_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698