| 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/local/syncable_file_operation_runner.h
" | 5 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SyncableFileOperationRunner::OnSyncEnabled(const FileSystemURL& url) { | 63 void SyncableFileOperationRunner::OnSyncEnabled(const FileSystemURL& url) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void SyncableFileOperationRunner::OnWriteEnabled(const FileSystemURL& url) { | 66 void SyncableFileOperationRunner::OnWriteEnabled(const FileSystemURL& url) { |
| 67 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 68 RunNextRunnableTask(); | 68 RunNextRunnableTask(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SyncableFileOperationRunner::PostOperationTask(scoped_ptr<Task> task) { | 71 void SyncableFileOperationRunner::PostOperationTask( |
| 72 std::unique_ptr<Task> task) { |
| 72 DCHECK(CalledOnValidThread()); | 73 DCHECK(CalledOnValidThread()); |
| 73 pending_tasks_.push_back(task.release()); | 74 pending_tasks_.push_back(task.release()); |
| 74 RunNextRunnableTask(); | 75 RunNextRunnableTask(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void SyncableFileOperationRunner::RunNextRunnableTask() { | 78 void SyncableFileOperationRunner::RunNextRunnableTask() { |
| 78 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
| 79 for (std::list<Task*>::iterator iter = pending_tasks_.begin(); | 80 for (std::list<Task*>::iterator iter = pending_tasks_.begin(); |
| 80 iter != pending_tasks_.end() && ShouldStartMoreTasks();) { | 81 iter != pending_tasks_.end() && ShouldStartMoreTasks();) { |
| 81 if ((*iter)->IsRunnable(sync_status())) { | 82 if ((*iter)->IsRunnable(sync_status())) { |
| 82 ++num_inflight_tasks_; | 83 ++num_inflight_tasks_; |
| 83 DCHECK_GE(num_inflight_tasks_, 1); | 84 DCHECK_GE(num_inflight_tasks_, 1); |
| 84 scoped_ptr<Task> task(*iter); | 85 std::unique_ptr<Task> task(*iter); |
| 85 pending_tasks_.erase(iter++); | 86 pending_tasks_.erase(iter++); |
| 86 task->Start(sync_status()); | 87 task->Start(sync_status()); |
| 87 continue; | 88 continue; |
| 88 } | 89 } |
| 89 ++iter; | 90 ++iter; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 void SyncableFileOperationRunner::OnOperationCompleted( | 94 void SyncableFileOperationRunner::OnOperationCompleted( |
| 94 const std::vector<FileSystemURL>& target_paths) { | 95 const std::vector<FileSystemURL>& target_paths) { |
| 95 --num_inflight_tasks_; | 96 --num_inflight_tasks_; |
| 96 DCHECK_GE(num_inflight_tasks_, 0); | 97 DCHECK_GE(num_inflight_tasks_, 0); |
| 97 for (size_t i = 0; i < target_paths.size(); ++i) { | 98 for (size_t i = 0; i < target_paths.size(); ++i) { |
| 98 DCHECK(sync_status()->IsWriting(target_paths[i])); | 99 DCHECK(sync_status()->IsWriting(target_paths[i])); |
| 99 sync_status()->EndWriting(target_paths[i]); | 100 sync_status()->EndWriting(target_paths[i]); |
| 100 } | 101 } |
| 101 RunNextRunnableTask(); | 102 RunNextRunnableTask(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool SyncableFileOperationRunner::ShouldStartMoreTasks() const { | 105 bool SyncableFileOperationRunner::ShouldStartMoreTasks() const { |
| 105 return num_inflight_tasks_ < max_inflight_tasks_; | 106 return num_inflight_tasks_ < max_inflight_tasks_; |
| 106 } | 107 } |
| 107 | 108 |
| 108 } // namespace sync_file_system | 109 } // namespace sync_file_system |
| OLD | NEW |