OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
12 #include "base/files/file.h" | 14 #include "base/files/file.h" |
13 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/macros.h" |
14 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
15 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" | 18 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" |
16 #include "chrome/browser/sync_file_system/sync_status_code.h" | 19 #include "chrome/browser/sync_file_system/sync_status_code.h" |
17 #include "storage/browser/blob/blob_data_handle.h" | 20 #include "storage/browser/blob/blob_data_handle.h" |
18 #include "storage/browser/fileapi/file_system_operation.h" | 21 #include "storage/browser/fileapi/file_system_operation.h" |
19 #include "storage/browser/fileapi/file_system_url.h" | 22 #include "storage/browser/fileapi/file_system_url.h" |
20 #include "storage/browser/quota/quota_callbacks.h" | 23 #include "storage/browser/quota/quota_callbacks.h" |
21 #include "storage/common/fileapi/file_system_types.h" | 24 #include "storage/common/fileapi/file_system_types.h" |
22 #include "storage/common/fileapi/file_system_util.h" | 25 #include "storage/common/fileapi/file_system_util.h" |
23 #include "storage/common/quota/quota_types.h" | 26 #include "storage/common/quota/quota_types.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // This internally creates its own QuotaManager and FileSystemContext | 58 // This internally creates its own QuotaManager and FileSystemContext |
56 // (as we do so for each isolated application). | 59 // (as we do so for each isolated application). |
57 class CannedSyncableFileSystem | 60 class CannedSyncableFileSystem |
58 : public LocalFileSyncStatus::Observer { | 61 : public LocalFileSyncStatus::Observer { |
59 public: | 62 public: |
60 typedef base::Callback<void(const GURL& root, | 63 typedef base::Callback<void(const GURL& root, |
61 const std::string& name, | 64 const std::string& name, |
62 base::File::Error result)> | 65 base::File::Error result)> |
63 OpenFileSystemCallback; | 66 OpenFileSystemCallback; |
64 typedef base::Callback<void(base::File::Error)> StatusCallback; | 67 typedef base::Callback<void(base::File::Error)> StatusCallback; |
65 typedef base::Callback<void(int64)> WriteCallback; | 68 typedef base::Callback<void(int64_t)> WriteCallback; |
66 typedef storage::FileSystemOperation::FileEntryList FileEntryList; | 69 typedef storage::FileSystemOperation::FileEntryList FileEntryList; |
67 | 70 |
68 enum QuotaMode { | 71 enum QuotaMode { |
69 QUOTA_ENABLED, | 72 QUOTA_ENABLED, |
70 QUOTA_DISABLED, | 73 QUOTA_DISABLED, |
71 }; | 74 }; |
72 | 75 |
73 CannedSyncableFileSystem( | 76 CannedSyncableFileSystem( |
74 const GURL& origin, | 77 const GURL& origin, |
75 leveldb::Env* env_override, | 78 leveldb::Env* env_override, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // Helper routines to perform file system operations. | 117 // Helper routines to perform file system operations. |
115 // OpenFileSystem() must have been called before calling any of them. | 118 // OpenFileSystem() must have been called before calling any of them. |
116 // They create an operation and run it on IO task runner, and the operation | 119 // They create an operation and run it on IO task runner, and the operation |
117 // posts a task on file runner. | 120 // posts a task on file runner. |
118 base::File::Error CreateDirectory(const storage::FileSystemURL& url); | 121 base::File::Error CreateDirectory(const storage::FileSystemURL& url); |
119 base::File::Error CreateFile(const storage::FileSystemURL& url); | 122 base::File::Error CreateFile(const storage::FileSystemURL& url); |
120 base::File::Error Copy(const storage::FileSystemURL& src_url, | 123 base::File::Error Copy(const storage::FileSystemURL& src_url, |
121 const storage::FileSystemURL& dest_url); | 124 const storage::FileSystemURL& dest_url); |
122 base::File::Error Move(const storage::FileSystemURL& src_url, | 125 base::File::Error Move(const storage::FileSystemURL& src_url, |
123 const storage::FileSystemURL& dest_url); | 126 const storage::FileSystemURL& dest_url); |
124 base::File::Error TruncateFile(const storage::FileSystemURL& url, int64 size); | 127 base::File::Error TruncateFile(const storage::FileSystemURL& url, |
| 128 int64_t size); |
125 base::File::Error TouchFile(const storage::FileSystemURL& url, | 129 base::File::Error TouchFile(const storage::FileSystemURL& url, |
126 const base::Time& last_access_time, | 130 const base::Time& last_access_time, |
127 const base::Time& last_modified_time); | 131 const base::Time& last_modified_time); |
128 base::File::Error Remove(const storage::FileSystemURL& url, bool recursive); | 132 base::File::Error Remove(const storage::FileSystemURL& url, bool recursive); |
129 base::File::Error FileExists(const storage::FileSystemURL& url); | 133 base::File::Error FileExists(const storage::FileSystemURL& url); |
130 base::File::Error DirectoryExists(const storage::FileSystemURL& url); | 134 base::File::Error DirectoryExists(const storage::FileSystemURL& url); |
131 base::File::Error VerifyFile(const storage::FileSystemURL& url, | 135 base::File::Error VerifyFile(const storage::FileSystemURL& url, |
132 const std::string& expected_data); | 136 const std::string& expected_data); |
133 base::File::Error GetMetadataAndPlatformPath( | 137 base::File::Error GetMetadataAndPlatformPath( |
134 const storage::FileSystemURL& url, | 138 const storage::FileSystemURL& url, |
135 base::File::Info* info, | 139 base::File::Info* info, |
136 base::FilePath* platform_path); | 140 base::FilePath* platform_path); |
137 base::File::Error ReadDirectory(const storage::FileSystemURL& url, | 141 base::File::Error ReadDirectory(const storage::FileSystemURL& url, |
138 FileEntryList* entries); | 142 FileEntryList* entries); |
139 | 143 |
140 // Returns the # of bytes written (>=0) or an error code (<0). | 144 // Returns the # of bytes written (>=0) or an error code (<0). |
141 int64 Write(net::URLRequestContext* url_request_context, | 145 int64_t Write(net::URLRequestContext* url_request_context, |
142 const storage::FileSystemURL& url, | 146 const storage::FileSystemURL& url, |
143 scoped_ptr<storage::BlobDataHandle> blob_data_handle); | 147 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
144 int64 WriteString(const storage::FileSystemURL& url, const std::string& data); | 148 int64_t WriteString(const storage::FileSystemURL& url, |
| 149 const std::string& data); |
145 | 150 |
146 // Purges the file system local storage. | 151 // Purges the file system local storage. |
147 base::File::Error DeleteFileSystem(); | 152 base::File::Error DeleteFileSystem(); |
148 | 153 |
149 // Retrieves the quota and usage. | 154 // Retrieves the quota and usage. |
150 storage::QuotaStatusCode GetUsageAndQuota(int64* usage, int64* quota); | 155 storage::QuotaStatusCode GetUsageAndQuota(int64_t* usage, int64_t* quota); |
151 | 156 |
152 // ChangeTracker related methods. They run on file task runner. | 157 // ChangeTracker related methods. They run on file task runner. |
153 void GetChangedURLsInTracker(storage::FileSystemURLSet* urls); | 158 void GetChangedURLsInTracker(storage::FileSystemURLSet* urls); |
154 void ClearChangeForURLInTracker(const storage::FileSystemURL& url); | 159 void ClearChangeForURLInTracker(const storage::FileSystemURL& url); |
155 void GetChangesForURLInTracker(const storage::FileSystemURL& url, | 160 void GetChangesForURLInTracker(const storage::FileSystemURL& url, |
156 FileChangeList* changes); | 161 FileChangeList* changes); |
157 | 162 |
158 SyncFileSystemBackend* backend(); | 163 SyncFileSystemBackend* backend(); |
159 storage::FileSystemOperationRunner* operation_runner(); | 164 storage::FileSystemOperationRunner* operation_runner(); |
160 | 165 |
161 // LocalFileSyncStatus::Observer overrides. | 166 // LocalFileSyncStatus::Observer overrides. |
162 void OnSyncEnabled(const storage::FileSystemURL& url) override; | 167 void OnSyncEnabled(const storage::FileSystemURL& url) override; |
163 void OnWriteEnabled(const storage::FileSystemURL& url) override; | 168 void OnWriteEnabled(const storage::FileSystemURL& url) override; |
164 | 169 |
165 // Operation methods body. | 170 // Operation methods body. |
166 // They can be also called directly if the caller is already on IO thread. | 171 // They can be also called directly if the caller is already on IO thread. |
167 void DoOpenFileSystem(const OpenFileSystemCallback& callback); | 172 void DoOpenFileSystem(const OpenFileSystemCallback& callback); |
168 void DoCreateDirectory(const storage::FileSystemURL& url, | 173 void DoCreateDirectory(const storage::FileSystemURL& url, |
169 const StatusCallback& callback); | 174 const StatusCallback& callback); |
170 void DoCreateFile(const storage::FileSystemURL& url, | 175 void DoCreateFile(const storage::FileSystemURL& url, |
171 const StatusCallback& callback); | 176 const StatusCallback& callback); |
172 void DoCopy(const storage::FileSystemURL& src_url, | 177 void DoCopy(const storage::FileSystemURL& src_url, |
173 const storage::FileSystemURL& dest_url, | 178 const storage::FileSystemURL& dest_url, |
174 const StatusCallback& callback); | 179 const StatusCallback& callback); |
175 void DoMove(const storage::FileSystemURL& src_url, | 180 void DoMove(const storage::FileSystemURL& src_url, |
176 const storage::FileSystemURL& dest_url, | 181 const storage::FileSystemURL& dest_url, |
177 const StatusCallback& callback); | 182 const StatusCallback& callback); |
178 void DoTruncateFile(const storage::FileSystemURL& url, | 183 void DoTruncateFile(const storage::FileSystemURL& url, |
179 int64 size, | 184 int64_t size, |
180 const StatusCallback& callback); | 185 const StatusCallback& callback); |
181 void DoTouchFile(const storage::FileSystemURL& url, | 186 void DoTouchFile(const storage::FileSystemURL& url, |
182 const base::Time& last_access_time, | 187 const base::Time& last_access_time, |
183 const base::Time& last_modified_time, | 188 const base::Time& last_modified_time, |
184 const StatusCallback& callback); | 189 const StatusCallback& callback); |
185 void DoRemove(const storage::FileSystemURL& url, | 190 void DoRemove(const storage::FileSystemURL& url, |
186 bool recursive, | 191 bool recursive, |
187 const StatusCallback& callback); | 192 const StatusCallback& callback); |
188 void DoFileExists(const storage::FileSystemURL& url, | 193 void DoFileExists(const storage::FileSystemURL& url, |
189 const StatusCallback& callback); | 194 const StatusCallback& callback); |
190 void DoDirectoryExists(const storage::FileSystemURL& url, | 195 void DoDirectoryExists(const storage::FileSystemURL& url, |
191 const StatusCallback& callback); | 196 const StatusCallback& callback); |
192 void DoVerifyFile(const storage::FileSystemURL& url, | 197 void DoVerifyFile(const storage::FileSystemURL& url, |
193 const std::string& expected_data, | 198 const std::string& expected_data, |
194 const StatusCallback& callback); | 199 const StatusCallback& callback); |
195 void DoGetMetadataAndPlatformPath(const storage::FileSystemURL& url, | 200 void DoGetMetadataAndPlatformPath(const storage::FileSystemURL& url, |
196 base::File::Info* info, | 201 base::File::Info* info, |
197 base::FilePath* platform_path, | 202 base::FilePath* platform_path, |
198 const StatusCallback& callback); | 203 const StatusCallback& callback); |
199 void DoReadDirectory(const storage::FileSystemURL& url, | 204 void DoReadDirectory(const storage::FileSystemURL& url, |
200 FileEntryList* entries, | 205 FileEntryList* entries, |
201 const StatusCallback& callback); | 206 const StatusCallback& callback); |
202 void DoWrite(net::URLRequestContext* url_request_context, | 207 void DoWrite(net::URLRequestContext* url_request_context, |
203 const storage::FileSystemURL& url, | 208 const storage::FileSystemURL& url, |
204 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 209 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
205 const WriteCallback& callback); | 210 const WriteCallback& callback); |
206 void DoWriteString(const storage::FileSystemURL& url, | 211 void DoWriteString(const storage::FileSystemURL& url, |
207 const std::string& data, | 212 const std::string& data, |
208 const WriteCallback& callback); | 213 const WriteCallback& callback); |
209 void DoGetUsageAndQuota(int64* usage, | 214 void DoGetUsageAndQuota(int64_t* usage, |
210 int64* quota, | 215 int64_t* quota, |
211 const storage::StatusCallback& callback); | 216 const storage::StatusCallback& callback); |
212 | 217 |
213 private: | 218 private: |
214 typedef base::ObserverListThreadSafe<LocalFileSyncStatus::Observer> | 219 typedef base::ObserverListThreadSafe<LocalFileSyncStatus::Observer> |
215 ObserverList; | 220 ObserverList; |
216 | 221 |
217 // Callbacks. | 222 // Callbacks. |
218 void DidOpenFileSystem(base::SingleThreadTaskRunner* original_task_runner, | 223 void DidOpenFileSystem(base::SingleThreadTaskRunner* original_task_runner, |
219 const base::Closure& quit_closure, | 224 const base::Closure& quit_closure, |
220 const GURL& root, | 225 const GURL& root, |
(...skipping 24 matching lines...) Expand all Loading... |
245 bool is_filesystem_opened_; // Should be accessed only on the IO thread. | 250 bool is_filesystem_opened_; // Should be accessed only on the IO thread. |
246 | 251 |
247 scoped_refptr<ObserverList> sync_status_observers_; | 252 scoped_refptr<ObserverList> sync_status_observers_; |
248 | 253 |
249 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); | 254 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); |
250 }; | 255 }; |
251 | 256 |
252 } // namespace sync_file_system | 257 } // namespace sync_file_system |
253 | 258 |
254 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 259 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
OLD | NEW |