| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | |
| 18 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" | 17 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" |
| 19 #include "storage/browser/fileapi/file_system_url.h" | 18 #include "storage/browser/fileapi/file_system_url.h" |
| 20 | 19 |
| 21 namespace storage { | 20 namespace storage { |
| 22 class FileSystemURL; | 21 class FileSystemURL; |
| 23 } | 22 } |
| 24 | 23 |
| 25 namespace sync_file_system { | 24 namespace sync_file_system { |
| 26 | 25 |
| 27 // This class must run only on IO thread. | 26 // This class must run only on IO thread. |
| 28 // Owned by LocalFileSyncContext. | 27 // Owned by LocalFileSyncContext. |
| 29 class SyncableFileOperationRunner | 28 class SyncableFileOperationRunner |
| 30 : public base::NonThreadSafe, | 29 : public base::SupportsWeakPtr<SyncableFileOperationRunner>, |
| 31 public base::SupportsWeakPtr<SyncableFileOperationRunner>, | |
| 32 public LocalFileSyncStatus::Observer { | 30 public LocalFileSyncStatus::Observer { |
| 33 public: | 31 public: |
| 34 // Represents an operation task (which usually wraps one FileSystemOperation). | 32 // Represents an operation task (which usually wraps one FileSystemOperation). |
| 35 class Task { | 33 class Task { |
| 36 public: | 34 public: |
| 37 Task() {} | 35 Task() {} |
| 38 virtual ~Task() {} | 36 virtual ~Task() {} |
| 39 | 37 |
| 40 // Only one of Run() or Cancel() is called. | 38 // Only one of Run() or Cancel() is called. |
| 41 virtual void Run() = 0; | 39 virtual void Run() = 0; |
| 42 virtual void Cancel() = 0; | 40 virtual void Cancel() = 0; |
| 43 | 41 |
| 44 protected: | 42 protected: |
| 45 // This is never called after Run() or Cancel() is called. | 43 // This is never called after Run() or Cancel() is called. |
| 46 virtual const std::vector<storage::FileSystemURL>& target_paths() const = 0; | 44 virtual const std::vector<storage::FileSystemURL>& target_paths() const = 0; |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 friend class SyncableFileOperationRunner; | 47 friend class SyncableFileOperationRunner; |
| 50 bool IsRunnable(LocalFileSyncStatus* status) const; | 48 bool IsRunnable(LocalFileSyncStatus* status) const; |
| 51 void Start(LocalFileSyncStatus* status); | 49 void Start(LocalFileSyncStatus* status); |
| 52 static void CancelAndDelete(Task* task); | |
| 53 | 50 |
| 54 DISALLOW_COPY_AND_ASSIGN(Task); | 51 DISALLOW_COPY_AND_ASSIGN(Task); |
| 55 }; | 52 }; |
| 56 | 53 |
| 57 SyncableFileOperationRunner(int64_t max_inflight_tasks, | 54 SyncableFileOperationRunner(int64_t max_inflight_tasks, |
| 58 LocalFileSyncStatus* sync_status); | 55 LocalFileSyncStatus* sync_status); |
| 59 ~SyncableFileOperationRunner() override; | 56 ~SyncableFileOperationRunner() override; |
| 60 | 57 |
| 61 // LocalFileSyncStatus::Observer overrides. | 58 // LocalFileSyncStatus::Observer overrides. |
| 62 void OnSyncEnabled(const storage::FileSystemURL& url) override; | 59 void OnSyncEnabled(const storage::FileSystemURL& url) override; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 84 return static_cast<int64_t>(pending_tasks_.size()); | 81 return static_cast<int64_t>(pending_tasks_.size()); |
| 85 } | 82 } |
| 86 | 83 |
| 87 int64_t num_inflight_tasks() const { return num_inflight_tasks_; } | 84 int64_t num_inflight_tasks() const { return num_inflight_tasks_; } |
| 88 | 85 |
| 89 private: | 86 private: |
| 90 // Returns true if we should start more tasks. | 87 // Returns true if we should start more tasks. |
| 91 bool ShouldStartMoreTasks() const; | 88 bool ShouldStartMoreTasks() const; |
| 92 | 89 |
| 93 // Keeps track of the writing/syncing status. Not owned. | 90 // Keeps track of the writing/syncing status. Not owned. |
| 94 LocalFileSyncStatus* sync_status_; | 91 LocalFileSyncStatus* const sync_status_; |
| 95 | 92 |
| 96 std::list<Task*> pending_tasks_; | 93 std::list<std::unique_ptr<Task>> pending_tasks_; |
| 97 | 94 |
| 98 const int64_t max_inflight_tasks_; | 95 const int64_t max_inflight_tasks_; |
| 99 int64_t num_inflight_tasks_; | 96 int64_t num_inflight_tasks_; |
| 100 | 97 |
| 101 DISALLOW_COPY_AND_ASSIGN(SyncableFileOperationRunner); | 98 DISALLOW_COPY_AND_ASSIGN(SyncableFileOperationRunner); |
| 102 }; | 99 }; |
| 103 | 100 |
| 104 } // namespace sync_file_system | 101 } // namespace sync_file_system |
| 105 | 102 |
| 106 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_
H_ | 103 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_OPERATION_RUNNER_
H_ |
| OLD | NEW |