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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
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 c02d81a6ce3f739d2d8deac244f64bae9a00fb77..4a3365538b7cefc274e3437a6b1236cf7d339fcb 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"
@@ -37,9 +37,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);
@@ -56,9 +61,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>;
@@ -85,9 +119,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_;
@@ -103,6 +145,11 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext
// profile single origin wouldn't belong to multiple FileSystemContexts.)
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);
};
« 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