| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/sync/test/integration/retry_verifier.h" | 5 #include "chrome/browser/sync/test/integration/retry_verifier.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 12 #include "components/sync/engine/polling_constants.h" | 13 #include "components/sync/engine/polling_constants.h" |
| 13 #include "components/sync/sessions/sync_session_snapshot.h" | |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 // Given the current delay calculate the minimum and maximum wait times for | 16 // Given the current delay calculate the minimum and maximum wait times for |
| 17 // the next retry. | 17 // the next retry. |
| 18 DelayInfo CalculateDelay(int64_t current_delay) { | 18 DelayInfo CalculateDelay(int64_t current_delay) { |
| 19 int64_t backoff_s = | 19 int64_t backoff_s = |
| 20 std::max(static_cast<int64_t>(1), | 20 std::max(static_cast<int64_t>(1), |
| 21 current_delay * syncer::kBackoffRandomizationFactor); | 21 current_delay * syncer::kBackoffRandomizationFactor); |
| 22 | 22 |
| 23 DelayInfo delay_info; | 23 DelayInfo delay_info; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 RetryVerifier::RetryVerifier() : retry_count_(0), | 74 RetryVerifier::RetryVerifier() : retry_count_(0), |
| 75 success_(false), | 75 success_(false), |
| 76 done_(false) { | 76 done_(false) { |
| 77 memset(&delay_table_, 0, sizeof(delay_table_)); | 77 memset(&delay_table_, 0, sizeof(delay_table_)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 RetryVerifier::~RetryVerifier() { | 80 RetryVerifier::~RetryVerifier() { |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Initializes the state for verification. | 83 // Initializes the state for verification. |
| 84 void RetryVerifier::Initialize( | 84 void RetryVerifier::Initialize(const syncer::SyncCycleSnapshot& snap) { |
| 85 const syncer::sessions::SyncSessionSnapshot& snap) { | |
| 86 retry_count_ = 0; | 85 retry_count_ = 0; |
| 87 last_sync_time_ = snap.sync_start_time(); | 86 last_sync_time_ = snap.sync_start_time(); |
| 88 FillDelayTable(delay_table_, kMaxRetry); | 87 FillDelayTable(delay_table_, kMaxRetry); |
| 89 done_ = false; | 88 done_ = false; |
| 90 success_ = false; | 89 success_ = false; |
| 91 } | 90 } |
| 92 | 91 |
| 93 void RetryVerifier::VerifyRetryInterval( | 92 void RetryVerifier::VerifyRetryInterval(const syncer::SyncCycleSnapshot& snap) { |
| 94 const syncer::sessions::SyncSessionSnapshot& snap) { | |
| 95 DCHECK(retry_count_ < kMaxRetry); | 93 DCHECK(retry_count_ < kMaxRetry); |
| 96 if (retry_count_ == 0) { | 94 if (retry_count_ == 0) { |
| 97 if (snap.sync_start_time() != last_sync_time_) { | 95 if (snap.sync_start_time() != last_sync_time_) { |
| 98 retry_count_++; | 96 retry_count_++; |
| 99 last_sync_time_ = snap.sync_start_time(); | 97 last_sync_time_ = snap.sync_start_time(); |
| 100 } | 98 } |
| 101 success_ = true; | 99 success_ = true; |
| 102 return; | 100 return; |
| 103 } | 101 } |
| 104 | 102 |
| 105 // Check if the sync start time has changed. If so indicates a new sync | 103 // Check if the sync start time has changed. If so indicates a new sync |
| 106 // has taken place. | 104 // has taken place. |
| 107 if (snap.sync_start_time() != last_sync_time_) { | 105 if (snap.sync_start_time() != last_sync_time_) { |
| 108 base::TimeDelta delta = snap.sync_start_time() - last_sync_time_; | 106 base::TimeDelta delta = snap.sync_start_time() - last_sync_time_; |
| 109 success_ = IsRetryOnTime(delay_table_,retry_count_ -1, delta); | 107 success_ = IsRetryOnTime(delay_table_,retry_count_ -1, delta); |
| 110 last_sync_time_ = snap.sync_start_time(); | 108 last_sync_time_ = snap.sync_start_time(); |
| 111 ++retry_count_; | 109 ++retry_count_; |
| 112 done_ = (retry_count_ >= kMaxRetry); | 110 done_ = (retry_count_ >= kMaxRetry); |
| 113 return; | 111 return; |
| 114 } | 112 } |
| 115 } | 113 } |
| 116 | 114 |
| OLD | NEW |