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

Side by Side 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: Make GCM wake from suspend aware 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 "google_apis/gcm/engine/heartbeat_manager.h" 5 #include "google_apis/gcm/engine/heartbeat_manager.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "google_apis/gcm/protocol/mcs.pb.h" 9 #include "google_apis/gcm/protocol/mcs.pb.h"
10 #include "net/base/network_change_notifier.h" 10 #include "net/base/network_change_notifier.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 server_interval_ms_ = config.interval_ms(); 73 server_interval_ms_ = config.interval_ms();
74 } 74 }
75 75
76 base::TimeTicks HeartbeatManager::GetNextHeartbeatTime() const { 76 base::TimeTicks HeartbeatManager::GetNextHeartbeatTime() const {
77 if (heartbeat_timer_->IsRunning()) 77 if (heartbeat_timer_->IsRunning())
78 return heartbeat_timer_->desired_run_time(); 78 return heartbeat_timer_->desired_run_time();
79 else 79 else
80 return base::TimeTicks(); 80 return base::TimeTicks();
81 } 81 }
82 82
83 void HeartbeatManager::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) {
84 bool was_running = heartbeat_timer_->IsRunning();
85
86 Stop();
Nicolas Zea 2014/12/05 00:53:05 I don't think you should be calling Stop() here. I
Chirantan Ekbote 2014/12/05 21:49:05 Done.
87 heartbeat_timer_ = timer.Pass();
88
89 if (was_running)
90 RestartTimer();
91 }
92
83 void HeartbeatManager::OnHeartbeatTriggered() { 93 void HeartbeatManager::OnHeartbeatTriggered() {
84 // Reset the weak pointers used for heartbeat checks. 94 // Reset the weak pointers used for heartbeat checks.
85 weak_ptr_factory_.InvalidateWeakPtrs(); 95 weak_ptr_factory_.InvalidateWeakPtrs();
86 96
87 if (waiting_for_ack_) { 97 if (waiting_for_ack_) {
88 LOG(WARNING) << "Lost connection to MCS, reconnecting."; 98 LOG(WARNING) << "Lost connection to MCS, reconnecting.";
89 Stop(); 99 Stop();
90 trigger_reconnect_callback_.Run(); 100 trigger_reconnect_callback_.Run();
91 return; 101 return;
92 } 102 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 163
154 // Otherwise check again later. 164 // Otherwise check again later.
155 base::MessageLoop::current()->PostDelayedTask( 165 base::MessageLoop::current()->PostDelayedTask(
156 FROM_HERE, 166 FROM_HERE,
157 base::Bind(&HeartbeatManager::CheckForMissedHeartbeat, 167 base::Bind(&HeartbeatManager::CheckForMissedHeartbeat,
158 weak_ptr_factory_.GetWeakPtr()), 168 weak_ptr_factory_.GetWeakPtr()),
159 base::TimeDelta::FromMilliseconds(kHeartbeatMissedCheckMs)); 169 base::TimeDelta::FromMilliseconds(kHeartbeatMissedCheckMs));
160 } 170 }
161 171
162 } // namespace gcm 172 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698