Index: webkit/fileapi/syncable/local_file_sync_context.h |
diff --git a/webkit/fileapi/syncable/local_file_sync_context.h b/webkit/fileapi/syncable/local_file_sync_context.h |
index 74b4a90fe04e57c2a1dfa1d2b202c1a0073b893f..7b680730c74e642f91973fd28fffb77b155521f3 100644 |
--- a/webkit/fileapi/syncable/local_file_sync_context.h |
+++ b/webkit/fileapi/syncable/local_file_sync_context.h |
@@ -10,7 +10,7 @@ |
#include <set> |
#include "base/basictypes.h" |
-#include "base/callback_forward.h" |
+#include "base/callback.h" |
#include "base/file_path.h" |
#include "base/logging.h" |
#include "base/memory/ref_counted.h" |
@@ -39,9 +39,14 @@ class SyncableFileOperationRunner; |
// An instance of this class is shared by FileSystemContexts and outlives |
// LocalFileSyncService. |
class WEBKIT_STORAGE_EXPORT LocalFileSyncContext |
- : public base::RefCountedThreadSafe<LocalFileSyncContext> { |
+ : public base::RefCountedThreadSafe<LocalFileSyncContext>, |
+ public LocalFileSyncStatus::Observer { |
public: |
typedef base::Callback<void(SyncStatusCode status)> StatusCallback; |
+ typedef base::Callback<void(const FileSystemURL& url)> URLCallback; |
+ typedef base::Callback<void( |
+ SyncStatusCode status, |
+ const FileChangeList& change)> ChangeListCallback; |
LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, |
base::SingleThreadTaskRunner* io_task_runner); |
@@ -58,12 +63,38 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext |
// This method must be called on UI thread. |
void ShutdownOnUIThread(); |
+ // Prepares for sync |url| by disabling writes on |url|. |
+ // If the target |url| is being written and cannot start sync it |
+ // returns SYNC_STATUS_WRITING status code via |callback|. |
+ // Otherwise it disables writes, marks the |url| syncing and returns |
+ // the current change set made on |url|. |
+ // This method must be called on UI thread. |
+ void PrepareForSync(const FileSystemURL& url, |
+ const ChangeListCallback& callback); |
+ |
+ // Registers |url| to wait until sync is enabled for |url|. |
+ // |on_syncable_callback| is to be called when |url| becomes syncable |
+ // (i.e. when we have no pending writes and the file is successfully locked |
+ // for sync). |
+ // |
+ // It is NOT valid to call this method while this already has a URL waiting |
+ // for sync. |
+ // |
+ // This method must be called on UI thread. |
+ void RegisterURLForWaitingSync(const FileSystemURL& url, |
+ const URLCallback& on_syncable_callback); |
+ |
// OperationRunner is accessible only on IO thread. |
base::WeakPtr<SyncableFileOperationRunner> operation_runner() const; |
// SyncContext is accessible only on IO thread. |
LocalFileSyncStatus* sync_status() const; |
+ protected: |
+ // LocalFileSyncStatus::Observer overrides. They are called on IO thread. |
+ virtual void OnSyncEnabled(const FileSystemURL& url) OVERRIDE; |
+ virtual void OnWriteEnabled(const FileSystemURL& url) OVERRIDE; |
+ |
private: |
typedef std::deque<StatusCallback> StatusCallbackQueue; |
friend class base::RefCountedThreadSafe<LocalFileSyncContext>; |
@@ -90,9 +121,17 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext |
FileSystemContext* file_system_context, |
SyncStatusCode status); |
+ // Helper routines for PrepareForSync. |
+ void DidDisabledWritesForPrepareForSync( |
+ const FileSystemURL& url, |
+ const ChangeListCallback& callback); |
+ |
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
+ // Indicates if the sync service is shutdown on UI thread. |
+ bool shutdown_on_ui_; |
+ |
// OperationRunner. This must be accessed only on IO thread. |
scoped_ptr<SyncableFileOperationRunner> operation_runner_; |
@@ -114,6 +153,11 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext |
// Accessed only on UI thread. |
std::map<GURL, FileSystemContext*> origin_to_contexts_; |
+ // A URL and associated callback waiting for sync is enabled. |
+ // Accessed only on IO thread. |
+ FileSystemURL url_waiting_sync_on_io_; |
+ URLCallback url_syncable_callback_; |
+ |
DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); |
}; |