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_SYNC_TASK_TOKEN_H_
      6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/location.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "chrome/browser/sync_file_system/sync_callbacks.h"
     13 #include "chrome/browser/sync_file_system/task_logger.h"
     14 
     15 namespace sync_file_system {
     16 namespace drive_backend {
     17 
     18 class SyncTaskManager;
     19 struct BlockingFactor;
     20 
     21 // Represents a running sequence of SyncTasks.  Owned by a callback chain that
     22 // should run exclusively, and held by SyncTaskManager when no task is running.
     23 class SyncTaskToken {
     24  public:
     25   static const int64 kTestingTaskTokenID;
     26   static const int64 kForegroundTaskTokenID;
     27   static const int64 kMinimumBackgroundTaskTokenID;
     28 
     29   static scoped_ptr<SyncTaskToken> CreateForTesting(
     30       const SyncStatusCallback& callback);
     31   static scoped_ptr<SyncTaskToken> CreateForForegroundTask(
     32       const base::WeakPtr<SyncTaskManager>& manager);
     33   static scoped_ptr<SyncTaskToken> CreateForBackgroundTask(
     34       const base::WeakPtr<SyncTaskManager>& manager,
     35       int64 token_id,
     36       scoped_ptr<BlockingFactor> blocking_factor);
     37 
     38   void UpdateTask(const tracked_objects::Location& location,
     39                   const SyncStatusCallback& callback);
     40 
     41   const tracked_objects::Location& location() const { return location_; }
     42   virtual ~SyncTaskToken();
     43 
     44   static SyncStatusCallback WrapToCallback(scoped_ptr<SyncTaskToken> token);
     45 
     46   SyncTaskManager* manager() { return manager_.get(); }
     47 
     48   const SyncStatusCallback& callback() const { return callback_; }
     49   void clear_callback() { callback_.Reset(); }
     50 
     51   void set_blocking_factor(scoped_ptr<BlockingFactor> blocking_factor);
     52   const BlockingFactor* blocking_factor() const;
     53   void clear_blocking_factor();
     54 
     55   int64 token_id() const { return token_id_; }
     56 
     57   void InitializeTaskLog(const std::string& task_description);
     58   void FinalizeTaskLog(const std::string& result_description);
     59   void RecordLog(const std::string& message);
     60 
     61   bool has_task_log() const { return task_log_; }
     62   void SetTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log);
     63   scoped_ptr<TaskLogger::TaskLog> PassTaskLog();
     64 
     65  private:
     66   SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager,
     67                 int64 token_id,
     68                 scoped_ptr<BlockingFactor> blocking_factor,
     69                 const SyncStatusCallback& callback);
     70 
     71   base::WeakPtr<SyncTaskManager> manager_;
     72   tracked_objects::Location location_;
     73   int64 token_id_;
     74   SyncStatusCallback callback_;
     75 
     76   scoped_ptr<TaskLogger::TaskLog> task_log_;
     77   scoped_ptr<BlockingFactor> blocking_factor_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(SyncTaskToken);
     80 };
     81 
     82 }  // namespace drive_backend
     83 }  // namespace sync_file_system
     84 
     85 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_
     86