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 "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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; | 314 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; |
| 315 // A case where there were previously no accounts reported with checkin is | 315 // A case where there were previously no accounts reported with checkin is |
| 316 // considered to be the same as when the list of accounts is empty. It enables | 316 // considered to be the same as when the list of accounts is empty. It enables |
| 317 // scheduling a periodic checkin for devices with no signed in users | 317 // scheduling a periodic checkin for devices with no signed in users |
| 318 // immediately after restart, while keeping |accounts_set == false| delays the | 318 // immediately after restart, while keeping |accounts_set == false| delays the |
| 319 // checkin until the list of accounts is set explicitly. | 319 // checkin until the list of accounts is set explicitly. |
| 320 if (result->last_checkin_accounts.size() == 0) | 320 if (result->last_checkin_accounts.size() == 0) |
| 321 device_checkin_info_.accounts_set = true; | 321 device_checkin_info_.accounts_set = true; |
| 322 last_checkin_time_ = result->last_checkin_time; | 322 last_checkin_time_ = result->last_checkin_time; |
| 323 gservices_settings_.UpdateFromLoadResult(*result); | 323 gservices_settings_.UpdateFromLoadResult(*result); |
| 324 std::vector<AccountMapping> account_mappings; | |
| 325 account_mappings.swap(result->account_mappings); | |
|
jianli
2014/09/24 21:21:31
Why can't we pass result->account_mappings to OnRe
fgorski
2014/09/24 22:25:40
Added comment as discussed.
| |
| 324 InitializeMCSClient(result.Pass()); | 326 InitializeMCSClient(result.Pass()); |
| 325 | 327 |
| 326 if (device_checkin_info_.IsValid()) { | 328 if (device_checkin_info_.IsValid()) { |
| 327 SchedulePeriodicCheckin(); | 329 SchedulePeriodicCheckin(); |
| 328 OnReady(); | 330 OnReady(account_mappings); |
| 329 return; | 331 return; |
| 330 } | 332 } |
| 331 | 333 |
| 332 state_ = INITIAL_DEVICE_CHECKIN; | 334 state_ = INITIAL_DEVICE_CHECKIN; |
| 333 device_checkin_info_.Reset(); | 335 device_checkin_info_.Reset(); |
| 334 StartCheckin(); | 336 StartCheckin(); |
| 335 } | 337 } |
| 336 | 338 |
| 337 void GCMClientImpl::InitializeMCSClient( | 339 void GCMClientImpl::InitializeMCSClient( |
| 338 scoped_ptr<GCMStore::LoadResult> result) { | 340 scoped_ptr<GCMStore::LoadResult> result) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 device_checkin_info_.android_id = checkin_info.android_id; | 374 device_checkin_info_.android_id = checkin_info.android_id; |
| 373 device_checkin_info_.secret = checkin_info.secret; | 375 device_checkin_info_.secret = checkin_info.secret; |
| 374 // If accounts were not set by now, we can consider them set (to empty list) | 376 // If accounts were not set by now, we can consider them set (to empty list) |
| 375 // to make sure periodic checkins get scheduled after initial checkin. | 377 // to make sure periodic checkins get scheduled after initial checkin. |
| 376 device_checkin_info_.accounts_set = true; | 378 device_checkin_info_.accounts_set = true; |
| 377 gcm_store_->SetDeviceCredentials( | 379 gcm_store_->SetDeviceCredentials( |
| 378 checkin_info.android_id, checkin_info.secret, | 380 checkin_info.android_id, checkin_info.secret, |
| 379 base::Bind(&GCMClientImpl::SetDeviceCredentialsCallback, | 381 base::Bind(&GCMClientImpl::SetDeviceCredentialsCallback, |
| 380 weak_ptr_factory_.GetWeakPtr())); | 382 weak_ptr_factory_.GetWeakPtr())); |
| 381 | 383 |
| 382 OnReady(); | 384 OnReady(std::vector<AccountMapping>()); |
| 383 } | 385 } |
| 384 | 386 |
| 385 void GCMClientImpl::OnReady() { | 387 void GCMClientImpl::OnReady( |
| 388 const std::vector<AccountMapping>& account_mappings) { | |
| 386 state_ = READY; | 389 state_ = READY; |
| 387 StartMCSLogin(); | 390 StartMCSLogin(); |
| 388 | 391 |
| 389 delegate_->OnGCMReady(); | 392 delegate_->OnGCMReady(account_mappings); |
| 390 } | 393 } |
| 391 | 394 |
| 392 void GCMClientImpl::StartMCSLogin() { | 395 void GCMClientImpl::StartMCSLogin() { |
| 393 DCHECK_EQ(READY, state_); | 396 DCHECK_EQ(READY, state_); |
| 394 DCHECK(device_checkin_info_.IsValid()); | 397 DCHECK(device_checkin_info_.IsValid()); |
| 395 mcs_client_->Login(device_checkin_info_.android_id, | 398 mcs_client_->Login(device_checkin_info_.android_id, |
| 396 device_checkin_info_.secret); | 399 device_checkin_info_.secret); |
| 397 } | 400 } |
| 398 | 401 |
| 399 void GCMClientImpl::ResetState() { | 402 void GCMClientImpl::ResetState() { |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 | 956 |
| 954 recorder_.RecordIncomingSendError( | 957 recorder_.RecordIncomingSendError( |
| 955 data_message_stanza.category(), | 958 data_message_stanza.category(), |
| 956 data_message_stanza.to(), | 959 data_message_stanza.to(), |
| 957 data_message_stanza.id()); | 960 data_message_stanza.id()); |
| 958 delegate_->OnMessageSendError(data_message_stanza.category(), | 961 delegate_->OnMessageSendError(data_message_stanza.category(), |
| 959 send_error_details); | 962 send_error_details); |
| 960 } | 963 } |
| 961 | 964 |
| 962 } // namespace gcm | 965 } // namespace gcm |
| OLD | NEW |