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

Unified Diff: chrome/browser/services/gcm/gcm_account_tracker.cc

Issue 885753002: Fixing the super-long delay when GCMAccountTracker posts a task (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding dependnecy on GCM Driver being connected Created 5 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/services/gcm/gcm_account_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « no previous file | chrome/browser/services/gcm/gcm_account_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698