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

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: Fixing Android build 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_fetch_time = result->last_token_fetch_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_fetch_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(const std::vector<AccountMapping>& account_mappings,
394 const std::vector<AccountMapping>& account_mappings) { 395 const base::Time& last_token_fetch_time) {
395 state_ = READY; 396 state_ = READY;
396 StartMCSLogin(); 397 StartMCSLogin();
397 398
398 delegate_->OnGCMReady(account_mappings); 399 delegate_->OnGCMReady(account_mappings, last_token_fetch_time);
399 } 400 }
400 401
401 void GCMClientImpl::StartMCSLogin() { 402 void GCMClientImpl::StartMCSLogin() {
402 DCHECK_EQ(READY, state_); 403 DCHECK_EQ(READY, state_);
403 DCHECK(device_checkin_info_.IsValid()); 404 DCHECK(device_checkin_info_.IsValid());
404 mcs_client_->Login(device_checkin_info_.android_id, 405 mcs_client_->Login(device_checkin_info_.android_id,
405 device_checkin_info_.secret); 406 device_checkin_info_.secret);
406 } 407 }
407 408
408 void GCMClientImpl::ResetState() { 409 void GCMClientImpl::ResetState() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 weak_ptr_factory_.GetWeakPtr())); 464 weak_ptr_factory_.GetWeakPtr()));
464 } 465 }
465 466
466 void GCMClientImpl::RemoveAccountMapping(const std::string& account_id) { 467 void GCMClientImpl::RemoveAccountMapping(const std::string& account_id) {
467 gcm_store_->RemoveAccountMapping( 468 gcm_store_->RemoveAccountMapping(
468 account_id, 469 account_id,
469 base::Bind(&GCMClientImpl::DefaultStoreCallback, 470 base::Bind(&GCMClientImpl::DefaultStoreCallback,
470 weak_ptr_factory_.GetWeakPtr())); 471 weak_ptr_factory_.GetWeakPtr()));
471 } 472 }
472 473
474 void GCMClientImpl::SetLastTokenFetchTime(const base::Time& time) {
475 gcm_store_->SetLastTokenFetchTime(
476 time,
477 base::Bind(&GCMClientImpl::DefaultStoreCallback,
478 weak_ptr_factory_.GetWeakPtr()));
479 }
480
473 void GCMClientImpl::StartCheckin() { 481 void GCMClientImpl::StartCheckin() {
474 // Make sure no checkin is in progress. 482 // Make sure no checkin is in progress.
475 if (checkin_request_.get()) 483 if (checkin_request_.get())
476 return; 484 return;
477 485
478 checkin_proto::ChromeBuildProto chrome_build_proto; 486 checkin_proto::ChromeBuildProto chrome_build_proto;
479 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); 487 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto);
480 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, 488 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id,
481 device_checkin_info_.secret, 489 device_checkin_info_.secret,
482 device_checkin_info_.account_tokens, 490 device_checkin_info_.account_tokens,
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 984
977 recorder_.RecordIncomingSendError( 985 recorder_.RecordIncomingSendError(
978 data_message_stanza.category(), 986 data_message_stanza.category(),
979 data_message_stanza.to(), 987 data_message_stanza.to(),
980 data_message_stanza.id()); 988 data_message_stanza.id());
981 delegate_->OnMessageSendError(data_message_stanza.category(), 989 delegate_->OnMessageSendError(data_message_stanza.category(),
982 send_error_details); 990 send_error_details);
983 } 991 }
984 992
985 } // namespace gcm 993 } // 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