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

Side by Side Diff: chrome/browser/chromeos/policy/heartbeat_scheduler.cc

Issue 2473813002: Notify GCMAppHandlers when the store is reset, so they clear cached IDs (Closed)
Patch Set: Update Cryptauth comment Created 4 years, 1 month 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 (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
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
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 if (!registration_helper_) {
431 ShutdownGCM();
432 RefreshHeartbeatSettings();
433 } // Otherwise let the pending registration complete normally.
434 }
435
427 void HeartbeatScheduler::OnMessage(const std::string& app_id, 436 void HeartbeatScheduler::OnMessage(const std::string& app_id,
428 const gcm::IncomingMessage& message) { 437 const gcm::IncomingMessage& message) {
429 // Should never be called because we don't get any incoming messages 438 // Should never be called because we don't get any incoming messages
430 // for our app ID. 439 // for our app ID.
431 NOTREACHED() << "Received incoming message for " << app_id; 440 NOTREACHED() << "Received incoming message for " << app_id;
432 } 441 }
433 442
434 void HeartbeatScheduler::OnMessagesDeleted(const std::string& app_id) { 443 void HeartbeatScheduler::OnMessagesDeleted(const std::string& app_id) {
435 } 444 }
436 445
(...skipping 11 matching lines...) Expand all
448 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) { 457 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) {
449 SignUpUpstreamNotification(); 458 SignUpUpstreamNotification();
450 } 459 }
451 460
452 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) { 461 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) {
453 // TODO(binjin): Handle the failure, probably by exponential backoff. 462 // TODO(binjin): Handle the failure, probably by exponential backoff.
454 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server"; 463 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server";
455 } 464 }
456 465
457 } // namespace policy 466 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/heartbeat_scheduler.h ('k') | chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698