Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: chrome/browser/sync_file_system/sync_process_runner.cc

Issue 378223002: [SyncFS] Make base::TimeTicks::Now() dependency in SyncProcessRunner injectable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync_file_system/sync_process_runner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/sync_file_system/logger.h" 8 #include "chrome/browser/sync_file_system/logger.h"
9 9
10 namespace sync_file_system { 10 namespace sync_file_system {
(...skipping 26 matching lines...) Expand all
37 virtual bool IsRunning() OVERRIDE { 37 virtual bool IsRunning() OVERRIDE {
38 return timer_.IsRunning(); 38 return timer_.IsRunning();
39 } 39 }
40 40
41 virtual void Start(const tracked_objects::Location& from_here, 41 virtual void Start(const tracked_objects::Location& from_here,
42 const base::TimeDelta& delay, 42 const base::TimeDelta& delay,
43 const base::Closure& closure) OVERRIDE { 43 const base::Closure& closure) OVERRIDE {
44 timer_.Start(from_here, delay, closure); 44 timer_.Start(from_here, delay, closure);
45 } 45 }
46 46
47 virtual base::TimeTicks Now() const OVERRIDE {
48 return base::TimeTicks::Now();
49 }
50
47 virtual ~BaseTimerHelper() {} 51 virtual ~BaseTimerHelper() {}
48 52
49 private: 53 private:
50 base::OneShotTimer<SyncProcessRunner> timer_; 54 base::OneShotTimer<SyncProcessRunner> timer_;
51 55
52 DISALLOW_COPY_AND_ASSIGN(BaseTimerHelper); 56 DISALLOW_COPY_AND_ASSIGN(BaseTimerHelper);
53 }; 57 };
54 58
55 bool WasSuccessfulSync(SyncStatusCode status) { 59 bool WasSuccessfulSync(SyncStatusCode status) {
56 return status == SYNC_STATUS_OK || 60 return status == SYNC_STATUS_OK ||
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 150 }
147 151
148 void SyncProcessRunner::Finished(const base::TimeTicks& start_time, 152 void SyncProcessRunner::Finished(const base::TimeTicks& start_time,
149 SyncStatusCode status) { 153 SyncStatusCode status) {
150 DCHECK_LT(0, running_tasks_); 154 DCHECK_LT(0, running_tasks_);
151 DCHECK_LE(running_tasks_, max_parallel_task_); 155 DCHECK_LE(running_tasks_, max_parallel_task_);
152 --running_tasks_; 156 --running_tasks_;
153 util::Log(logging::LOG_VERBOSE, FROM_HERE, 157 util::Log(logging::LOG_VERBOSE, FROM_HERE,
154 "[%s] * Finished (elapsed: %" PRId64 " sec)", 158 "[%s] * Finished (elapsed: %" PRId64 " sec)",
155 name_.c_str(), 159 name_.c_str(),
156 (base::TimeTicks::Now() - start_time).InSeconds()); 160 (timer_helper_->Now() - start_time).InSeconds());
157 if (status == SYNC_STATUS_NO_CHANGE_TO_SYNC || 161 if (status == SYNC_STATUS_NO_CHANGE_TO_SYNC ||
158 status == SYNC_STATUS_FILE_BUSY) 162 status == SYNC_STATUS_FILE_BUSY)
159 ScheduleInternal(kSyncDelayMaxInMilliseconds); 163 ScheduleInternal(kSyncDelayMaxInMilliseconds);
160 else if (!WasSuccessfulSync(status) && 164 else if (!WasSuccessfulSync(status) &&
161 GetServiceState() == SYNC_SERVICE_RUNNING) 165 GetServiceState() == SYNC_SERVICE_RUNNING)
162 ScheduleInternal(kSyncDelayWithSyncError); 166 ScheduleInternal(kSyncDelayWithSyncError);
163 else 167 else
164 Schedule(); 168 Schedule();
165 } 169 }
166 170
167 void SyncProcessRunner::Run() { 171 void SyncProcessRunner::Run() {
168 if (running_tasks_ >= max_parallel_task_) 172 if (running_tasks_ >= max_parallel_task_)
169 return; 173 return;
170 ++running_tasks_; 174 ++running_tasks_;
171 last_scheduled_ = base::TimeTicks::Now(); 175 last_scheduled_ = timer_helper_->Now();
172 last_delay_ = current_delay_; 176 last_delay_ = current_delay_;
173 177
174 util::Log(logging::LOG_VERBOSE, FROM_HERE, 178 util::Log(logging::LOG_VERBOSE, FROM_HERE,
175 "[%s] * Started", name_.c_str()); 179 "[%s] * Started", name_.c_str());
176 180
177 StartSync(base::Bind(&SyncProcessRunner::Finished, factory_.GetWeakPtr(), 181 StartSync(base::Bind(&SyncProcessRunner::Finished, factory_.GetWeakPtr(),
178 last_scheduled_)); 182 last_scheduled_));
179 } 183 }
180 184
181 void SyncProcessRunner::ScheduleInternal(int64 delay) { 185 void SyncProcessRunner::ScheduleInternal(int64 delay) {
182 base::TimeDelta time_to_next = base::TimeDelta::FromMilliseconds(delay); 186 base::TimeDelta time_to_next = base::TimeDelta::FromMilliseconds(delay);
183 187
184 if (timer_helper_->IsRunning()) { 188 if (timer_helper_->IsRunning()) {
185 if (current_delay_ == delay) 189 if (current_delay_ == delay)
186 return; 190 return;
187 191
188 base::TimeDelta elapsed = base::TimeTicks::Now() - last_scheduled_; 192 base::TimeDelta elapsed = timer_helper_->Now() - last_scheduled_;
189 if (elapsed < time_to_next) { 193 if (elapsed < time_to_next) {
190 time_to_next = time_to_next - elapsed; 194 time_to_next = time_to_next - elapsed;
191 } else { 195 } else {
192 time_to_next = base::TimeDelta::FromMilliseconds( 196 time_to_next = base::TimeDelta::FromMilliseconds(
193 kSyncDelayFastInMilliseconds); 197 kSyncDelayFastInMilliseconds);
194 } 198 }
195 } 199 }
196 200
197 if (current_delay_ != delay) { 201 if (current_delay_ != delay) {
198 util::Log(logging::LOG_VERBOSE, FROM_HERE, 202 util::Log(logging::LOG_VERBOSE, FROM_HERE,
199 "[%s] Scheduling task in %" PRId64 " secs", 203 "[%s] Scheduling task in %" PRId64 " secs",
200 name_.c_str(), time_to_next.InSeconds()); 204 name_.c_str(), time_to_next.InSeconds());
201 } 205 }
202 current_delay_ = delay; 206 current_delay_ = delay;
203 207
204 timer_helper_->Start( 208 timer_helper_->Start(
205 FROM_HERE, time_to_next, 209 FROM_HERE, time_to_next,
206 base::Bind(&SyncProcessRunner::Run, base::Unretained(this))); 210 base::Bind(&SyncProcessRunner::Run, base::Unretained(this)));
207 } 211 }
208 212
209 } // namespace sync_file_system 213 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/sync_process_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698