| 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "chrome/browser/sync_file_system/subtree_set.h" | 15 #include "chrome/browser/sync_file_system/subtree_set.h" |
| 16 | 16 |
| 17 namespace sync_file_system { | 17 namespace sync_file_system { |
| 18 namespace drive_backend { | 18 namespace drive_backend { |
| 19 | 19 |
| 20 struct BlockingFactor { | 20 struct TaskBlocker { |
| 21 bool exclusive; | 21 bool exclusive; |
| 22 std::string app_id; | 22 std::string app_id; |
| 23 std::vector<base::FilePath> paths; | 23 std::vector<base::FilePath> paths; |
| 24 std::vector<std::string> file_ids; | 24 std::vector<std::string> file_ids; |
| 25 std::vector<int64> tracker_ids; | 25 std::vector<int64> tracker_ids; |
| 26 | 26 |
| 27 BlockingFactor(); | 27 TaskBlocker(); |
| 28 ~BlockingFactor(); | 28 ~TaskBlocker(); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // This class manages dependency of the background tasks. | 31 // This class manages dependency of the background tasks. |
| 32 class TaskDependencyManager { | 32 class TaskDependencyManager { |
| 33 public: | 33 public: |
| 34 TaskDependencyManager(); | 34 TaskDependencyManager(); |
| 35 ~TaskDependencyManager(); | 35 ~TaskDependencyManager(); |
| 36 | 36 |
| 37 // Inserts |blocking_factor| to the collection and returns true if it | 37 // Inserts |task_blocker| to the collection and returns true if it |
| 38 // completes successfully. Returns false and doesn't modify the collection | 38 // completes successfully. Returns false and doesn't modify the collection |
| 39 // if |blocking_factor| conflicts other |blocking_factor| that is inserted | 39 // if |task_blocker| conflicts other |task_blocker| that is inserted |
| 40 // before. | 40 // before. |
| 41 // Two |blocking_factor| are handled as conflict if: | 41 // Two |task_blocker| are handled as conflict if: |
| 42 // - They have common |file_id| or |tracker_id|. | 42 // - They have common |file_id| or |tracker_id|. |
| 43 // - Or, they have the same |app_id| and have a |path| that one of its parent | 43 // - Or, they have the same |app_id| and have a |path| that one of its parent |
| 44 // belongs to the |blocking_factor|. | 44 // belongs to the |task_blocker|. |
| 45 bool Insert(const BlockingFactor* blocking_factor); | 45 bool Insert(const TaskBlocker* task_blocker); |
| 46 | 46 |
| 47 void Erase(const BlockingFactor* blocking_factor); | 47 void Erase(const TaskBlocker* task_blocker); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class TaskDependencyManagerTest; | 50 friend class TaskDependencyManagerTest; |
| 51 | 51 |
| 52 int running_task_count_; | 52 int running_task_count_; |
| 53 bool running_exclusive_task_; | 53 bool running_exclusive_task_; |
| 54 std::map<std::string, SubtreeSet> paths_by_app_id_; | 54 std::map<std::string, SubtreeSet> paths_by_app_id_; |
| 55 std::set<std::string> file_ids_; | 55 std::set<std::string> file_ids_; |
| 56 std::set<int64> tracker_ids_; | 56 std::set<int64> tracker_ids_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(TaskDependencyManager); | 58 DISALLOW_COPY_AND_ASSIGN(TaskDependencyManager); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 } // namespace drive_backend | 61 } // namespace drive_backend |
| 62 } // namespace sync_file_system | 62 } // namespace sync_file_system |
| 63 | 63 |
| 64 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER
_H_ | 64 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER
_H_ |
| OLD | NEW |