Home | History | Annotate | Download | only in drive_backend
      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 
     17 namespace sync_file_system {
     18 namespace drive_backend {
     19 
     20 struct 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.
     32 class 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   int running_task_count_;
     53   bool running_exclusive_task_;
     54   std::map<std::string, SubtreeSet> paths_by_app_id_;
     55   std::set<std::string> file_ids_;
     56   std::set<int64> tracker_ids_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(TaskDependencyManager);
     59 };
     60 
     61 }  // namespace drive_backend
     62 }  // namespace sync_file_system
     63 
     64 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_TASK_DEPENDENCY_MANAGER_H_
     65