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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; | 341 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; |
342 // A case where there were previously no accounts reported with checkin is | 342 // A case where there were previously no accounts reported with checkin is |
343 // considered to be the same as when the list of accounts is empty. It enables | 343 // considered to be the same as when the list of accounts is empty. It enables |
344 // scheduling a periodic checkin for devices with no signed in users | 344 // scheduling a periodic checkin for devices with no signed in users |
345 // immediately after restart, while keeping |accounts_set == false| delays the | 345 // immediately after restart, while keeping |accounts_set == false| delays the |
346 // checkin until the list of accounts is set explicitly. | 346 // checkin until the list of accounts is set explicitly. |
347 if (result->last_checkin_accounts.size() == 0) | 347 if (result->last_checkin_accounts.size() == 0) |
348 device_checkin_info_.accounts_set = true; | 348 device_checkin_info_.accounts_set = true; |
349 last_checkin_time_ = result->last_checkin_time; | 349 last_checkin_time_ = result->last_checkin_time; |
350 gservices_settings_.UpdateFromLoadResult(*result); | 350 gservices_settings_.UpdateFromLoadResult(*result); |
| 351 instance_id_data_ = result->instance_id_data; |
351 load_result_ = result.Pass(); | 352 load_result_ = result.Pass(); |
352 state_ = LOADED; | 353 state_ = LOADED; |
353 | 354 |
354 // Don't initiate the GCM connection when GCM is in delayed start mode and | 355 // Don't initiate the GCM connection when GCM is in delayed start mode and |
355 // not any standalone app has registered GCM yet. | 356 // not any standalone app has registered GCM yet. |
356 if (start_mode_ == DELAYED_START && !HasStandaloneRegisteredApp()) | 357 if (start_mode_ == DELAYED_START && !HasStandaloneRegisteredApp()) |
357 return; | 358 return; |
358 | 359 |
359 StartGCM(); | 360 StartGCM(); |
360 } | 361 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 time, | 524 time, |
524 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, | 525 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, |
525 weak_ptr_factory_.GetWeakPtr())); | 526 weak_ptr_factory_.GetWeakPtr())); |
526 } | 527 } |
527 | 528 |
528 void GCMClientImpl::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { | 529 void GCMClientImpl::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { |
529 DCHECK(mcs_client_); | 530 DCHECK(mcs_client_); |
530 mcs_client_->UpdateHeartbeatTimer(timer.Pass()); | 531 mcs_client_->UpdateHeartbeatTimer(timer.Pass()); |
531 } | 532 } |
532 | 533 |
| 534 void GCMClientImpl::AddInstanceIDData(const std::string& app_id, |
| 535 const std::string& instance_id_data) { |
| 536 instance_id_data_[app_id] = instance_id_data; |
| 537 gcm_store_->AddInstanceIDData( |
| 538 app_id, |
| 539 instance_id_data, |
| 540 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, |
| 541 weak_ptr_factory_.GetWeakPtr())); |
| 542 } |
| 543 |
| 544 void GCMClientImpl::RemoveInstanceIDData(const std::string& app_id) { |
| 545 instance_id_data_.erase(app_id); |
| 546 gcm_store_->RemoveInstanceIDData( |
| 547 app_id, |
| 548 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, |
| 549 weak_ptr_factory_.GetWeakPtr())); |
| 550 } |
| 551 |
| 552 std::string GCMClientImpl::GetInstanceIDData(const std::string& app_id) { |
| 553 auto iter = instance_id_data_.find(app_id); |
| 554 if (iter == instance_id_data_.end()) |
| 555 return std::string(); |
| 556 return iter->second; |
| 557 } |
| 558 |
533 void GCMClientImpl::StartCheckin() { | 559 void GCMClientImpl::StartCheckin() { |
534 // Make sure no checkin is in progress. | 560 // Make sure no checkin is in progress. |
535 if (checkin_request_.get()) | 561 if (checkin_request_.get()) |
536 return; | 562 return; |
537 | 563 |
538 checkin_proto::ChromeBuildProto chrome_build_proto; | 564 checkin_proto::ChromeBuildProto chrome_build_proto; |
539 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); | 565 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); |
540 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, | 566 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, |
541 device_checkin_info_.secret, | 567 device_checkin_info_.secret, |
542 device_checkin_info_.account_tokens, | 568 device_checkin_info_.account_tokens, |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1085 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
1060 if (registrations_.empty()) | 1086 if (registrations_.empty()) |
1061 return false; | 1087 return false; |
1062 // Note that account mapper is not counted as a standalone app since it is | 1088 // Note that account mapper is not counted as a standalone app since it is |
1063 // automatically started when other app uses GCM. | 1089 // automatically started when other app uses GCM. |
1064 return registrations_.size() > 1 || | 1090 return registrations_.size() > 1 || |
1065 !registrations_.count(kGCMAccountMapperAppId); | 1091 !registrations_.count(kGCMAccountMapperAppId); |
1066 } | 1092 } |
1067 | 1093 |
1068 } // namespace gcm | 1094 } // namespace gcm |
OLD | NEW |