OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "webkit/fileapi/file_system_url.h" | 19 #include "webkit/fileapi/file_system_url.h" |
20 #include "webkit/fileapi/syncable/sync_callbacks.h" | 20 #include "webkit/fileapi/syncable/sync_callbacks.h" |
21 #include "webkit/fileapi/syncable/sync_status_code.h" | 21 #include "webkit/fileapi/syncable/sync_status_code.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
25 } | 25 } |
26 | 26 |
| 27 namespace leveldb { |
| 28 class DB; |
| 29 } |
| 30 |
27 class GURL; | 31 class GURL; |
28 | 32 |
29 namespace sync_file_system { | 33 namespace sync_file_system { |
30 | 34 |
31 class DriveMetadata; | 35 class DriveMetadata; |
32 class DriveMetadataDB; | 36 class DriveMetadataDB; |
33 struct DriveMetadataDBContents; | 37 struct DriveMetadataDBContents; |
34 | 38 |
35 // This class holds a snapshot of the server side metadata. | 39 // This class holds a snapshot of the server side metadata. |
36 class DriveMetadataStore | 40 class DriveMetadataStore |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Lookups and reads the database entry for |url|. | 76 // Lookups and reads the database entry for |url|. |
73 SyncStatusCode ReadEntry(const fileapi::FileSystemURL& url, | 77 SyncStatusCode ReadEntry(const fileapi::FileSystemURL& url, |
74 DriveMetadata* metadata) const; | 78 DriveMetadata* metadata) const; |
75 | 79 |
76 // Marks |origin| as incremental sync and associates it with the directory | 80 // Marks |origin| as incremental sync and associates it with the directory |
77 // identified by |resource_id|. | 81 // identified by |resource_id|. |
78 // |origin| must not already be an incremental sync origin. | 82 // |origin| must not already be an incremental sync origin. |
79 void AddIncrementalSyncOrigin(const GURL& origin, | 83 void AddIncrementalSyncOrigin(const GURL& origin, |
80 const std::string& resource_id); | 84 const std::string& resource_id); |
81 | 85 |
82 // Returns true if |origin| is a batch sync origin, a incremental sync origin | 86 // Returns true if |origin| is an incremental sync or disabled origin. |
83 // or a disabled origin. | |
84 bool IsKnownOrigin(const GURL& origin) const; | 87 bool IsKnownOrigin(const GURL& origin) const; |
85 | 88 |
86 // Returns true if |origin| is a batch sync origin, i.e. the origin's entire | |
87 // file list hasn't been fully fetched and processed yet. | |
88 bool IsBatchSyncOrigin(const GURL& origin) const; | |
89 | |
90 // Returns true if |origin| is an incremental sync origin, i.e. the origin's | 89 // Returns true if |origin| is an incremental sync origin, i.e. the origin's |
91 // entire file list has been cached and is ready to apply changes | 90 // entire file list has been cached and is ready to apply changes |
92 // incrementally. | 91 // incrementally. |
93 bool IsIncrementalSyncOrigin(const GURL& origin) const; | 92 bool IsIncrementalSyncOrigin(const GURL& origin) const; |
94 | 93 |
95 // Returns true if |origin| is a disabled origin. | 94 // Returns true if |origin| is a disabled origin. |
96 bool IsOriginDisabled(const GURL& origin) const; | 95 bool IsOriginDisabled(const GURL& origin) const; |
97 | 96 |
98 void EnableOrigin(const GURL& origin, | 97 void EnableOrigin(const GURL& origin, |
99 const SyncStatusCallback& callback); | 98 const SyncStatusCallback& callback); |
(...skipping 11 matching lines...) Expand all Loading... |
111 const std::string& resource_id); | 110 const std::string& resource_id); |
112 | 111 |
113 // Returns a set of URLs for files in conflict. | 112 // Returns a set of URLs for files in conflict. |
114 SyncStatusCode GetConflictURLs( | 113 SyncStatusCode GetConflictURLs( |
115 fileapi::FileSystemURLSet* urls) const; | 114 fileapi::FileSystemURLSet* urls) const; |
116 | 115 |
117 // Returns a set of URLs and Resource IDs for files to be fetched. | 116 // Returns a set of URLs and Resource IDs for files to be fetched. |
118 SyncStatusCode GetToBeFetchedFiles(URLAndDriveMetadataList* list) const; | 117 SyncStatusCode GetToBeFetchedFiles(URLAndDriveMetadataList* list) const; |
119 | 118 |
120 // Returns resource id for |origin|. | 119 // Returns resource id for |origin|. |
121 // This may return an empty string if |origin| is not a batch, incremental | 120 // This may return an empty string if |origin| is not a incremental or |
122 // or disabled origin. | 121 // disabled origin. |
123 std::string GetResourceIdForOrigin(const GURL& origin) const; | 122 std::string GetResourceIdForOrigin(const GURL& origin) const; |
124 | 123 |
125 const std::string& sync_root_directory() const { | 124 const std::string& sync_root_directory() const { |
126 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
127 return sync_root_directory_resource_id_; | 126 return sync_root_directory_resource_id_; |
128 } | 127 } |
129 | 128 |
130 const ResourceIdByOrigin& batch_sync_origins() const { | |
131 DCHECK(CalledOnValidThread()); | |
132 return batch_sync_origins_; | |
133 } | |
134 | |
135 const ResourceIdByOrigin& incremental_sync_origins() const { | 129 const ResourceIdByOrigin& incremental_sync_origins() const { |
136 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
137 return incremental_sync_origins_; | 131 return incremental_sync_origins_; |
138 } | 132 } |
139 | 133 |
140 const ResourceIdByOrigin& disabled_origins() const { | 134 const ResourceIdByOrigin& disabled_origins() const { |
141 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
142 return disabled_origins_; | 136 return disabled_origins_; |
143 } | 137 } |
144 | 138 |
145 // Returns all tracked origins. i.e. Union of batch_sync_origins_, | 139 // Returns all tracked origins. i.e. incremental_sync_origins_ and |
146 // incremental_sync_origins_ and disabled_origins_. | 140 // disabled_origins_. |
147 void GetAllOrigins(std::vector<GURL>* origins); | 141 void GetAllOrigins(std::vector<GURL>* origins); |
148 | 142 |
149 // Maps |resource_id| to corresponding |origin|. | 143 // Maps |resource_id| to corresponding |origin|. |
150 // Returns true if the directory indicated by |resource_id| is not an origin | 144 // Returns true if the directory indicated by |resource_id| is not an origin |
151 // root directory. | 145 // root directory. |
152 bool GetOriginByOriginRootDirectoryId(const std::string& resource_id, | 146 bool GetOriginByOriginRootDirectoryId(const std::string& resource_id, |
153 GURL* origin); | 147 GURL* origin); |
154 | 148 |
155 private: | 149 private: |
156 friend class DriveMetadataStoreTest; | 150 friend class DriveMetadataStoreTest; |
157 | 151 |
158 // Marks |origin| as a batch sync origin and associates it with the directory | |
159 // identified by |resource_id|. | |
160 // |origin| must not be a batch sync origin nor an incremental sync origin. | |
161 void AddBatchSyncOrigin(const GURL& origin, const std::string& resource_id); | |
162 | |
163 // Marks |origin| as an incremental sync origin. | |
164 // |origin| must be a batch sync origin. | |
165 void MoveBatchSyncOriginToIncremental(const GURL& origin); | |
166 | |
167 void UpdateDBStatus(SyncStatusCode status); | 152 void UpdateDBStatus(SyncStatusCode status); |
168 void UpdateDBStatusAndInvokeCallback(const SyncStatusCallback& callback, | 153 void UpdateDBStatusAndInvokeCallback(const SyncStatusCallback& callback, |
169 SyncStatusCode status); | 154 SyncStatusCode status); |
170 void DidInitialize(const InitializationCallback& callback, | 155 void DidInitialize(const InitializationCallback& callback, |
171 DriveMetadataDBContents* contents, | 156 DriveMetadataDBContents* contents, |
172 SyncStatusCode error); | 157 SyncStatusCode error); |
173 void DidUpdateOrigin(const SyncStatusCallback& callback, | 158 void DidUpdateOrigin(const SyncStatusCallback& callback, |
174 SyncStatusCode status); | 159 SyncStatusCode status); |
175 | 160 |
176 // These are only for testing. | 161 // These are only for testing. |
177 void RestoreSyncRootDirectory(const SyncStatusCallback& callback); | 162 void RestoreSyncRootDirectory(const SyncStatusCallback& callback); |
178 void DidRestoreSyncRootDirectory(const SyncStatusCallback& callback, | 163 void DidRestoreSyncRootDirectory(const SyncStatusCallback& callback, |
179 std::string* sync_root_directory_resource_id, | 164 std::string* sync_root_directory_resource_id, |
180 SyncStatusCode status); | 165 SyncStatusCode status); |
181 void RestoreOrigins(const SyncStatusCallback& callback); | 166 void RestoreOrigins(const SyncStatusCallback& callback); |
182 void DidRestoreOrigins(const SyncStatusCallback& callback, | 167 void DidRestoreOrigins(const SyncStatusCallback& callback, |
183 ResourceIdByOrigin* batch_sync_origins, | |
184 ResourceIdByOrigin* incremental_sync_origins, | 168 ResourceIdByOrigin* incremental_sync_origins, |
185 ResourceIdByOrigin* disabled_origins, | 169 ResourceIdByOrigin* disabled_origins, |
186 SyncStatusCode status); | 170 SyncStatusCode status); |
| 171 leveldb::DB* GetDBInstanceForTesting(); |
187 | 172 |
188 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 173 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
189 scoped_ptr<DriveMetadataDB> db_; | 174 scoped_ptr<DriveMetadataDB> db_; |
190 SyncStatusCode db_status_; | 175 SyncStatusCode db_status_; |
191 | 176 |
192 int64 largest_changestamp_; | 177 int64 largest_changestamp_; |
193 MetadataMap metadata_map_; | 178 MetadataMap metadata_map_; |
194 | 179 |
195 std::string sync_root_directory_resource_id_; | 180 std::string sync_root_directory_resource_id_; |
196 ResourceIdByOrigin batch_sync_origins_; | |
197 ResourceIdByOrigin incremental_sync_origins_; | 181 ResourceIdByOrigin incremental_sync_origins_; |
198 ResourceIdByOrigin disabled_origins_; | 182 ResourceIdByOrigin disabled_origins_; |
199 | 183 |
200 OriginByResourceId origin_by_resource_id_; | 184 OriginByResourceId origin_by_resource_id_; |
201 | 185 |
202 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStore); | 186 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStore); |
203 }; | 187 }; |
204 | 188 |
205 } // namespace sync_file_system | 189 } // namespace sync_file_system |
206 | 190 |
207 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ | 191 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_METADATA_STORE_H_ |
OLD | NEW |