OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_RETRY_VERIFIER_H_ |
| 6 #define CHROME_BROWSER_SYNC_RETRY_VERIFIER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/time.h" |
| 10 |
| 11 namespace browser_sync { |
| 12 namespace sessions { |
| 13 struct SyncSessionSnapshot; |
| 14 } |
| 15 } |
| 16 |
| 17 // The minimum and maximum wait times for a retry. The actual retry would take |
| 18 // place somewhere in this range. The algorithm that calculates the retry wait |
| 19 // time uses rand functions. |
| 20 struct DelayInfo { |
| 21 int64 min_delay; |
| 22 int64 max_delay; |
| 23 }; |
| 24 |
| 25 // Class to verify retries take place using the exponential backoff algorithm. |
| 26 class RetryVerifier { |
| 27 public: |
| 28 static const int kMaxRetry = 5; |
| 29 RetryVerifier(); |
| 30 ~RetryVerifier(); |
| 31 int RetryCount() const { return retry_count_; } |
| 32 void Initialize(const browser_sync::sessions::SyncSessionSnapshot& snap); |
| 33 void VerifyRetryInterval( |
| 34 const browser_sync::sessions::SyncSessionSnapshot& snap); |
| 35 bool Done() const { return done_; } |
| 36 bool Success() const { return Done() && success_; } |
| 37 |
| 38 private: |
| 39 int retry_count_; |
| 40 base::Time last_sync_time_; |
| 41 DelayInfo delay_table_[kMaxRetry]; |
| 42 bool done_; |
| 43 bool success_; |
| 44 DISALLOW_COPY_AND_ASSIGN(RetryVerifier); |
| 45 }; |
| 46 |
| 47 #endif // CHROME_BROWSER_SYNC_RETRY_VERIFIER_H_ |
OLD | NEW |