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