OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_ |
| 6 #define WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <map> |
| 10 #include <set> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/callback_forward.h" |
| 14 #include "base/file_path.h" |
| 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "googleurl/src/gurl.h" |
| 19 #include "webkit/fileapi/fileapi_export.h" |
| 20 #include "webkit/fileapi/syncable/file_change.h" |
| 21 #include "webkit/fileapi/syncable/sync_status_code.h" |
| 22 |
| 23 namespace base { |
| 24 class SingleThreadTaskRunner; |
| 25 } |
| 26 |
| 27 namespace fileapi { |
| 28 |
| 29 class FileSystemContext; |
| 30 class LocalFileChangeTracker; |
| 31 |
| 32 // This class works as a bridge between LocalFileSyncService (which is a |
| 33 // per-profile object) and FileSystemContext's (which is a per-storage-partition |
| 34 // object and may exist multiple in a profile). |
| 35 // An instance of this class is shared by FileSystemContexts and outlives |
| 36 // LocalFileSyncService. |
| 37 class FILEAPI_EXPORT LocalFileSyncContext |
| 38 : public base::RefCountedThreadSafe<LocalFileSyncContext> { |
| 39 public: |
| 40 typedef base::Callback<void(SyncStatusCode status)> StatusCallback; |
| 41 |
| 42 LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, |
| 43 base::SingleThreadTaskRunner* io_task_runner); |
| 44 |
| 45 // Initializes |file_system_context| for syncable file operations and |
| 46 // registers the it into the internal map. |
| 47 // Calling this multiple times for the same file_system_context is valid. |
| 48 // This method must be called on UI thread. |
| 49 void MaybeInitializeFileSystemContext(const GURL& source_url, |
| 50 FileSystemContext* file_system_context, |
| 51 const StatusCallback& callback); |
| 52 |
| 53 // Called when the corresponding LocalFileSyncService exits. |
| 54 // This method must be called on UI thread. |
| 55 void ShutdownOnUIThread(); |
| 56 |
| 57 private: |
| 58 typedef std::deque<StatusCallback> StatusCallbackQueue; |
| 59 friend class base::RefCountedThreadSafe<LocalFileSyncContext>; |
| 60 |
| 61 ~LocalFileSyncContext(); |
| 62 |
| 63 void ShutdownOnIOThread(); |
| 64 |
| 65 // Helper routines for MaybeInitializeFileSystemContext. |
| 66 void InitializeFileSystemContextOnIOThread( |
| 67 const GURL& source_url, |
| 68 FileSystemContext* file_system_context); |
| 69 SyncStatusCode InitializeChangeTrackerOnFileThread( |
| 70 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, |
| 71 FileSystemContext* file_system_context); |
| 72 void DidInitializeChangeTracker( |
| 73 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, |
| 74 const GURL& source_url, |
| 75 FileSystemContext* file_system_context, |
| 76 SyncStatusCode status); |
| 77 void DidInitialize( |
| 78 const GURL& source_url, |
| 79 FileSystemContext* file_system_context, |
| 80 SyncStatusCode status); |
| 81 |
| 82 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 83 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 84 |
| 85 // This must be accessed only on UI thread. |
| 86 bool shutdown_; |
| 87 |
| 88 // Pointers to file system contexts that have been initialized for |
| 89 // synchronization (i.e. that own this instance). |
| 90 // This must be accessed only on UI thread. |
| 91 std::set<FileSystemContext*> file_system_contexts_; |
| 92 |
| 93 std::map<FileSystemContext*, StatusCallbackQueue> |
| 94 pending_initialize_callbacks_; |
| 95 |
| 96 // Origin to context map. (Assuming that as far as we're in the same |
| 97 // profile single origin wouldn't belong to multiple FileSystemContexts.) |
| 98 std::map<GURL, FileSystemContext*> origin_to_contexts_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); |
| 101 }; |
| 102 |
| 103 } // namespace fileapi |
| 104 |
| 105 #endif // WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_SYNC_CONTEXT_H_ |
OLD | NEW |