diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 17:52:26 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 17:52:26 +0000 |
commit | 52186d0fad83b466f11165590f9b89fa549264d3 (patch) | |
tree | 225c52501680ebe40243b5f80121bd8727db5ca0 /google_apis | |
parent | 5de1ad792fa9810d9882f767f3be41dc494f0288 (diff) | |
download | chromium_src-52186d0fad83b466f11165590f9b89fa549264d3.zip chromium_src-52186d0fad83b466f11165590f9b89fa549264d3.tar.gz chromium_src-52186d0fad83b466f11165590f9b89fa549264d3.tar.bz2 |
[GCM] Pull backoff policy out into GCM and update values
The default backoff time is now 15 seconds. Additionally, the backoff
policy is now injected into the connection factory, to allow sharing it
with the registration and checking logic.
BUG=284553
Review URL: https://codereview.chromium.org/154743003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl.cc | 33 | ||||
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl.h | 4 | ||||
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl_unittest.cc | 5 | ||||
-rw-r--r-- | google_apis/gcm/gcm_client_impl.cc | 35 | ||||
-rw-r--r-- | google_apis/gcm/tools/mcs_probe.cc | 27 |
5 files changed, 73 insertions, 31 deletions
diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc index 7ae40be..f75b719 100644 --- a/google_apis/gcm/engine/connection_factory_impl.cc +++ b/google_apis/gcm/engine/connection_factory_impl.cc @@ -29,40 +29,15 @@ const int kReadTimeoutMs = 30000; // 30 seconds. // as if it was transient). const int kConnectionResetWindowSecs = 10; // 10 seconds. -// Backoff policy. -const net::BackoffEntry::Policy kConnectionBackoffPolicy = { - // Number of initial errors (in sequence) to ignore before applying - // exponential back-off rules. - 0, - - // Initial delay for exponential back-off in ms. - 10000, // 10 seconds. - - // Factor by which the waiting time will be multiplied. - 2, - - // Fuzzing percentage. ex: 10% will spread requests randomly - // between 90%-100% of the calculated time. - 0.5, // 50%. - - // Maximum amount of time we are willing to delay our request in ms. - 1000 * 60 * 5, // 5 minutes. - - // Time to keep an entry from being discarded even when it - // has no significant state, -1 to never discard. - -1, - - // Don't use initial delay unless the last request was an error. - false, -}; - } // namespace ConnectionFactoryImpl::ConnectionFactoryImpl( const GURL& mcs_endpoint, + const net::BackoffEntry::Policy& backoff_policy, scoped_refptr<net::HttpNetworkSession> network_session, net::NetLog* net_log) : mcs_endpoint_(mcs_endpoint), + backoff_policy_(backoff_policy), network_session_(network_session), net_log_(net_log), connecting_(false), @@ -78,8 +53,8 @@ void ConnectionFactoryImpl::Initialize( const ConnectionHandler::ProtoSentCallback& write_callback) { DCHECK(!connection_handler_); - previous_backoff_ = CreateBackoffEntry(&kConnectionBackoffPolicy); - backoff_entry_ = CreateBackoffEntry(&kConnectionBackoffPolicy); + previous_backoff_ = CreateBackoffEntry(&backoff_policy_); + backoff_entry_ = CreateBackoffEntry(&backoff_policy_); request_builder_ = request_builder; net::NetworkChangeNotifier::AddIPAddressObserver(this); diff --git a/google_apis/gcm/engine/connection_factory_impl.h b/google_apis/gcm/engine/connection_factory_impl.h index 3827b1c..3d79a78 100644 --- a/google_apis/gcm/engine/connection_factory_impl.h +++ b/google_apis/gcm/engine/connection_factory_impl.h @@ -30,6 +30,7 @@ class GCM_EXPORT ConnectionFactoryImpl : public: ConnectionFactoryImpl( const GURL& mcs_endpoint, + const net::BackoffEntry::Policy& backoff_policy, scoped_refptr<net::HttpNetworkSession> network_session, net::NetLog* net_log); virtual ~ConnectionFactoryImpl(); @@ -80,6 +81,9 @@ class GCM_EXPORT ConnectionFactoryImpl : // The MCS endpoint to make connections to. const GURL mcs_endpoint_; + // The backoff policy to use. + const net::BackoffEntry::Policy backoff_policy_; + // ---- net:: components for establishing connections. ---- // Network session for creating new connections. const scoped_refptr<net::HttpNetworkSession> network_session_; diff --git a/google_apis/gcm/engine/connection_factory_impl_unittest.cc b/google_apis/gcm/engine/connection_factory_impl_unittest.cc index d0fd245..9a85681 100644 --- a/google_apis/gcm/engine/connection_factory_impl_unittest.cc +++ b/google_apis/gcm/engine/connection_factory_impl_unittest.cc @@ -132,7 +132,10 @@ class TestConnectionFactoryImpl : public ConnectionFactoryImpl { TestConnectionFactoryImpl::TestConnectionFactoryImpl( const base::Closure& finished_callback) - : ConnectionFactoryImpl(GURL(kMCSEndpoint), NULL, NULL), + : ConnectionFactoryImpl(GURL(kMCSEndpoint), + net::BackoffEntry::Policy(), + NULL, + NULL), connect_result_(net::ERR_UNEXPECTED), num_expected_attempts_(0), connections_fulfilled_(true), diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc index 1a28bd5..92402e1 100644 --- a/google_apis/gcm/gcm_client_impl.cc +++ b/google_apis/gcm/gcm_client_impl.cc @@ -28,6 +28,36 @@ namespace gcm { namespace { +// Backoff policy. Shared across reconnection logic and checkin/registration +// retries. +// TODO(zea): consider sharing/synchronizing the scheduling of backoff retries +// themselves. +const net::BackoffEntry::Policy kDefaultBackoffPolicy = { + // Number of initial errors (in sequence) to ignore before applying + // exponential back-off rules. + 0, + + // Initial delay for exponential back-off in ms. + 15000, // 15 seconds. + + // Factor by which the waiting time will be multiplied. + 2, + + // Fuzzing percentage. ex: 10% will spread requests randomly + // between 90%-100% of the calculated time. + 0.5, // 50%. + + // Maximum amount of time we are willing to delay our request in ms. + 1000 * 60 * 5, // 5 minutes. + + // Time to keep an entry from being discarded even when it + // has no significant state, -1 to never discard. + -1, + + // Don't use initial delay unless the last request was an error. + false, +}; + // Indicates a message type of the received message. enum MessageType { UNKNOWN, // Undetermined type. @@ -134,7 +164,10 @@ void GCMClientImpl::Initialize( DCHECK(network_session_params); network_session_ = new net::HttpNetworkSession(*network_session_params); connection_factory_.reset(new ConnectionFactoryImpl( - GURL(kMCSEndpoint), network_session_, net_log_.net_log())); + GURL(kMCSEndpoint), + kDefaultBackoffPolicy, + network_session_, + net_log_.net_log())); mcs_client_.reset(new MCSClient(clock_.get(), connection_factory_.get(), gcm_store_.get())); diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index 7d5168b..7d05a29 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -51,6 +51,32 @@ namespace gcm { namespace { +const net::BackoffEntry::Policy kDefaultBackoffPolicy = { + // Number of initial errors (in sequence) to ignore before applying + // exponential back-off rules. + 0, + + // Initial delay for exponential back-off in ms. + 15000, // 15 seconds. + + // Factor by which the waiting time will be multiplied. + 2, + + // Fuzzing percentage. ex: 10% will spread requests randomly + // between 90%-100% of the calculated time. + 0.5, // 50%. + + // Maximum amount of time we are willing to delay our request in ms. + 1000 * 60 * 5, // 5 minutes. + + // Time to keep an entry from being discarded even when it + // has no significant state, -1 to never discard. + -1, + + // Don't use initial delay unless the last request was an error. + false, +}; + // Default values used to communicate with the check-in server. const char kChromeVersion[] = "Chrome MCS Probe"; const int64 kUserSerialNumber = 1; @@ -273,6 +299,7 @@ void MCSProbe::Start() { connection_factory_.reset( new ConnectionFactoryImpl(GURL("https://" + net::HostPortPair( server_host_, server_port_).ToString()), + kDefaultBackoffPolicy, network_session_, &net_log_)); gcm_store_.reset( |