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

Side by Side Diff: components/gcm_driver/gcm_client_impl.cc

Issue 2450383003: [GCM] Reset store on checkin rejection and add checkin state to internals (Closed)
Patch Set: Fix mcs probe 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 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 "components/gcm_driver/gcm_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 537
538 void GCMClientImpl::DestroyStoreWhenNotNeeded() { 538 void GCMClientImpl::DestroyStoreWhenNotNeeded() {
539 if (state_ != LOADED || start_mode_ != DELAYED_START) 539 if (state_ != LOADED || start_mode_ != DELAYED_START)
540 return; 540 return;
541 541
542 gcm_store_->Destroy(base::Bind(&GCMClientImpl::DestroyStoreCallback, 542 gcm_store_->Destroy(base::Bind(&GCMClientImpl::DestroyStoreCallback,
543 weak_ptr_factory_.GetWeakPtr())); 543 weak_ptr_factory_.GetWeakPtr()));
544 } 544 }
545 545
546 void GCMClientImpl::ResetStore() { 546 void GCMClientImpl::ResetStore() {
547 DCHECK_EQ(LOADING, state_);
548
549 // If already being reset, don't do it again. We want to prevent from 547 // If already being reset, don't do it again. We want to prevent from
550 // resetting and loading from the store again and again. 548 // resetting and loading from the store again and again.
551 if (gcm_store_reset_) { 549 if (gcm_store_reset_) {
552 RecordResetStoreErrorToUMA(INFINITE_STORE_RESET); 550 RecordResetStoreErrorToUMA(INFINITE_STORE_RESET);
553 state_ = UNINITIALIZED; 551 state_ = UNINITIALIZED;
554 return; 552 return;
555 } 553 }
556 gcm_store_reset_ = true; 554 gcm_store_reset_ = true;
557 555
558 // Destroy the GCM store to start over. 556 // Destroy the GCM store to start over.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 weak_ptr_factory_.GetWeakPtr()), 692 weak_ptr_factory_.GetWeakPtr()),
695 url_request_context_getter_.get(), 693 url_request_context_getter_.get(),
696 &recorder_)); 694 &recorder_));
697 // Taking a snapshot of the accounts count here, as there might be an asynch 695 // Taking a snapshot of the accounts count here, as there might be an asynch
698 // update of the account tokens while checkin is in progress. 696 // update of the account tokens while checkin is in progress.
699 device_checkin_info_.SnapshotCheckinAccounts(); 697 device_checkin_info_.SnapshotCheckinAccounts();
700 checkin_request_->Start(); 698 checkin_request_->Start();
701 } 699 }
702 700
703 void GCMClientImpl::OnCheckinCompleted( 701 void GCMClientImpl::OnCheckinCompleted(
702 net::HttpStatusCode response_code,
704 const checkin_proto::AndroidCheckinResponse& checkin_response) { 703 const checkin_proto::AndroidCheckinResponse& checkin_response) {
705 checkin_request_.reset(); 704 checkin_request_.reset();
706 705
707 if (!checkin_response.has_android_id() || 706 if (response_code == net::HTTP_UNAUTHORIZED ||
708 !checkin_response.has_security_token()) { 707 response_code == net::HTTP_BAD_REQUEST) {
709 // TODO(fgorski): I don't think a retry here will help, we should probably 708 LOG(ERROR) << "Checkin rejected. Resetting GCM Store.";
710 // start over. By checking in with (0, 0). 709 ResetStore();
711 return; 710 return;
712 } 711 }
713 712
713 DCHECK(checkin_response.has_android_id());
714 DCHECK(checkin_response.has_security_token());
714 CheckinInfo checkin_info; 715 CheckinInfo checkin_info;
715 checkin_info.android_id = checkin_response.android_id(); 716 checkin_info.android_id = checkin_response.android_id();
716 checkin_info.secret = checkin_response.security_token(); 717 checkin_info.secret = checkin_response.security_token();
717 718
718 if (state_ == INITIAL_DEVICE_CHECKIN) { 719 if (state_ == INITIAL_DEVICE_CHECKIN) {
719 OnFirstTimeDeviceCheckinCompleted(checkin_info); 720 OnFirstTimeDeviceCheckinCompleted(checkin_info);
720 } else { 721 } else {
721 // checkin_info is not expected to change after a periodic checkin as it 722 // checkin_info is not expected to change after a periodic checkin as it
722 // would invalidate the registratoin IDs. 723 // would invalidate the registration IDs.
723 DCHECK_EQ(READY, state_); 724 DCHECK_EQ(READY, state_);
724 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); 725 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id);
725 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); 726 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret);
726 } 727 }
727 728
728 if (device_checkin_info_.IsValid()) { 729 if (device_checkin_info_.IsValid()) {
729 // First update G-services settings, as something might have changed. 730 // First update G-services settings, as something might have changed.
730 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) { 731 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) {
731 gcm_store_->SetGServicesSettings( 732 gcm_store_->SetGServicesSettings(
732 gservices_settings_.settings_map(), 733 gservices_settings_.settings_map(),
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 void GCMClientImpl::ClearActivityLogs() { 1181 void GCMClientImpl::ClearActivityLogs() {
1181 recorder_.Clear(); 1182 recorder_.Clear();
1182 } 1183 }
1183 1184
1184 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { 1185 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const {
1185 GCMClient::GCMStatistics stats; 1186 GCMClient::GCMStatistics stats;
1186 stats.gcm_client_created = true; 1187 stats.gcm_client_created = true;
1187 stats.is_recording = recorder_.is_recording(); 1188 stats.is_recording = recorder_.is_recording();
1188 stats.gcm_client_state = GetStateString(); 1189 stats.gcm_client_state = GetStateString();
1189 stats.connection_client_created = mcs_client_.get() != NULL; 1190 stats.connection_client_created = mcs_client_.get() != NULL;
1191 stats.last_checkin = last_checkin_time_;
1192 stats.next_checkin =
1193 last_checkin_time_ + gservices_settings_.GetCheckinInterval();
1190 if (connection_factory_.get()) 1194 if (connection_factory_.get())
1191 stats.connection_state = connection_factory_->GetConnectionStateString(); 1195 stats.connection_state = connection_factory_->GetConnectionStateString();
1192 if (mcs_client_.get()) { 1196 if (mcs_client_.get()) {
1193 stats.send_queue_size = mcs_client_->GetSendQueueSize(); 1197 stats.send_queue_size = mcs_client_->GetSendQueueSize();
1194 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); 1198 stats.resend_queue_size = mcs_client_->GetResendQueueSize();
1195 } 1199 }
1196 if (device_checkin_info_.android_id > 0) 1200 if (device_checkin_info_.android_id > 0)
1197 stats.android_id = device_checkin_info_.android_id; 1201 stats.android_id = device_checkin_info_.android_id;
1198 recorder_.CollectActivities(&stats.recorded_activities); 1202 recorder_.CollectActivities(&stats.recorded_activities);
1199 1203
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 bool GCMClientImpl::HasStandaloneRegisteredApp() const { 1433 bool GCMClientImpl::HasStandaloneRegisteredApp() const {
1430 if (registrations_.empty()) 1434 if (registrations_.empty())
1431 return false; 1435 return false;
1432 // Note that account mapper is not counted as a standalone app since it is 1436 // Note that account mapper is not counted as a standalone app since it is
1433 // automatically started when other app uses GCM. 1437 // automatically started when other app uses GCM.
1434 return registrations_.size() > 1 || 1438 return registrations_.size() > 1 ||
1435 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); 1439 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId);
1436 } 1440 }
1437 1441
1438 } // namespace gcm 1442 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_client_impl.h ('k') | components/gcm_driver/gcm_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698