| 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 "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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void SyncProcessRunner::ResetOldThrottling() { | 138 void SyncProcessRunner::ResetOldThrottling() { |
| 139 if (throttle_until_ < base::TimeTicks::Now()) | 139 if (throttle_until_ < base::TimeTicks::Now()) |
| 140 ResetThrottling(); | 140 ResetThrottling(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SyncProcessRunner::ResetThrottling() { | 143 void SyncProcessRunner::ResetThrottling() { |
| 144 throttle_from_ = base::TimeTicks(); | 144 throttle_from_ = base::TimeTicks(); |
| 145 throttle_until_ = base::TimeTicks(); | 145 throttle_until_ = base::TimeTicks(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 SyncServiceState SyncProcessRunner::GetServiceState() { |
| 149 return client_->GetSyncServiceState(); |
| 150 } |
| 151 |
| 148 void SyncProcessRunner::OnChangesUpdated( | 152 void SyncProcessRunner::OnChangesUpdated( |
| 149 int64 pending_changes) { | 153 int64 pending_changes) { |
| 150 DCHECK_GE(pending_changes, 0); | 154 DCHECK_GE(pending_changes, 0); |
| 151 int64 old_pending_changes = pending_changes_; | 155 int64 old_pending_changes = pending_changes_; |
| 152 pending_changes_ = pending_changes; | 156 pending_changes_ = pending_changes; |
| 153 if (old_pending_changes != pending_changes) { | 157 if (old_pending_changes != pending_changes) { |
| 154 if (pending_changes == 0) | 158 CheckIfIdle(); |
| 155 client_->OnSyncIdle(); | |
| 156 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 159 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
| 157 "[%s] pending_changes updated: %" PRId64, | 160 "[%s] pending_changes updated: %" PRId64, |
| 158 name_.c_str(), pending_changes); | 161 name_.c_str(), pending_changes); |
| 159 } | 162 } |
| 160 Schedule(); | 163 Schedule(); |
| 161 } | 164 } |
| 162 | 165 |
| 163 SyncFileSystemService* SyncProcessRunner::GetSyncService() { | 166 SyncFileSystemService* SyncProcessRunner::GetSyncService() { |
| 164 return client_->GetSyncService(); | 167 return client_->GetSyncService(); |
| 165 } | 168 } |
| 166 | 169 |
| 167 SyncServiceState SyncProcessRunner::GetServiceState() { | |
| 168 return client_->GetSyncServiceState(); | |
| 169 } | |
| 170 | |
| 171 void SyncProcessRunner::Finished(const base::TimeTicks& start_time, | 170 void SyncProcessRunner::Finished(const base::TimeTicks& start_time, |
| 172 SyncStatusCode status) { | 171 SyncStatusCode status) { |
| 173 DCHECK_LT(0u, running_tasks_); | 172 DCHECK_LT(0u, running_tasks_); |
| 174 DCHECK_LE(running_tasks_, max_parallel_task_); | 173 DCHECK_LE(running_tasks_, max_parallel_task_); |
| 175 --running_tasks_; | 174 --running_tasks_; |
| 175 CheckIfIdle(); |
| 176 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 176 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
| 177 "[%s] * Finished (elapsed: %" PRId64 " ms)", name_.c_str(), | 177 "[%s] * Finished (elapsed: %" PRId64 " ms)", name_.c_str(), |
| 178 (timer_helper_->Now() - start_time).InMilliseconds()); | 178 (timer_helper_->Now() - start_time).InMilliseconds()); |
| 179 | 179 |
| 180 if (status == SYNC_STATUS_NO_CHANGE_TO_SYNC || | 180 if (status == SYNC_STATUS_NO_CHANGE_TO_SYNC || |
| 181 status == SYNC_STATUS_FILE_BUSY) { | 181 status == SYNC_STATUS_FILE_BUSY) { |
| 182 ScheduleInternal(kSyncDelayMaxInMilliseconds); | 182 ScheduleInternal(kSyncDelayMaxInMilliseconds); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 "[%s] Scheduling task in %" PRId64 " ms", | 231 "[%s] Scheduling task in %" PRId64 " ms", |
| 232 name_.c_str(), (next_scheduled - now).InMilliseconds()); | 232 name_.c_str(), (next_scheduled - now).InMilliseconds()); |
| 233 | 233 |
| 234 last_scheduled_ = next_scheduled; | 234 last_scheduled_ = next_scheduled; |
| 235 | 235 |
| 236 timer_helper_->Start( | 236 timer_helper_->Start( |
| 237 FROM_HERE, next_scheduled - now, | 237 FROM_HERE, next_scheduled - now, |
| 238 base::Bind(&SyncProcessRunner::Run, base::Unretained(this))); | 238 base::Bind(&SyncProcessRunner::Run, base::Unretained(this))); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void SyncProcessRunner::CheckIfIdle() { |
| 242 if (pending_changes_ == 0 && running_tasks_ == 0) |
| 243 client_->OnSyncIdle(); |
| 244 } |
| 245 |
| 241 } // namespace sync_file_system | 246 } // namespace sync_file_system |
| OLD | NEW |