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