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

Side by Side Diff: webkit/fileapi/syncable/syncable_context.h

Issue 11090019: Add LocalFileSyncContext class which wires up profile-owned service and FileSystemContext(s) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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;
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 ~SyncableContext();
46
47 // Initializes |file_system_context| for syncable file operations and
48 // registers the it into the internal map.
49 // Calling this multiple times for the same file_system_context is valid.
50 // This method must be called on UI thread.
51 void MaybeInitializeFileSystemContext(const GURL& source_url,
52 FileSystemContext* file_system_context,
53 const StatusCallback& callback);
54
55 // Called when the corresponding LocalFileSyncService exits.
56 // This method must be called on UI thread.
57 void ShutdownOnUIThread();
58
59 private:
60 typedef std::deque<StatusCallback> StatusCallbackQueue;
61
62 void ShutdownOnIOThread();
63
64 // Helper routines for MaybeInitializeFileSystemContext.
65 void InitializeFileSystemContextOnIOThread(
66 const GURL& source_url,
67 FileSystemContext* file_system_context);
68 SyncStatusCode InitializeChangeTrackerOnFileThread(
69 scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
70 FileSystemContext* file_system_context);
71 void DidInitializeChangeTracker(
72 scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
73 const GURL& source_url,
74 FileSystemContext* file_system_context,
75 SyncStatusCode status);
76 void DidInitialize(
77 const GURL& source_url,
78 FileSystemContext* file_system_context,
79 SyncStatusCode status);
80
81 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
82 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
83
84 // This must be accessed only on UI thread.
85 bool shutdown_;
86
87 // Pointers to file system contexts that have been initialized for
88 // synchronization (i.e. that own this instance).
89 // This must be accessed only on UI thread.
90 std::set<FileSystemContext*> file_system_contexts_;
91
92 std::map<FileSystemContext*, StatusCallbackQueue>
93 pending_initialize_callbacks_;
94
95 // Origin to context map. (Assuming that as far as we're in the same
96 // profile single origin wouldn't belong to multiple FileSystemContexts.)
97 std::map<GURL, FileSystemContext*> origin_to_contexts_;
98
99 DISALLOW_COPY_AND_ASSIGN(SyncableContext);
100 };
101
102 } // namespace fileapi
103
104 #endif // WEBKIT_FILEAPI_SYNCABLE_SYNCABLE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698