gcm_backoff_policy.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/gcm_driver/gcm_backoff_policy.h" 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace gcm { 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace { 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Backoff policy. Shared across GCM requests. 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Note: In order to ensure a minimum of 20 seconds between server errors (for 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// server reasons), we have a 30s +- 10s (33%) jitter initial backoff. 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst net::BackoffEntry::Policy kDefaultBackoffPolicy = { 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Number of initial errors (in sequence) to ignore before applying 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // exponential back-off rules. 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 0, 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Initial delay for exponential back-off in ms. 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 30 * 1000, // 30 seconds. 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Factor by which the waiting time will be multiplied. 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2, 24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Fuzzing percentage. ex: 10% will spread requests randomly 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // between 90%-100% of the calculated time. 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 0.33, // 33%. 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Maximum amount of time we are willing to delay our request in ms. 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 10 * 60 * 1000, // 10 minutes. 315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Time to keep an entry from being discarded even when it 33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // has no significant state, -1 to never discard. 34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) -1, 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Don't use initial delay unless the last request was an error. 376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) false, 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}; 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} // namespace 41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)const net::BackoffEntry::Policy& GetGCMBackoffPolicy() { 43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return kDefaultBackoffPolicy; 446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} // namespace gcm 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)