| Index: chrome/browser/services/gcm/gcm_account_tracker.cc
|
| diff --git a/chrome/browser/services/gcm/gcm_account_tracker.cc b/chrome/browser/services/gcm/gcm_account_tracker.cc
|
| index 22dd5b526f19ee6967cec3ee7aebda83bb2c65a9..52f2914a3beb71d54488a45ed8bccab0b0f243ca 100644
|
| --- a/chrome/browser/services/gcm/gcm_account_tracker.cc
|
| +++ b/chrome/browser/services/gcm/gcm_account_tracker.cc
|
| @@ -80,6 +80,11 @@ void GCMAccountTracker::Start() {
|
| }
|
|
|
| void GCMAccountTracker::ScheduleReportTokens() {
|
| + // Shortcutting here, in case GCM Driver is not yet connected. In that case
|
| + // reporting will be scheduled/started when the connection is made.
|
| + if (!driver_->IsConnected())
|
| + return;
|
| +
|
| DVLOG(1) << "Deferring the token reporting for: "
|
| << GetTimeToNextTokenReporting().InSeconds() << " seconds.";
|
|
|
| @@ -164,8 +169,12 @@ void GCMAccountTracker::OnGetTokenFailure(
|
| }
|
|
|
| void GCMAccountTracker::OnConnected(const net::IPEndPoint& ip_endpoint) {
|
| + // We are sure here, that GCM is running and connected. We can start reporting
|
| + // tokens if reporting is due now, or schedule reporting for later.
|
| if (IsTokenReportingRequired())
|
| ReportTokens();
|
| + else
|
| + ScheduleReportTokens();
|
| }
|
|
|
| void GCMAccountTracker::OnDisconnected() {
|
| @@ -276,8 +285,20 @@ base::TimeDelta GCMAccountTracker::GetTimeToNextTokenReporting() const {
|
| driver_->GetLastTokenFetchTime() +
|
| base::TimeDelta::FromMilliseconds(kTokenReportingIntervalMs) -
|
| base::Time::Now();
|
| - return time_till_next_reporting < base::TimeDelta() ?
|
| - base::TimeDelta() : time_till_next_reporting;
|
| +
|
| + // Case when token fetching is overdue.
|
| + if (time_till_next_reporting < base::TimeDelta())
|
| + return base::TimeDelta();
|
| +
|
| + // Case when calculated period is larger than expected, including the
|
| + // situation when the method is called before GCM driver is completely
|
| + // initialized.
|
| + if (time_till_next_reporting >
|
| + base::TimeDelta::FromMilliseconds(kTokenReportingIntervalMs)) {
|
| + return base::TimeDelta::FromMilliseconds(kTokenReportingIntervalMs);
|
| + }
|
| +
|
| + return time_till_next_reporting;
|
| }
|
|
|
| void GCMAccountTracker::DeleteTokenRequest(
|
|
|