Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( |
| 704 const checkin_proto::AndroidCheckinResponse& checkin_response) { | 702 const checkin_proto::AndroidCheckinResponse& checkin_response) { |
| 705 checkin_request_.reset(); | 703 checkin_request_.reset(); |
| 706 | 704 |
| 707 if (!checkin_response.has_android_id() || | 705 if (!checkin_response.has_android_id() || |
| 708 !checkin_response.has_security_token()) { | 706 !checkin_response.has_security_token()) { |
| 709 // TODO(fgorski): I don't think a retry here will help, we should probably | 707 LOG(ERROR) << "Checkin rejected. Resetting GCM Store."; |
| 710 // start over. By checking in with (0, 0). | 708 ResetStore(); |
|
Peter Beverloo
2016/10/28 15:52:30
I'm a bit concerned that this opens up a path for
Nicolas Zea
2016/11/01 00:18:16
Updated to only perform a reset for 400/401 respon
Peter Beverloo
2016/11/01 15:19:14
Chirp (go/finch-chirp) could help for automated wa
| |
| 711 return; | 709 return; |
| 712 } | 710 } |
| 713 | 711 |
| 714 CheckinInfo checkin_info; | 712 CheckinInfo checkin_info; |
| 715 checkin_info.android_id = checkin_response.android_id(); | 713 checkin_info.android_id = checkin_response.android_id(); |
| 716 checkin_info.secret = checkin_response.security_token(); | 714 checkin_info.secret = checkin_response.security_token(); |
| 717 | 715 |
| 718 if (state_ == INITIAL_DEVICE_CHECKIN) { | 716 if (state_ == INITIAL_DEVICE_CHECKIN) { |
| 719 OnFirstTimeDeviceCheckinCompleted(checkin_info); | 717 OnFirstTimeDeviceCheckinCompleted(checkin_info); |
| 720 } else { | 718 } else { |
| 721 // checkin_info is not expected to change after a periodic checkin as it | 719 // checkin_info is not expected to change after a periodic checkin as it |
| 722 // would invalidate the registratoin IDs. | 720 // would invalidate the registration IDs. |
| 723 DCHECK_EQ(READY, state_); | 721 DCHECK_EQ(READY, state_); |
| 724 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); | 722 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); |
| 725 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); | 723 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); |
| 726 } | 724 } |
| 727 | 725 |
| 728 if (device_checkin_info_.IsValid()) { | 726 if (device_checkin_info_.IsValid()) { |
| 729 // First update G-services settings, as something might have changed. | 727 // First update G-services settings, as something might have changed. |
| 730 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) { | 728 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) { |
| 731 gcm_store_->SetGServicesSettings( | 729 gcm_store_->SetGServicesSettings( |
| 732 gservices_settings_.settings_map(), | 730 gservices_settings_.settings_map(), |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 void GCMClientImpl::ClearActivityLogs() { | 1178 void GCMClientImpl::ClearActivityLogs() { |
| 1181 recorder_.Clear(); | 1179 recorder_.Clear(); |
| 1182 } | 1180 } |
| 1183 | 1181 |
| 1184 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { | 1182 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { |
| 1185 GCMClient::GCMStatistics stats; | 1183 GCMClient::GCMStatistics stats; |
| 1186 stats.gcm_client_created = true; | 1184 stats.gcm_client_created = true; |
| 1187 stats.is_recording = recorder_.is_recording(); | 1185 stats.is_recording = recorder_.is_recording(); |
| 1188 stats.gcm_client_state = GetStateString(); | 1186 stats.gcm_client_state = GetStateString(); |
| 1189 stats.connection_client_created = mcs_client_.get() != NULL; | 1187 stats.connection_client_created = mcs_client_.get() != NULL; |
| 1188 stats.last_checkin = last_checkin_time_; | |
| 1189 stats.next_checkin = | |
| 1190 last_checkin_time_ + gservices_settings_.GetCheckinInterval(); | |
| 1190 if (connection_factory_.get()) | 1191 if (connection_factory_.get()) |
| 1191 stats.connection_state = connection_factory_->GetConnectionStateString(); | 1192 stats.connection_state = connection_factory_->GetConnectionStateString(); |
| 1192 if (mcs_client_.get()) { | 1193 if (mcs_client_.get()) { |
| 1193 stats.send_queue_size = mcs_client_->GetSendQueueSize(); | 1194 stats.send_queue_size = mcs_client_->GetSendQueueSize(); |
| 1194 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); | 1195 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); |
| 1195 } | 1196 } |
| 1196 if (device_checkin_info_.android_id > 0) | 1197 if (device_checkin_info_.android_id > 0) |
| 1197 stats.android_id = device_checkin_info_.android_id; | 1198 stats.android_id = device_checkin_info_.android_id; |
| 1198 recorder_.CollectActivities(&stats.recorded_activities); | 1199 recorder_.CollectActivities(&stats.recorded_activities); |
| 1199 | 1200 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1430 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
| 1430 if (registrations_.empty()) | 1431 if (registrations_.empty()) |
| 1431 return false; | 1432 return false; |
| 1432 // Note that account mapper is not counted as a standalone app since it is | 1433 // Note that account mapper is not counted as a standalone app since it is |
| 1433 // automatically started when other app uses GCM. | 1434 // automatically started when other app uses GCM. |
| 1434 return registrations_.size() > 1 || | 1435 return registrations_.size() > 1 || |
| 1435 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1436 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
| 1436 } | 1437 } |
| 1437 | 1438 |
| 1438 } // namespace gcm | 1439 } // namespace gcm |
| OLD | NEW |