Index: webkit/fileapi/syncable/syncable_context.h |
diff --git a/webkit/fileapi/syncable/syncable_context.h b/webkit/fileapi/syncable/syncable_context.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24393ad0e906856aa4f9b81f6f5f6036ce944dcf |
--- /dev/null |
+++ b/webkit/fileapi/syncable/syncable_context.h |
@@ -0,0 +1,106 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_CONTEXT_H_ |
+#define WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_CONTEXT_H_ |
+ |
+#include <deque> |
+#include <map> |
+#include <set> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback_forward.h" |
+#include "base/file_path.h" |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/single_thread_task_runner.h" |
+#include "googleurl/src/gurl.h" |
+#include "webkit/fileapi/fileapi_export.h" |
+#include "webkit/fileapi/syncable/file_change.h" |
+#include "webkit/fileapi/syncable/sync_status_code.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
tzik
2012/10/11 09:42:54
can we drop this?
kinuko
2012/10/11 10:13:02
Removed the include line on line 18.
|
+} |
+ |
+namespace fileapi { |
+ |
+class FileSystemContext; |
+class LocalFileChangeTracker; |
+ |
+// This class works as a bridge between LocalFileSyncService (which is a |
+// per-profile object) and FileSystemContext's (which is a per-storage-partition |
+// object and may exist multiple in a profile). |
+// An instance of this class is shared by FileSystemContexts and outlives |
+// LocalFileSyncService. |
+class FILEAPI_EXPORT SyncableContext |
+ : public base::RefCountedThreadSafe<SyncableContext> { |
+ public: |
+ typedef base::Callback<void(SyncStatusCode status)> StatusCallback; |
+ |
+ SyncableContext(base::SingleThreadTaskRunner* ui_task_runner, |
+ base::SingleThreadTaskRunner* io_task_runner); |
+ |
+ // Initializes |file_system_context| for syncable file operations and |
+ // registers the it into the internal map. |
+ // Calling this multiple times for the same file_system_context is valid. |
+ // This method must be called on UI thread. |
+ void MaybeInitializeFileSystemContext(const GURL& source_url, |
+ FileSystemContext* file_system_context, |
+ const StatusCallback& callback); |
+ |
+ // Called when the corresponding LocalFileSyncService exits. |
+ // This method must be called on UI thread. |
+ void ShutdownOnUIThread(); |
+ |
+ private: |
+ typedef std::deque<StatusCallback> StatusCallbackQueue; |
+ friend class base::RefCountedThreadSafe<SyncableContext>; |
+ |
+ ~SyncableContext(); |
+ |
+ void ShutdownOnIOThread(); |
+ |
+ // Helper routines for MaybeInitializeFileSystemContext. |
+ void InitializeFileSystemContextOnIOThread( |
+ const GURL& source_url, |
+ FileSystemContext* file_system_context); |
+ SyncStatusCode InitializeChangeTrackerOnFileThread( |
+ scoped_ptr<LocalFileChangeTracker>* tracker_ptr, |
+ FileSystemContext* file_system_context); |
+ void DidInitializeChangeTracker( |
+ scoped_ptr<LocalFileChangeTracker>* tracker_ptr, |
+ const GURL& source_url, |
+ FileSystemContext* file_system_context, |
+ SyncStatusCode status); |
+ void DidInitialize( |
+ const GURL& source_url, |
+ FileSystemContext* file_system_context, |
+ SyncStatusCode status); |
+ |
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
+ |
+ // This must be accessed only on UI thread. |
+ bool shutdown_; |
+ |
+ // Pointers to file system contexts that have been initialized for |
+ // synchronization (i.e. that own this instance). |
+ // This must be accessed only on UI thread. |
+ std::set<FileSystemContext*> file_system_contexts_; |
+ |
+ std::map<FileSystemContext*, StatusCallbackQueue> |
+ pending_initialize_callbacks_; |
+ |
+ // Origin to context map. (Assuming that as far as we're in the same |
+ // profile single origin wouldn't belong to multiple FileSystemContexts.) |
+ std::map<GURL, FileSystemContext*> origin_to_contexts_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SyncableContext); |
+}; |
+ |
+} // namespace fileapi |
+ |
+#endif // WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_CONTEXT_H_ |