task_dependency_manager.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 std::string app_id; 22 std::vector<base::FilePath> paths; 23 std::vector<std::string> file_ids; 24 std::vector<int64> tracker_ids; 25 26 BlockingFactor(); 27 ~BlockingFactor(); 28}; 29 30// This class manages dependency of the background tasks. 31class TaskDependencyManager { 32 public: 33 TaskDependencyManager(); 34 ~TaskDependencyManager(); 35 36 // Inserts |blocking_factor| to the collection and returns true if it 37 // completes successfully. Returns false and doesn't modify the collection 38 // if |blocking_factor| conflicts other |blocking_factor| that is inserted 39 // before. 40 // Two |blocking_factor| are handled as conflict if: 41 // - They have common |file_id| or |tracker_id|. 42 // - Or, they have the same |app_id| and have a |path| that one of its parent 43 // belongs to the |blocking_factor|. 44 bool Insert(const BlockingFactor& blocking_factor); 45 46 void Erase(const BlockingFactor& blocking_factor); 47 48 private: 49 friend class TaskDependencyManagerTest; 50 51 std::map<std::string, SubtreeSet> paths_by_app_id_; 52 std::set<std::string> file_ids_; 53 std::set<int64> tracker_ids_; 54 55 DISALLOW_COPY_AND_ASSIGN(TaskDependencyManager); 56}; 57 58} // namespace drive_backend 59} // namespace sync_file_system 60 61#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_ 62