Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: webkit/fileapi/syncable/syncable_file_operation_runner.h

Issue 11238054: Add OnSyncEnabled/OnWriteEnabled notification handling to operation runner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added export Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_ 5 #ifndef WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_
6 #define WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_ 6 #define WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "webkit/fileapi/file_system_url.h" 16 #include "webkit/fileapi/file_system_url.h"
17 #include "webkit/fileapi/syncable/local_file_sync_status.h"
17 #include "webkit/storage/webkit_storage_export.h" 18 #include "webkit/storage/webkit_storage_export.h"
18 19
19 namespace fileapi { 20 namespace fileapi {
20 21
21 class FileSystemURL; 22 class FileSystemURL;
22 class LocalFileSyncStatus;
23 23
24 // This class must run only on IO thread. 24 // This class must run only on IO thread.
25 // Owned by LocalFileSyncContext. 25 // Owned by LocalFileSyncContext.
26 class WEBKIT_STORAGE_EXPORT SyncableFileOperationRunner 26 class WEBKIT_STORAGE_EXPORT SyncableFileOperationRunner
27 : public base::NonThreadSafe, 27 : public base::NonThreadSafe,
28 public base::SupportsWeakPtr<SyncableFileOperationRunner> { 28 public base::SupportsWeakPtr<SyncableFileOperationRunner>,
29 public LocalFileSyncStatus::Observer {
29 public: 30 public:
30 // Represents an operation task (which usually wraps one FileSystemOperation). 31 // Represents an operation task (which usually wraps one FileSystemOperation).
31 class Task { 32 class Task {
32 public: 33 public:
33 Task() {} 34 Task() {}
34 virtual ~Task() {} 35 virtual ~Task() {}
35 36
36 // Only one of Run() or Cancel() is called. 37 // Only one of Run() or Cancel() is called.
37 virtual void Run() = 0; 38 virtual void Run() = 0;
38 virtual void Cancel() = 0; 39 virtual void Cancel() = 0;
39 40
40 protected: 41 protected:
41 // This is never called after Run() or Cancel() is called. 42 // This is never called after Run() or Cancel() is called.
42 virtual const std::vector<FileSystemURL>& target_paths() const = 0; 43 virtual const std::vector<FileSystemURL>& target_paths() const = 0;
43 44
44 private: 45 private:
45 friend class SyncableFileOperationRunner; 46 friend class SyncableFileOperationRunner;
46 bool IsRunnable(LocalFileSyncStatus* status) const; 47 bool IsRunnable(LocalFileSyncStatus* status) const;
47 void Start(LocalFileSyncStatus* status); 48 void Start(LocalFileSyncStatus* status);
48 static void CancelAndDelete(Task* task); 49 static void CancelAndDelete(Task* task);
49 50
50 DISALLOW_COPY_AND_ASSIGN(Task); 51 DISALLOW_COPY_AND_ASSIGN(Task);
51 }; 52 };
52 53
53 SyncableFileOperationRunner(); 54 SyncableFileOperationRunner(int64 max_inflight_tasks,
54 ~SyncableFileOperationRunner(); 55 LocalFileSyncStatus* sync_status);
56 virtual ~SyncableFileOperationRunner();
57
58 // LocalFileSyncStatus::Observer overrides.
59 virtual void OnSyncEnabled(const FileSystemURL& url) OVERRIDE;
60 virtual void OnWriteEnabled(const FileSystemURL& url) OVERRIDE;
55 61
56 // Runs the given |task| if no sync operation is running on any of 62 // Runs the given |task| if no sync operation is running on any of
57 // its target_paths(). This also runs pending operations that have become 63 // its target_paths(). This also runs pending tasks that have become
58 // runnable (before running the given operation). 64 // runnable (before running the given operation).
59 // If there're ongoing sync operations on the target_paths this method 65 // If there're ongoing sync tasks on the target_paths this method
60 // just queues up the |task|. 66 // just queues up the |task|.
61 // Pending operations are cancelled when this class is destructed. 67 // Pending tasks are cancelled when this class is destructed.
62 void PostOperationTask(scoped_ptr<Task> task); 68 void PostOperationTask(scoped_ptr<Task> task);
63 69
64 // Runs a next runnable task (if there's any). 70 // Runs a next runnable task (if there's any).
65 void RunNextRunnableTask(); 71 void RunNextRunnableTask();
66 72
67 // Called when an operation is completed. This will make |target_paths| 73 // Called when an operation is completed. This will make |target_paths|
68 // writable and may start a next runnable task. 74 // writable and may start a next runnable task.
69 void OnOperationCompleted(const std::vector<FileSystemURL>& target_paths); 75 void OnOperationCompleted(const std::vector<FileSystemURL>& target_paths);
70 76
71 // For syncable file systems. 77 LocalFileSyncStatus* sync_status() const { return sync_status_; }
72 LocalFileSyncStatus* sync_status() const { return sync_status_.get(); } 78
79 int64 num_pending_tasks() const {
80 return static_cast<int64>(pending_tasks_.size());
81 }
82
83 int64 num_inflight_tasks() const { return num_inflight_tasks_; }
73 84
74 private: 85 private:
75 // Keeps track of the writing/syncing status. 86 // Returns true if we should start more tasks.
76 scoped_ptr<LocalFileSyncStatus> sync_status_; 87 bool ShouldStartMoreTasks() const;
77 88
78 std::list<Task*> pending_operations_; 89 // Keeps track of the writing/syncing status. Not owned.
90 LocalFileSyncStatus* sync_status_;
91
92 std::list<Task*> pending_tasks_;
93
94 const int64 max_inflight_tasks_;
95 int64 num_inflight_tasks_;
79 96
80 DISALLOW_COPY_AND_ASSIGN(SyncableFileOperationRunner); 97 DISALLOW_COPY_AND_ASSIGN(SyncableFileOperationRunner);
81 }; 98 };
82 99
83 } // namespace fileapi 100 } // namespace fileapi
84 101
85 #endif // WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_ 102 #endif // WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_FILE_OPERATION_RUNNER_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/local_file_sync_status.cc ('k') | webkit/fileapi/syncable/syncable_file_operation_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698