| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/drive_backend/task_dependency_manager.
h" | 5 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 for (itr = paths_to_insert.begin(); itr != end; ++itr) | 52 for (itr = paths_to_insert.begin(); itr != end; ++itr) |
| 53 paths->erase(*itr); | 53 paths->erase(*itr); |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 BlockingFactor::BlockingFactor() : exclusive(false) {} | 62 TaskBlocker::TaskBlocker() : exclusive(false) {} |
| 63 BlockingFactor::~BlockingFactor() {} | 63 TaskBlocker::~TaskBlocker() {} |
| 64 | 64 |
| 65 TaskDependencyManager::TaskDependencyManager() | 65 TaskDependencyManager::TaskDependencyManager() |
| 66 : running_task_count_(0), | 66 : running_task_count_(0), |
| 67 running_exclusive_task_(false) {} | 67 running_exclusive_task_(false) {} |
| 68 | 68 |
| 69 TaskDependencyManager::~TaskDependencyManager() { | 69 TaskDependencyManager::~TaskDependencyManager() { |
| 70 DCHECK(paths_by_app_id_.empty()); | 70 DCHECK(paths_by_app_id_.empty()); |
| 71 DCHECK(file_ids_.empty()); | 71 DCHECK(file_ids_.empty()); |
| 72 DCHECK(tracker_ids_.empty()); | 72 DCHECK(tracker_ids_.empty()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool TaskDependencyManager::Insert(const BlockingFactor* blocking_factor) { | 75 bool TaskDependencyManager::Insert(const TaskBlocker* task_blocker) { |
| 76 if (running_exclusive_task_) | 76 if (running_exclusive_task_) |
| 77 return false; | 77 return false; |
| 78 | 78 |
| 79 if (!blocking_factor) { | 79 if (!task_blocker) { |
| 80 ++running_task_count_; | 80 ++running_task_count_; |
| 81 return true; | 81 return true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (blocking_factor->exclusive) { | 84 if (task_blocker->exclusive) { |
| 85 if (running_task_count_ || | 85 if (running_task_count_ || |
| 86 !tracker_ids_.empty() || | 86 !tracker_ids_.empty() || |
| 87 !file_ids_.empty() || | 87 !file_ids_.empty() || |
| 88 !paths_by_app_id_.empty()) | 88 !paths_by_app_id_.empty()) |
| 89 return false; | 89 return false; |
| 90 ++running_task_count_; | 90 ++running_task_count_; |
| 91 running_exclusive_task_ = true; | 91 running_exclusive_task_ = true; |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 if (!InsertAllOrNone(blocking_factor->tracker_ids, &tracker_ids_)) | 95 if (!InsertAllOrNone(task_blocker->tracker_ids, &tracker_ids_)) |
| 96 goto fail_on_tracker_id_insertion; | 96 goto fail_on_tracker_id_insertion; |
| 97 | 97 |
| 98 if (!InsertAllOrNone(blocking_factor->file_ids, &file_ids_)) | 98 if (!InsertAllOrNone(task_blocker->file_ids, &file_ids_)) |
| 99 goto fail_on_file_id_insertion; | 99 goto fail_on_file_id_insertion; |
| 100 | 100 |
| 101 if (!blocking_factor->app_id.empty() && | 101 if (!task_blocker->app_id.empty() && |
| 102 !InsertPaths(blocking_factor->paths, | 102 !InsertPaths(task_blocker->paths, |
| 103 &paths_by_app_id_[blocking_factor->app_id])) { | 103 &paths_by_app_id_[task_blocker->app_id])) { |
| 104 if (paths_by_app_id_[blocking_factor->app_id].empty()) | 104 if (paths_by_app_id_[task_blocker->app_id].empty()) |
| 105 paths_by_app_id_.erase(blocking_factor->app_id); | 105 paths_by_app_id_.erase(task_blocker->app_id); |
| 106 goto fail_on_path_insertion; | 106 goto fail_on_path_insertion; |
| 107 } | 107 } |
| 108 | 108 |
| 109 ++running_task_count_; | 109 ++running_task_count_; |
| 110 return true; | 110 return true; |
| 111 | 111 |
| 112 fail_on_path_insertion: | 112 fail_on_path_insertion: |
| 113 EraseContainer(blocking_factor->file_ids, &file_ids_); | 113 EraseContainer(task_blocker->file_ids, &file_ids_); |
| 114 fail_on_file_id_insertion: | 114 fail_on_file_id_insertion: |
| 115 EraseContainer(blocking_factor->tracker_ids, &tracker_ids_); | 115 EraseContainer(task_blocker->tracker_ids, &tracker_ids_); |
| 116 fail_on_tracker_id_insertion: | 116 fail_on_tracker_id_insertion: |
| 117 | 117 |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void TaskDependencyManager::Erase(const BlockingFactor* blocking_factor) { | 121 void TaskDependencyManager::Erase(const TaskBlocker* task_blocker) { |
| 122 --running_task_count_; | 122 --running_task_count_; |
| 123 DCHECK_LE(0, running_task_count_); | 123 DCHECK_LE(0, running_task_count_); |
| 124 if (!blocking_factor) | 124 if (!task_blocker) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 if (blocking_factor->exclusive) { | 127 if (task_blocker->exclusive) { |
| 128 DCHECK(running_exclusive_task_); | 128 DCHECK(running_exclusive_task_); |
| 129 DCHECK(paths_by_app_id_.empty()); | 129 DCHECK(paths_by_app_id_.empty()); |
| 130 DCHECK(file_ids_.empty()); | 130 DCHECK(file_ids_.empty()); |
| 131 DCHECK(tracker_ids_.empty()); | 131 DCHECK(tracker_ids_.empty()); |
| 132 DCHECK_EQ(0, running_task_count_); | 132 DCHECK_EQ(0, running_task_count_); |
| 133 | 133 |
| 134 running_exclusive_task_ = false; | 134 running_exclusive_task_ = false; |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 if (!blocking_factor->app_id.empty()) { | 138 if (!task_blocker->app_id.empty()) { |
| 139 EraseContainer(blocking_factor->paths, | 139 EraseContainer(task_blocker->paths, |
| 140 &paths_by_app_id_[blocking_factor->app_id]); | 140 &paths_by_app_id_[task_blocker->app_id]); |
| 141 if (paths_by_app_id_[blocking_factor->app_id].empty()) | 141 if (paths_by_app_id_[task_blocker->app_id].empty()) |
| 142 paths_by_app_id_.erase(blocking_factor->app_id); | 142 paths_by_app_id_.erase(task_blocker->app_id); |
| 143 } | 143 } |
| 144 | 144 |
| 145 EraseContainer(blocking_factor->file_ids, &file_ids_); | 145 EraseContainer(task_blocker->file_ids, &file_ids_); |
| 146 EraseContainer(blocking_factor->tracker_ids, &tracker_ids_); | 146 EraseContainer(task_blocker->tracker_ids, &tracker_ids_); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace drive_backend | 149 } // namespace drive_backend |
| 150 } // namespace sync_file_system | 150 } // namespace sync_file_system |
| OLD | NEW |