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

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

Issue 681453004: [GCM] Adding last token fetching time handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 "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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // immediately after restart, while keeping |accounts_set == false| delays the 321 // immediately after restart, while keeping |accounts_set == false| delays the
322 // checkin until the list of accounts is set explicitly. 322 // checkin until the list of accounts is set explicitly.
323 if (result->last_checkin_accounts.size() == 0) 323 if (result->last_checkin_accounts.size() == 0)
324 device_checkin_info_.accounts_set = true; 324 device_checkin_info_.accounts_set = true;
325 last_checkin_time_ = result->last_checkin_time; 325 last_checkin_time_ = result->last_checkin_time;
326 gservices_settings_.UpdateFromLoadResult(*result); 326 gservices_settings_.UpdateFromLoadResult(*result);
327 // Taking over the value of account_mappings before passing the ownership of 327 // Taking over the value of account_mappings before passing the ownership of
328 // load result to InitializeMCSClient. 328 // load result to InitializeMCSClient.
329 std::vector<AccountMapping> account_mappings; 329 std::vector<AccountMapping> account_mappings;
330 account_mappings.swap(result->account_mappings); 330 account_mappings.swap(result->account_mappings);
331 base::Time last_token_fetching_time = result->last_token_fetching_time;
331 332
332 InitializeMCSClient(result.Pass()); 333 InitializeMCSClient(result.Pass());
333 334
334 if (device_checkin_info_.IsValid()) { 335 if (device_checkin_info_.IsValid()) {
335 SchedulePeriodicCheckin(); 336 SchedulePeriodicCheckin();
336 OnReady(account_mappings); 337 OnReady(account_mappings, last_token_fetching_time);
337 return; 338 return;
338 } 339 }
339 340
340 state_ = INITIAL_DEVICE_CHECKIN; 341 state_ = INITIAL_DEVICE_CHECKIN;
341 device_checkin_info_.Reset(); 342 device_checkin_info_.Reset();
342 StartCheckin(); 343 StartCheckin();
343 } 344 }
344 345
345 void GCMClientImpl::InitializeMCSClient( 346 void GCMClientImpl::InitializeMCSClient(
346 scoped_ptr<GCMStore::LoadResult> result) { 347 scoped_ptr<GCMStore::LoadResult> result) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 device_checkin_info_.android_id = checkin_info.android_id; 381 device_checkin_info_.android_id = checkin_info.android_id;
381 device_checkin_info_.secret = checkin_info.secret; 382 device_checkin_info_.secret = checkin_info.secret;
382 // If accounts were not set by now, we can consider them set (to empty list) 383 // If accounts were not set by now, we can consider them set (to empty list)
383 // to make sure periodic checkins get scheduled after initial checkin. 384 // to make sure periodic checkins get scheduled after initial checkin.
384 device_checkin_info_.accounts_set = true; 385 device_checkin_info_.accounts_set = true;
385 gcm_store_->SetDeviceCredentials( 386 gcm_store_->SetDeviceCredentials(
386 checkin_info.android_id, checkin_info.secret, 387 checkin_info.android_id, checkin_info.secret,
387 base::Bind(&GCMClientImpl::SetDeviceCredentialsCallback, 388 base::Bind(&GCMClientImpl::SetDeviceCredentialsCallback,
388 weak_ptr_factory_.GetWeakPtr())); 389 weak_ptr_factory_.GetWeakPtr()));
389 390
390 OnReady(std::vector<AccountMapping>()); 391 OnReady(std::vector<AccountMapping>(), base::Time());
391 } 392 }
392 393
393 void GCMClientImpl::OnReady( 394 void GCMClientImpl::OnReady(
394 const std::vector<AccountMapping>& account_mappings) { 395 const std::vector<AccountMapping>& account_mappings,
396 const base::Time& last_token_fetching_time) {
395 state_ = READY; 397 state_ = READY;
396 StartMCSLogin(); 398 StartMCSLogin();
397 399
398 delegate_->OnGCMReady(account_mappings); 400 delegate_->OnGCMReady(account_mappings, last_token_fetching_time);
399 } 401 }
400 402
401 void GCMClientImpl::StartMCSLogin() { 403 void GCMClientImpl::StartMCSLogin() {
402 DCHECK_EQ(READY, state_); 404 DCHECK_EQ(READY, state_);
403 DCHECK(device_checkin_info_.IsValid()); 405 DCHECK(device_checkin_info_.IsValid());
404 mcs_client_->Login(device_checkin_info_.android_id, 406 mcs_client_->Login(device_checkin_info_.android_id,
405 device_checkin_info_.secret); 407 device_checkin_info_.secret);
406 } 408 }
407 409
408 void GCMClientImpl::ResetState() { 410 void GCMClientImpl::ResetState() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 weak_ptr_factory_.GetWeakPtr())); 465 weak_ptr_factory_.GetWeakPtr()));
464 } 466 }
465 467
466 void GCMClientImpl::RemoveAccountMapping(const std::string& account_id) { 468 void GCMClientImpl::RemoveAccountMapping(const std::string& account_id) {
467 gcm_store_->RemoveAccountMapping( 469 gcm_store_->RemoveAccountMapping(
468 account_id, 470 account_id,
469 base::Bind(&GCMClientImpl::DefaultStoreCallback, 471 base::Bind(&GCMClientImpl::DefaultStoreCallback,
470 weak_ptr_factory_.GetWeakPtr())); 472 weak_ptr_factory_.GetWeakPtr()));
471 } 473 }
472 474
475 void GCMClientImpl::SetLastTokenFetchingTime(const base::Time& time) {
476 gcm_store_->SetLastTokenFetchingTime(
477 time,
478 base::Bind(&GCMClientImpl::DefaultStoreCallback,
479 weak_ptr_factory_.GetWeakPtr()));
480 }
481
473 void GCMClientImpl::StartCheckin() { 482 void GCMClientImpl::StartCheckin() {
474 // Make sure no checkin is in progress. 483 // Make sure no checkin is in progress.
475 if (checkin_request_.get()) 484 if (checkin_request_.get())
476 return; 485 return;
477 486
478 checkin_proto::ChromeBuildProto chrome_build_proto; 487 checkin_proto::ChromeBuildProto chrome_build_proto;
479 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); 488 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto);
480 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, 489 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id,
481 device_checkin_info_.secret, 490 device_checkin_info_.secret,
482 device_checkin_info_.account_tokens, 491 device_checkin_info_.account_tokens,
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 985
977 recorder_.RecordIncomingSendError( 986 recorder_.RecordIncomingSendError(
978 data_message_stanza.category(), 987 data_message_stanza.category(),
979 data_message_stanza.to(), 988 data_message_stanza.to(),
980 data_message_stanza.id()); 989 data_message_stanza.id());
981 delegate_->OnMessageSendError(data_message_stanza.category(), 990 delegate_->OnMessageSendError(data_message_stanza.category(),
982 send_error_details); 991 send_error_details);
983 } 992 }
984 993
985 } // namespace gcm 994 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698