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

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

Issue 11235027: Wire up Syncable operation runner to the local file sync context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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_LOCAL_FILE_SYNC_CONTEXT_H_ 5 #ifndef WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_
6 #define WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_ 6 #define WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback_forward.h" 13 #include "base/callback.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "webkit/fileapi/syncable/file_change.h" 20 #include "webkit/fileapi/syncable/file_change.h"
21 #include "webkit/fileapi/syncable/sync_status_code.h" 21 #include "webkit/fileapi/syncable/sync_status_code.h"
22 #include "webkit/storage/webkit_storage_export.h" 22 #include "webkit/storage/webkit_storage_export.h"
23 23
24 namespace base { 24 namespace base {
25 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
26 } 26 }
27 27
28 namespace fileapi { 28 namespace fileapi {
29 29
30 class FileSystemContext; 30 class FileSystemContext;
31 class LocalFileChangeTracker; 31 class LocalFileChangeTracker;
32 class SyncableFileOperationRunner; 32 class SyncableFileOperationRunner;
33 33
34 // This class works as a bridge between LocalFileSyncService (which is a 34 // This class works as a bridge between LocalFileSyncService (which is a
35 // per-profile object) and FileSystemContext's (which is a per-storage-partition 35 // per-profile object) and FileSystemContext's (which is a per-storage-partition
36 // object and may exist multiple in a profile). 36 // object and may exist multiple in a profile).
37 // An instance of this class is shared by FileSystemContexts and outlives 37 // An instance of this class is shared by FileSystemContexts and outlives
38 // LocalFileSyncService. 38 // LocalFileSyncService.
39 class WEBKIT_STORAGE_EXPORT LocalFileSyncContext 39 class WEBKIT_STORAGE_EXPORT LocalFileSyncContext
40 : public base::RefCountedThreadSafe<LocalFileSyncContext> { 40 : public base::RefCountedThreadSafe<LocalFileSyncContext>,
41 public LocalFileSyncStatus::Observer {
41 public: 42 public:
42 typedef base::Callback<void(SyncStatusCode status)> StatusCallback; 43 typedef base::Callback<void(SyncStatusCode status)> StatusCallback;
44 typedef base::Callback<void(const FileSystemURL& url)> URLCallback;
45 typedef base::Callback<void(
46 SyncStatusCode status,
47 const FileChangeList& change)> ChangeListCallback;
43 48
44 LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, 49 LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner,
45 base::SingleThreadTaskRunner* io_task_runner); 50 base::SingleThreadTaskRunner* io_task_runner);
46 51
47 // Initializes |file_system_context| for syncable file operations and 52 // Initializes |file_system_context| for syncable file operations and
48 // registers the it into the internal map. 53 // registers the it into the internal map.
49 // Calling this multiple times for the same file_system_context is valid. 54 // Calling this multiple times for the same file_system_context is valid.
50 // This method must be called on UI thread. 55 // This method must be called on UI thread.
51 void MaybeInitializeFileSystemContext(const GURL& source_url, 56 void MaybeInitializeFileSystemContext(const GURL& source_url,
52 FileSystemContext* file_system_context, 57 FileSystemContext* file_system_context,
53 const StatusCallback& callback); 58 const StatusCallback& callback);
54 59
55 // Called when the corresponding LocalFileSyncService exits. 60 // Called when the corresponding LocalFileSyncService exits.
56 // This method must be called on UI thread. 61 // This method must be called on UI thread.
57 void ShutdownOnUIThread(); 62 void ShutdownOnUIThread();
58 63
64 // Prepares for sync |url| by disabling writes on |url|.
65 // If the target |url| is being written and cannot start sync it
66 // returns SYNC_STATUS_WRITING status code via |callback|.
67 // Otherwise it disables writes, marks the |url| syncing and returns
68 // the current change set made on |url|.
69 // This method must be called on UI thread.
70 void PrepareForSync(const FileSystemURL& url,
71 const ChangeListCallback& callback);
72
73 // Registers |url| to wait until sync is enabled for |url|.
74 // |on_syncable_callback| is to be called when |url| becomes syncable
75 // (i.e. when we have no pending writes and the file is successfully locked
76 // for sync).
77 //
78 // It is NOT valid to call this method while this already has a URL waiting
79 // for sync.
80 //
81 // This method must be called on UI thread.
82 void RegisterURLForWaitingSync(const FileSystemURL& url,
83 const URLCallback& on_syncable_callback);
84
59 // OperationRunner is accessible only on IO thread. 85 // OperationRunner is accessible only on IO thread.
60 base::WeakPtr<SyncableFileOperationRunner> operation_runner() const; 86 base::WeakPtr<SyncableFileOperationRunner> operation_runner() const;
61 87
88 // SyncContext is accessible only on IO thread.
89 LocalFileSyncStatus* sync_status() const;
90
91 protected:
92 // LocalFileSyncStatus::Observer overrides. They are called on IO thread.
93 virtual void OnSyncEnabled(const FileSystemURL& url) OVERRIDE;
94 virtual void OnWriteEnabled(const FileSystemURL& url) OVERRIDE;
95
62 private: 96 private:
63 typedef std::deque<StatusCallback> StatusCallbackQueue; 97 typedef std::deque<StatusCallback> StatusCallbackQueue;
64 friend class base::RefCountedThreadSafe<LocalFileSyncContext>; 98 friend class base::RefCountedThreadSafe<LocalFileSyncContext>;
65 friend class CannedSyncableFileSystem; 99 friend class CannedSyncableFileSystem;
66 100
67 ~LocalFileSyncContext(); 101 ~LocalFileSyncContext();
tzik 2012/10/24 03:45:13 could you readd virtual?
kinuko 2012/10/24 09:39:56 Done.
kinuko 2012/10/24 14:07:05 (This is done by the other change)
68 102
69 void ShutdownOnIOThread(); 103 void ShutdownOnIOThread();
70 104
71 // Helper routines for MaybeInitializeFileSystemContext. 105 // Helper routines for MaybeInitializeFileSystemContext.
72 void InitializeFileSystemContextOnIOThread( 106 void InitializeFileSystemContextOnIOThread(
73 const GURL& source_url, 107 const GURL& source_url,
74 FileSystemContext* file_system_context); 108 FileSystemContext* file_system_context);
75 SyncStatusCode InitializeChangeTrackerOnFileThread( 109 SyncStatusCode InitializeChangeTrackerOnFileThread(
76 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, 110 scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
77 FileSystemContext* file_system_context); 111 FileSystemContext* file_system_context);
78 void DidInitializeChangeTracker( 112 void DidInitializeChangeTracker(
79 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, 113 scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
80 const GURL& source_url, 114 const GURL& source_url,
81 FileSystemContext* file_system_context, 115 FileSystemContext* file_system_context,
82 SyncStatusCode status); 116 SyncStatusCode status);
83 void DidInitialize( 117 void DidInitialize(
84 const GURL& source_url, 118 const GURL& source_url,
85 FileSystemContext* file_system_context, 119 FileSystemContext* file_system_context,
86 SyncStatusCode status); 120 SyncStatusCode status);
87 121
122 // Helper routines for PrepareForSync.
123 void DidDisabledWritesForPrepareForSync(
124 const FileSystemURL& url,
125 const ChangeListCallback& callback);
126
88 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 127 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
89 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 128 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
90 129
130 // Indicates if the sync service is shutdown on UI thread.
131 bool shutdown_on_ui_;
132
91 // OperationRunner. This must be accessed only on IO thread. 133 // OperationRunner. This must be accessed only on IO thread.
92 scoped_ptr<SyncableFileOperationRunner> operation_runner_; 134 scoped_ptr<SyncableFileOperationRunner> operation_runner_;
93 135
94 // Pointers to file system contexts that have been initialized for 136 // Pointers to file system contexts that have been initialized for
95 // synchronization (i.e. that own this instance). 137 // synchronization (i.e. that own this instance).
96 // This must be accessed only on UI thread. 138 // This must be accessed only on UI thread.
97 std::set<FileSystemContext*> file_system_contexts_; 139 std::set<FileSystemContext*> file_system_contexts_;
98 140
99 std::map<FileSystemContext*, StatusCallbackQueue> 141 std::map<FileSystemContext*, StatusCallbackQueue>
100 pending_initialize_callbacks_; 142 pending_initialize_callbacks_;
101 143
102 // Origin to context map. (Assuming that as far as we're in the same 144 // Origin to context map. (Assuming that as far as we're in the same
103 // profile single origin wouldn't belong to multiple FileSystemContexts.) 145 // profile single origin wouldn't belong to multiple FileSystemContexts.)
104 std::map<GURL, FileSystemContext*> origin_to_contexts_; 146 std::map<GURL, FileSystemContext*> origin_to_contexts_;
105 147
148 // A URL and associated callback waiting for sync is enabled.
149 // Accessed only on IO thread.
150 FileSystemURL url_waiting_sync_on_io_;
151 URLCallback url_syncable_callback_;
152
106 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); 153 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext);
107 }; 154 };
108 155
109 } // namespace fileapi 156 } // namespace fileapi
110 157
111 #endif // WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_ 158 #endif // WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/fileapi/syncable/local_file_sync_context.cc » ('j') | webkit/fileapi/syncable/local_file_sync_context.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698