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..29c60299d1d294400587c79a9c2a476a69831696 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" |
@@ -35,8 +37,21 @@ const int kFirstTimeDelaySeconds = 1 * 60; // 1 minute. |
// The fuzzing variation added to the polling delay. |
const int kGCMChannelRequestTimeJitterSeconds = 15 * 60; // 15 minues. |
+// The minimum poll interval that can be overridden to. |
+const int kMinCustomPollIntervalMinutes = 5; |
+ |
+// Custom poll interval could not be used more than the number below. |
+const int kMaxNumberToUseCustomPollInterval = 5; |
+ |
} // namespace |
+namespace switches { |
+ |
+// Override the default poll interval for testing purpose. |
+const char kCustomPollIntervalMinutes[] = "gcm-channel-poll-interval"; |
+ |
+} // namepsace switches |
+ |
// static |
void GCMChannelStatusSyncer::RegisterPrefs(PrefRegistrySimple* registry) { |
registry->RegisterBooleanPref(kGCMChannelStatus, true); |
@@ -82,6 +97,7 @@ GCMChannelStatusSyncer::GCMChannelStatusSyncer( |
gcm_enabled_(true), |
poll_interval_seconds_( |
GCMChannelStatusRequest::default_poll_interval_seconds()), |
+ custom_poll_interval_use_count_(0), |
delay_removed_for_testing_(false), |
weak_ptr_factory_(this) { |
gcm_enabled_ = prefs_->GetBoolean(kGCMChannelStatus); |
@@ -91,6 +107,17 @@ GCMChannelStatusSyncer::GCMChannelStatusSyncer( |
poll_interval_seconds_ = |
GCMChannelStatusRequest::min_poll_interval_seconds(); |
} |
+ if (CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kCustomPollIntervalMinutes)) { |
+ std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kCustomPollIntervalMinutes)); |
+ int minutes = 0; |
+ if (base::StringToInt(value, &minutes) && |
+ minutes >= kMinCustomPollIntervalMinutes) { |
+ poll_interval_seconds_ = minutes * 60; |
+ custom_poll_interval_use_count_ = kMaxNumberToUseCustomPollInterval; |
+ } |
fgorski
2014/10/15 21:17:20
nit: DVLOG here that it was not set and we are ign
|
+ } |
last_check_time_ = base::Time::FromInternalValue( |
prefs_->GetInt64(kGCMChannelLastCheckTime)); |
} |
@@ -111,7 +138,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 +149,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 +211,11 @@ base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const { |
delay_seconds = kFirstTimeDelaySeconds; |
} else { |
// Otherwise, add a fuzzing variation to the delay. |
- delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); |
+ // The fuzzing variation is off when the custom interval is used. |
+ if (custom_poll_interval_use_count_) |
+ custom_poll_interval_use_count_--; |
+ else |
+ delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); |
} |
return base::TimeDelta::FromSeconds(delay_seconds); |