OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/policy/heartbeat_scheduler.h" | 5 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 240 |
241 bool enabled; | 241 bool enabled; |
242 if (settings->GetBoolean(chromeos::kHeartbeatEnabled, &enabled)) | 242 if (settings->GetBoolean(chromeos::kHeartbeatEnabled, &enabled)) |
243 heartbeat_enabled_ = enabled; | 243 heartbeat_enabled_ = enabled; |
244 | 244 |
245 if (!heartbeat_enabled_) { | 245 if (!heartbeat_enabled_) { |
246 // Heartbeats are no longer enabled - cancel our callback and any | 246 // Heartbeats are no longer enabled - cancel our callback and any |
247 // outstanding registration attempts and disconnect from GCM so the | 247 // outstanding registration attempts and disconnect from GCM so the |
248 // connection can be shut down. If heartbeats are re-enabled later, we | 248 // connection can be shut down. If heartbeats are re-enabled later, we |
249 // will re-register with GCM. | 249 // will re-register with GCM. |
250 heartbeat_callback_.Cancel(); | |
251 ShutdownGCM(); | 250 ShutdownGCM(); |
252 } else { | 251 } else { |
253 // Schedule a new upload with the new frequency. | 252 // Schedule a new upload with the new frequency. |
254 ScheduleNextHeartbeat(); | 253 ScheduleNextHeartbeat(); |
255 } | 254 } |
256 | 255 |
257 DVLOG(1) << "heartbeat enabled: " << heartbeat_enabled_; | 256 DVLOG(1) << "heartbeat enabled: " << heartbeat_enabled_; |
258 DVLOG(1) << "heartbeat frequency: " << heartbeat_interval_; | 257 DVLOG(1) << "heartbeat frequency: " << heartbeat_interval_; |
259 } | 258 } |
260 | 259 |
261 void HeartbeatScheduler::ShutdownGCM() { | 260 void HeartbeatScheduler::ShutdownGCM() { |
261 heartbeat_callback_.Cancel(); | |
262 registration_helper_.reset(); | 262 registration_helper_.reset(); |
263 registration_id_.clear(); | 263 registration_id_.clear(); |
264 if (registered_app_handler_) { | 264 if (registered_app_handler_) { |
265 registered_app_handler_ = false; | 265 registered_app_handler_ = false; |
266 gcm_driver_->RemoveHeartbeatInterval(kHeartbeatSchedulerScope); | 266 gcm_driver_->RemoveHeartbeatInterval(kHeartbeatSchedulerScope); |
267 gcm_driver_->RemoveAppHandler(kHeartbeatGCMAppID); | 267 gcm_driver_->RemoveAppHandler(kHeartbeatGCMAppID); |
268 gcm_driver_->RemoveConnectionObserver(this); | 268 gcm_driver_->RemoveConnectionObserver(this); |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 417 |
418 void HeartbeatScheduler::ShutdownHandler() { | 418 void HeartbeatScheduler::ShutdownHandler() { |
419 // This should never be called, because BrowserProcessImpl::StartTearDown() | 419 // This should never be called, because BrowserProcessImpl::StartTearDown() |
420 // should shutdown the BrowserPolicyConnector (which destroys this object) | 420 // should shutdown the BrowserPolicyConnector (which destroys this object) |
421 // before the GCMDriver. Our goal is to make sure that this object is always | 421 // before the GCMDriver. Our goal is to make sure that this object is always |
422 // shutdown before GCMDriver is shut down, rather than trying to handle the | 422 // shutdown before GCMDriver is shut down, rather than trying to handle the |
423 // case when GCMDriver goes away. | 423 // case when GCMDriver goes away. |
424 NOTREACHED() << "HeartbeatScheduler should be destroyed before GCMDriver"; | 424 NOTREACHED() << "HeartbeatScheduler should be destroyed before GCMDriver"; |
425 } | 425 } |
426 | 426 |
427 void HeartbeatScheduler::OnStoreReset() { | |
428 // TODO(crbug.com/661660): Tell server that |registration_id_| is no longer | |
429 // valid. See also crbug.com/516375. | |
430 ShutdownGCM(); | |
Andrew T Wilson (Slow)
2016/11/09 08:19:39
Problem is that this will shutdown our GCM connect
johnme
2016/11/09 19:33:48
Makes sense.
| |
431 } | |
432 | |
427 void HeartbeatScheduler::OnMessage(const std::string& app_id, | 433 void HeartbeatScheduler::OnMessage(const std::string& app_id, |
428 const gcm::IncomingMessage& message) { | 434 const gcm::IncomingMessage& message) { |
429 // Should never be called because we don't get any incoming messages | 435 // Should never be called because we don't get any incoming messages |
430 // for our app ID. | 436 // for our app ID. |
431 NOTREACHED() << "Received incoming message for " << app_id; | 437 NOTREACHED() << "Received incoming message for " << app_id; |
432 } | 438 } |
433 | 439 |
434 void HeartbeatScheduler::OnMessagesDeleted(const std::string& app_id) { | 440 void HeartbeatScheduler::OnMessagesDeleted(const std::string& app_id) { |
435 } | 441 } |
436 | 442 |
(...skipping 11 matching lines...) Expand all Loading... | |
448 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) { | 454 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) { |
449 SignUpUpstreamNotification(); | 455 SignUpUpstreamNotification(); |
450 } | 456 } |
451 | 457 |
452 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) { | 458 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) { |
453 // TODO(binjin): Handle the failure, probably by exponential backoff. | 459 // TODO(binjin): Handle the failure, probably by exponential backoff. |
454 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server"; | 460 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server"; |
455 } | 461 } |
456 | 462 |
457 } // namespace policy | 463 } // namespace policy |
OLD | NEW |