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

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: update 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
« no previous file with comments | « no previous file | webkit/fileapi/syncable/local_file_sync_context.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d63d749a4402f21f38a58db1923f812773215150 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"
@@ -19,6 +19,7 @@
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/syncable/file_change.h"
#include "webkit/fileapi/syncable/local_file_sync_status.h"
+#include "webkit/fileapi/syncable/sync_callbacks.h"
#include "webkit/fileapi/syncable/sync_status_code.h"
#include "webkit/storage/webkit_storage_export.h"
@@ -39,9 +40,12 @@ 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(
+ SyncStatusCode status,
+ const FileChangeList& change)> ChangeListCallback;
LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner,
base::SingleThreadTaskRunner* io_task_runner);
@@ -58,12 +62,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).
+ //
+ // Calling this method again while this already has another URL waiting
+ // for sync will overwrite the previously registered URL.
+ //
+ // This method must be called on UI thread.
+ void RegisterURLForWaitingSync(const FileSystemURL& url,
+ const base::Closure& 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 +120,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 +152,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_;
+ base::Closure 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698