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

Unified Diff: components/gcm_driver/gcm_channel_status_syncer.cc

Issue 653843003: [GCM] Start GCMChannelStatusSyncer when GCM is disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a poll interval switch Created 6 years, 2 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 | « components/gcm_driver/gcm_channel_status_syncer.h ('k') | components/gcm_driver/gcm_driver_desktop.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_channel_status_syncer.cc
diff --git a/components/gcm_driver/gcm_channel_status_syncer.cc b/components/gcm_driver/gcm_channel_status_syncer.cc
index 443c90d57b8207f63390f8860cf8784b30ba594c..f86cdfe6115a4704e9aef61d02e05ec165cb6fdb 100644
--- a/components/gcm_driver/gcm_channel_status_syncer.cc
+++ b/components/gcm_driver/gcm_channel_status_syncer.cc
@@ -5,12 +5,14 @@
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/rand_util.h"
+#include "base/strings/string_number_conversions.h"
#include "components/gcm_driver/gcm_channel_status_request.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/pref_registry/pref_registry_syncable.h"
@@ -28,6 +30,9 @@ const char kGCMChannelPollIntervalSeconds[] = "gcm.poll_interval";
// Last time when checking with the GCM channel status server is done.
const char kGCMChannelLastCheckTime[] = "gcm.check_time";
+// Override the default poll interval for testing purpose.
+const char kCustomPollIntervalMinutes[] = "gcm-channel-poll-interval";
+
// A small delay to avoid sending request at browser startup time for first-time
// request.
const int kFirstTimeDelaySeconds = 1 * 60; // 1 minute.
@@ -80,6 +85,7 @@ GCMChannelStatusSyncer::GCMChannelStatusSyncer(
user_agent_(user_agent),
request_context_(request_context),
gcm_enabled_(true),
+ jitter_enabled_(true),
poll_interval_seconds_(
GCMChannelStatusRequest::default_poll_interval_seconds()),
delay_removed_for_testing_(false),
@@ -91,6 +97,16 @@ GCMChannelStatusSyncer::GCMChannelStatusSyncer(
poll_interval_seconds_ =
GCMChannelStatusRequest::min_poll_interval_seconds();
}
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kCustomPollIntervalMinutes)) {
+ std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ kCustomPollIntervalMinutes));
+ int minutes = 0;
+ if (base::StringToInt(value, &minutes)) {
+ poll_interval_seconds_ = minutes * 60;
fgorski 2014/10/15 17:01:52 we should make sure it is >0, right?
+ // The fuzzing variation is off when the custom interval is used.
+ jitter_enabled_ = false;
+ }
+ }
last_check_time_ = base::Time::FromInternalValue(
prefs_->GetInt64(kGCMChannelLastCheckTime));
}
@@ -111,7 +127,8 @@ void GCMChannelStatusSyncer::Stop() {
weak_ptr_factory_.InvalidateWeakPtrs();
}
-void GCMChannelStatusSyncer::OnRequestCompleted(bool enabled,
+void GCMChannelStatusSyncer::OnRequestCompleted(bool update_received,
+ bool enabled,
int poll_interval_seconds) {
DCHECK(request_);
request_.reset();
@@ -121,20 +138,23 @@ void GCMChannelStatusSyncer::OnRequestCompleted(bool enabled,
prefs_->SetInt64(kGCMChannelLastCheckTime,
last_check_time_.ToInternalValue());
- if (gcm_enabled_ != enabled) {
- gcm_enabled_ = enabled;
- prefs_->SetBoolean(kGCMChannelStatus, enabled);
- if (gcm_enabled_)
- driver_->Enable();
- else
- driver_->Disable();
- }
-
- DCHECK_GE(poll_interval_seconds,
- GCMChannelStatusRequest::min_poll_interval_seconds());
- if (poll_interval_seconds_ != poll_interval_seconds) {
- poll_interval_seconds_ = poll_interval_seconds;
- prefs_->SetInteger(kGCMChannelPollIntervalSeconds, poll_interval_seconds_);
+ if (update_received) {
+ if (gcm_enabled_ != enabled) {
+ gcm_enabled_ = enabled;
+ prefs_->SetBoolean(kGCMChannelStatus, enabled);
+ if (gcm_enabled_)
+ driver_->Enable();
+ else
+ driver_->Disable();
+ }
+
+ DCHECK_GE(poll_interval_seconds,
+ GCMChannelStatusRequest::min_poll_interval_seconds());
+ if (poll_interval_seconds_ != poll_interval_seconds) {
+ poll_interval_seconds_ = poll_interval_seconds;
+ prefs_->SetInteger(kGCMChannelPollIntervalSeconds,
+ poll_interval_seconds_);
+ }
}
ScheduleRequest();
@@ -180,7 +200,8 @@ base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const {
delay_seconds = kFirstTimeDelaySeconds;
} else {
// Otherwise, add a fuzzing variation to the delay.
- delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds);
+ if (jitter_enabled_)
+ delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds);
}
return base::TimeDelta::FromSeconds(delay_seconds);
« no previous file with comments | « components/gcm_driver/gcm_channel_status_syncer.h ('k') | components/gcm_driver/gcm_driver_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698