Chromium Code Reviews| Index: google_apis/gcm/gcm_client_impl.cc |
| diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc |
| index 4cc0fdd38b0acf28280c6df8b7cef754703a3db2..c505d879cbdeb2a8134732aa39d08d6f85975754 100644 |
| --- a/google_apis/gcm/gcm_client_impl.cc |
| +++ b/google_apis/gcm/gcm_client_impl.cc |
| @@ -74,6 +74,7 @@ enum MessageType { |
| const char kMCSEndpointMain[] = "https://mtalk.google.com:5228"; |
| const char kMCSEndpointFallback[] = "https://mtalk.google.com:443"; |
| +const int64 kDefaultCheckinInterval = 172800LL; // seconds - 2 days. |
|
Nicolas Zea
2014/04/02 21:53:55
nit: prefer 60 * 60 * 24 * 2 for readability
fgorski
2014/04/02 22:37:21
Done.
|
| const int kMaxRegistrationRetries = 5; |
| const char kMessageTypeDataMessage[] = "gcm"; |
| const char kMessageTypeDeletedMessagesKey[] = "deleted_messages"; |
| @@ -216,8 +217,10 @@ void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) { |
| if (!device_checkin_info_.IsValid()) { |
| device_checkin_info_.Reset(); |
| state_ = INITIAL_DEVICE_CHECKIN; |
| - StartCheckin(device_checkin_info_); |
| + StartCheckin(); |
| return; |
| + } else { |
|
jianli
2014/04/02 22:00:18
nit: revert these two parts
fgorski
2014/04/02 22:37:21
Done.
|
| + SchedulePeriodicCheckin(result->last_checkin_time); |
| } |
| OnReady(); |
| @@ -281,14 +284,14 @@ void GCMClientImpl::ResetState() { |
| // TODO(fgorski): reset all of the necessart objects and start over. |
| } |
| -void GCMClientImpl::StartCheckin(const CheckinInfo& checkin_info) { |
| +void GCMClientImpl::StartCheckin() { |
| checkin_request_.reset( |
| new CheckinRequest(base::Bind(&GCMClientImpl::OnCheckinCompleted, |
| weak_ptr_factory_.GetWeakPtr()), |
| kDefaultBackoffPolicy, |
| chrome_build_proto_, |
| - checkin_info.android_id, |
| - checkin_info.secret, |
| + device_checkin_info_.android_id, |
| + device_checkin_info_.secret, |
| account_ids_, |
| url_request_context_getter_)); |
| checkin_request_->Start(); |
| @@ -315,10 +318,38 @@ void GCMClientImpl::OnCheckinCompleted(uint64 android_id, |
| if (device_checkin_info_.android_id != checkin_info.android_id || |
| device_checkin_info_.secret != checkin_info.secret) { |
| ResetState(); |
|
jianli
2014/04/02 22:00:18
When the updated checkin info is different, we cal
fgorski
2014/04/02 22:37:21
Done.
|
| - } else { |
| - // TODO(fgorski): Reset the checkin timer. |
| } |
| } |
| + |
| + if (device_checkin_info_.IsValid()) { |
| + base::Time last_checkin_time = clock_->Now(); |
| + gcm_store_->SetLastCheckinTime( |
| + last_checkin_time, |
| + base::Bind(&GCMClientImpl::SetLastCheckinTimeCallback, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + SchedulePeriodicCheckin(last_checkin_time); |
| + } |
| +} |
| + |
| +void GCMClientImpl::SchedulePeriodicCheckin( |
| + const base::Time& last_checkin_time) { |
| + base::TimeDelta time_to_next_checkin = last_checkin_time |
| + + base::TimeDelta::FromSeconds(kDefaultCheckinInterval) |
|
jianli
2014/04/02 22:00:18
nit: + and - should be placed at the end of previo
fgorski
2014/04/02 22:37:21
Done.
|
| + - clock_->Now(); |
| + if (time_to_next_checkin < base::TimeDelta::FromSeconds(0L)) |
| + time_to_next_checkin = base::TimeDelta::FromSeconds(0L); |
| + // TODO(fgorski): Make sure that once dynamic events (like accounts list |
| + // change) trigger checkin we reset the timer. |
| + base::MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&GCMClientImpl::StartCheckin, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + time_to_next_checkin); |
| +} |
| + |
| +void GCMClientImpl::SetLastCheckinTimeCallback(bool success) { |
| + // TODO(fgorski): This is one of the signals that store needs a rebuild. |
| + DCHECK(success); |
| } |
| void GCMClientImpl::SetDeviceCredentialsCallback(bool success) { |