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() {} | 62 BlockingFactor::BlockingFactor() : exclusive(false) {} |
63 BlockingFactor::~BlockingFactor() {} | 63 BlockingFactor::~BlockingFactor() {} |
64 | 64 |
65 TaskDependencyManager::TaskDependencyManager() {} | 65 TaskDependencyManager::TaskDependencyManager() |
| 66 : running_exclusive_task_(false) {} |
66 | 67 |
67 TaskDependencyManager::~TaskDependencyManager() { | 68 TaskDependencyManager::~TaskDependencyManager() { |
68 DCHECK(paths_by_app_id_.empty()); | 69 DCHECK(paths_by_app_id_.empty()); |
69 DCHECK(file_ids_.empty()); | 70 DCHECK(file_ids_.empty()); |
70 DCHECK(tracker_ids_.empty()); | 71 DCHECK(tracker_ids_.empty()); |
71 } | 72 } |
72 | 73 |
73 bool TaskDependencyManager::Insert(const BlockingFactor& blocking_factor) { | 74 bool TaskDependencyManager::Insert(const BlockingFactor& blocking_factor) { |
| 75 if (running_exclusive_task_) |
| 76 return false; |
| 77 |
| 78 if (blocking_factor.exclusive) { |
| 79 if (!tracker_ids_.empty() || |
| 80 !file_ids_.empty() || |
| 81 !paths_by_app_id_.empty()) |
| 82 return false; |
| 83 running_exclusive_task_ = true; |
| 84 return true; |
| 85 } |
| 86 |
74 if (!InsertAllOrNone(blocking_factor.tracker_ids, &tracker_ids_)) | 87 if (!InsertAllOrNone(blocking_factor.tracker_ids, &tracker_ids_)) |
75 goto fail_on_tracker_id_insertion; | 88 goto fail_on_tracker_id_insertion; |
76 | 89 |
77 if (!InsertAllOrNone(blocking_factor.file_ids, &file_ids_)) | 90 if (!InsertAllOrNone(blocking_factor.file_ids, &file_ids_)) |
78 goto fail_on_file_id_insertion; | 91 goto fail_on_file_id_insertion; |
79 | 92 |
80 if (!blocking_factor.app_id.empty() && | 93 if (!blocking_factor.app_id.empty() && |
81 !InsertPaths(blocking_factor.paths, | 94 !InsertPaths(blocking_factor.paths, |
82 &paths_by_app_id_[blocking_factor.app_id])) { | 95 &paths_by_app_id_[blocking_factor.app_id])) { |
83 if (paths_by_app_id_[blocking_factor.app_id].empty()) | 96 if (paths_by_app_id_[blocking_factor.app_id].empty()) |
84 paths_by_app_id_.erase(blocking_factor.app_id); | 97 paths_by_app_id_.erase(blocking_factor.app_id); |
85 goto fail_on_path_insertion; | 98 goto fail_on_path_insertion; |
86 } | 99 } |
87 | 100 |
88 return true; | 101 return true; |
89 | 102 |
90 fail_on_path_insertion: | 103 fail_on_path_insertion: |
91 EraseContainer(blocking_factor.file_ids, &file_ids_); | 104 EraseContainer(blocking_factor.file_ids, &file_ids_); |
92 fail_on_file_id_insertion: | 105 fail_on_file_id_insertion: |
93 EraseContainer(blocking_factor.tracker_ids, &tracker_ids_); | 106 EraseContainer(blocking_factor.tracker_ids, &tracker_ids_); |
94 fail_on_tracker_id_insertion: | 107 fail_on_tracker_id_insertion: |
95 | 108 |
96 return false; | 109 return false; |
97 } | 110 } |
98 | 111 |
99 void TaskDependencyManager::Erase(const BlockingFactor& blocking_factor) { | 112 void TaskDependencyManager::Erase(const BlockingFactor& blocking_factor) { |
| 113 if (blocking_factor.exclusive) { |
| 114 DCHECK(running_exclusive_task_); |
| 115 DCHECK(paths_by_app_id_.empty()); |
| 116 DCHECK(file_ids_.empty()); |
| 117 DCHECK(tracker_ids_.empty()); |
| 118 |
| 119 running_exclusive_task_ = false; |
| 120 return; |
| 121 } |
| 122 |
100 if (!blocking_factor.app_id.empty()) { | 123 if (!blocking_factor.app_id.empty()) { |
101 EraseContainer(blocking_factor.paths, | 124 EraseContainer(blocking_factor.paths, |
102 &paths_by_app_id_[blocking_factor.app_id]); | 125 &paths_by_app_id_[blocking_factor.app_id]); |
103 if (paths_by_app_id_[blocking_factor.app_id].empty()) | 126 if (paths_by_app_id_[blocking_factor.app_id].empty()) |
104 paths_by_app_id_.erase(blocking_factor.app_id); | 127 paths_by_app_id_.erase(blocking_factor.app_id); |
105 } | 128 } |
106 | 129 |
107 EraseContainer(blocking_factor.file_ids, &file_ids_); | 130 EraseContainer(blocking_factor.file_ids, &file_ids_); |
108 EraseContainer(blocking_factor.tracker_ids, &tracker_ids_); | 131 EraseContainer(blocking_factor.tracker_ids, &tracker_ids_); |
109 } | 132 } |
110 | 133 |
111 } // namespace drive_backend | 134 } // namespace drive_backend |
112 } // namespace sync_file_system | 135 } // namespace sync_file_system |
OLD | NEW |