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_file_system/sync_process_runner.h" | 5 #include "chrome/browser/sync_file_system/sync_process_runner.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/macros.h" |
8 #include "chrome/browser/sync_file_system/logger.h" | 9 #include "chrome/browser/sync_file_system/logger.h" |
9 | 10 |
10 namespace sync_file_system { | 11 namespace sync_file_system { |
11 | 12 |
12 const int64 SyncProcessRunner::kSyncDelayInMilliseconds = | 13 const int64_t SyncProcessRunner::kSyncDelayInMilliseconds = |
13 1 * base::Time::kMillisecondsPerSecond; // 1 sec | 14 1 * base::Time::kMillisecondsPerSecond; // 1 sec |
14 const int64 SyncProcessRunner::kSyncDelayWithSyncError = | 15 const int64_t SyncProcessRunner::kSyncDelayWithSyncError = |
15 3 * base::Time::kMillisecondsPerSecond; // 3 sec | 16 3 * base::Time::kMillisecondsPerSecond; // 3 sec |
16 const int64 SyncProcessRunner::kSyncDelayFastInMilliseconds = 100; // 100 ms | 17 const int64_t SyncProcessRunner::kSyncDelayFastInMilliseconds = 100; // 100 ms |
17 const int SyncProcessRunner::kPendingChangeThresholdForFastSync = 10; | 18 const int SyncProcessRunner::kPendingChangeThresholdForFastSync = 10; |
18 const int64 SyncProcessRunner::kSyncDelaySlowInMilliseconds = | 19 const int64_t SyncProcessRunner::kSyncDelaySlowInMilliseconds = |
19 30 * base::Time::kMillisecondsPerSecond; // 30 sec | 20 30 * base::Time::kMillisecondsPerSecond; // 30 sec |
20 const int64 SyncProcessRunner::kSyncDelayMaxInMilliseconds = | 21 const int64_t SyncProcessRunner::kSyncDelayMaxInMilliseconds = |
21 30 * 60 * base::Time::kMillisecondsPerSecond; // 30 min | 22 30 * 60 * base::Time::kMillisecondsPerSecond; // 30 min |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class BaseTimerHelper : public SyncProcessRunner::TimerHelper { | 26 class BaseTimerHelper : public SyncProcessRunner::TimerHelper { |
26 public: | 27 public: |
27 BaseTimerHelper() {} | 28 BaseTimerHelper() {} |
28 | 29 |
29 bool IsRunning() override { return timer_.IsRunning(); } | 30 bool IsRunning() override { return timer_.IsRunning(); } |
30 | 31 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (last_service_state != service_state_) | 105 if (last_service_state != service_state_) |
105 ThrottleSync(kSyncDelaySlowInMilliseconds); | 106 ThrottleSync(kSyncDelaySlowInMilliseconds); |
106 ScheduleInternal(kSyncDelayMaxInMilliseconds); | 107 ScheduleInternal(kSyncDelayMaxInMilliseconds); |
107 return; | 108 return; |
108 } | 109 } |
109 | 110 |
110 NOTREACHED(); | 111 NOTREACHED(); |
111 ScheduleInternal(kSyncDelayMaxInMilliseconds); | 112 ScheduleInternal(kSyncDelayMaxInMilliseconds); |
112 } | 113 } |
113 | 114 |
114 void SyncProcessRunner::ThrottleSync(int64 base_delay) { | 115 void SyncProcessRunner::ThrottleSync(int64_t base_delay) { |
115 base::TimeTicks now = timer_helper_->Now(); | 116 base::TimeTicks now = timer_helper_->Now(); |
116 base::TimeDelta elapsed = std::min(now, throttle_until_) - throttle_from_; | 117 base::TimeDelta elapsed = std::min(now, throttle_until_) - throttle_from_; |
117 DCHECK(base::TimeDelta() <= elapsed); | 118 DCHECK(base::TimeDelta() <= elapsed); |
118 | 119 |
119 throttle_from_ = now; | 120 throttle_from_ = now; |
120 // Extend throttling duration by twice the elapsed time. | 121 // Extend throttling duration by twice the elapsed time. |
121 // That is, if the backoff repeats in a short period, the throttling period | 122 // That is, if the backoff repeats in a short period, the throttling period |
122 // doesn't grow exponentially. If the backoff happens on the end of | 123 // doesn't grow exponentially. If the backoff happens on the end of |
123 // throttling period, it causes another throttling period that is twice as | 124 // throttling period, it causes another throttling period that is twice as |
124 // long as previous. | 125 // long as previous. |
(...skipping 13 matching lines...) Expand all Loading... |
138 | 139 |
139 void SyncProcessRunner::ResetThrottling() { | 140 void SyncProcessRunner::ResetThrottling() { |
140 throttle_from_ = base::TimeTicks(); | 141 throttle_from_ = base::TimeTicks(); |
141 throttle_until_ = base::TimeTicks(); | 142 throttle_until_ = base::TimeTicks(); |
142 } | 143 } |
143 | 144 |
144 SyncServiceState SyncProcessRunner::GetServiceState() { | 145 SyncServiceState SyncProcessRunner::GetServiceState() { |
145 return client_->GetSyncServiceState(); | 146 return client_->GetSyncServiceState(); |
146 } | 147 } |
147 | 148 |
148 void SyncProcessRunner::OnChangesUpdated( | 149 void SyncProcessRunner::OnChangesUpdated(int64_t pending_changes) { |
149 int64 pending_changes) { | |
150 DCHECK_GE(pending_changes, 0); | 150 DCHECK_GE(pending_changes, 0); |
151 int64 old_pending_changes = pending_changes_; | 151 int64_t old_pending_changes = pending_changes_; |
152 pending_changes_ = pending_changes; | 152 pending_changes_ = pending_changes; |
153 if (old_pending_changes != pending_changes) { | 153 if (old_pending_changes != pending_changes) { |
154 CheckIfIdle(); | 154 CheckIfIdle(); |
155 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 155 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
156 "[%s] pending_changes updated: %" PRId64, | 156 "[%s] pending_changes updated: %" PRId64, |
157 name_.c_str(), pending_changes); | 157 name_.c_str(), pending_changes); |
158 } | 158 } |
159 Schedule(); | 159 Schedule(); |
160 } | 160 } |
161 | 161 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 197 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
198 "[%s] * Started", name_.c_str()); | 198 "[%s] * Started", name_.c_str()); |
199 | 199 |
200 StartSync(base::Bind(&SyncProcessRunner::Finished, factory_.GetWeakPtr(), | 200 StartSync(base::Bind(&SyncProcessRunner::Finished, factory_.GetWeakPtr(), |
201 now)); | 201 now)); |
202 if (running_tasks_ < max_parallel_task_) | 202 if (running_tasks_ < max_parallel_task_) |
203 Schedule(); | 203 Schedule(); |
204 } | 204 } |
205 | 205 |
206 void SyncProcessRunner::ScheduleInternal(int64 delay) { | 206 void SyncProcessRunner::ScheduleInternal(int64_t delay) { |
207 base::TimeTicks now = timer_helper_->Now(); | 207 base::TimeTicks now = timer_helper_->Now(); |
208 base::TimeTicks next_scheduled; | 208 base::TimeTicks next_scheduled; |
209 | 209 |
210 if (timer_helper_->IsRunning()) { | 210 if (timer_helper_->IsRunning()) { |
211 next_scheduled = last_run_ + base::TimeDelta::FromMilliseconds(delay); | 211 next_scheduled = last_run_ + base::TimeDelta::FromMilliseconds(delay); |
212 if (next_scheduled < now) { | 212 if (next_scheduled < now) { |
213 next_scheduled = | 213 next_scheduled = |
214 now + base::TimeDelta::FromMilliseconds(kSyncDelayFastInMilliseconds); | 214 now + base::TimeDelta::FromMilliseconds(kSyncDelayFastInMilliseconds); |
215 } | 215 } |
216 } else { | 216 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
233 FROM_HERE, next_scheduled - now, | 233 FROM_HERE, next_scheduled - now, |
234 base::Bind(&SyncProcessRunner::Run, base::Unretained(this))); | 234 base::Bind(&SyncProcessRunner::Run, base::Unretained(this))); |
235 } | 235 } |
236 | 236 |
237 void SyncProcessRunner::CheckIfIdle() { | 237 void SyncProcessRunner::CheckIfIdle() { |
238 if (pending_changes_ == 0 && running_tasks_ == 0) | 238 if (pending_changes_ == 0 && running_tasks_ == 0) |
239 client_->OnSyncIdle(); | 239 client_->OnSyncIdle(); |
240 } | 240 } |
241 | 241 |
242 } // namespace sync_file_system | 242 } // namespace sync_file_system |
OLD | NEW |