task_dependency_manager.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 3// found in the LICENSE file. 4 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_ 7 8#include <map> 9#include <set> 10#include <string> 11#include <vector> 12 13#include "base/files/file_path.h" 14#include "base/memory/scoped_ptr.h" 15#include "chrome/browser/sync_file_system/subtree_set.h" 16 17namespace sync_file_system { 18namespace drive_backend { 19 20struct BlockingFactor { 21 bool exclusive; 22 std::string app_id; 23 std::vector<base::FilePath> paths; 24 std::vector<std::string> file_ids; 25 std::vector<int64> tracker_ids; 26 27 BlockingFactor(); 28 ~BlockingFactor(); 29}; 30 31// This class manages dependency of the background tasks. 32class TaskDependencyManager { 33 public: 34 TaskDependencyManager(); 35 ~TaskDependencyManager(); 36 37 // Inserts |blocking_factor| to the collection and returns true if it 38 // completes successfully. Returns false and doesn't modify the collection 39 // if |blocking_factor| conflicts other |blocking_factor| that is inserted 40 // before. 41 // Two |blocking_factor| are handled as conflict if: 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 44 // belongs to the |blocking_factor|. 45 bool Insert(const BlockingFactor& blocking_factor); 46 47 void Erase(const BlockingFactor& blocking_factor); 48 49 private: 50 friend class TaskDependencyManagerTest; 51 52 bool running_exclusive_task_; 53 std::map<std::string, SubtreeSet> paths_by_app_id_; 54 std::set<std::string> file_ids_; 55 std::set<int64> tracker_ids_; 56 57 DISALLOW_COPY_AND_ASSIGN(TaskDependencyManager); 58}; 59 60} // namespace drive_backend 61} // namespace sync_file_system 62 63#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ 64