| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/files/file.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/observer_list_threadsafe.h" | 15 #include "base/observer_list_threadsafe.h" |
| 15 #include "base/platform_file.h" | |
| 16 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" | 16 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" |
| 17 #include "chrome/browser/sync_file_system/sync_status_code.h" | 17 #include "chrome/browser/sync_file_system/sync_status_code.h" |
| 18 #include "webkit/browser/blob/blob_data_handle.h" | 18 #include "webkit/browser/blob/blob_data_handle.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation.h" | 19 #include "webkit/browser/fileapi/file_system_operation.h" |
| 20 #include "webkit/browser/fileapi/file_system_url.h" | 20 #include "webkit/browser/fileapi/file_system_url.h" |
| 21 #include "webkit/browser/quota/quota_callbacks.h" | 21 #include "webkit/browser/quota/quota_callbacks.h" |
| 22 #include "webkit/common/fileapi/file_system_types.h" | 22 #include "webkit/common/fileapi/file_system_types.h" |
| 23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
| 24 #include "webkit/common/quota/quota_types.h" | 24 #include "webkit/common/quota/quota_types.h" |
| 25 | 25 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 50 class SyncFileSystemBackend; | 50 class SyncFileSystemBackend; |
| 51 | 51 |
| 52 // A canned syncable filesystem for testing. | 52 // A canned syncable filesystem for testing. |
| 53 // This internally creates its own QuotaManager and FileSystemContext | 53 // This internally creates its own QuotaManager and FileSystemContext |
| 54 // (as we do so for each isolated application). | 54 // (as we do so for each isolated application). |
| 55 class CannedSyncableFileSystem | 55 class CannedSyncableFileSystem |
| 56 : public LocalFileSyncStatus::Observer { | 56 : public LocalFileSyncStatus::Observer { |
| 57 public: | 57 public: |
| 58 typedef base::Callback<void(const GURL& root, | 58 typedef base::Callback<void(const GURL& root, |
| 59 const std::string& name, | 59 const std::string& name, |
| 60 base::PlatformFileError result)> | 60 base::File::Error result)> |
| 61 OpenFileSystemCallback; | 61 OpenFileSystemCallback; |
| 62 typedef base::Callback<void(base::PlatformFileError)> StatusCallback; | 62 typedef base::Callback<void(base::File::Error)> StatusCallback; |
| 63 typedef base::Callback<void(int64)> WriteCallback; | 63 typedef base::Callback<void(int64)> WriteCallback; |
| 64 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; | 64 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; |
| 65 | 65 |
| 66 CannedSyncableFileSystem(const GURL& origin, | 66 CannedSyncableFileSystem(const GURL& origin, |
| 67 base::SingleThreadTaskRunner* io_task_runner, | 67 base::SingleThreadTaskRunner* io_task_runner, |
| 68 base::SingleThreadTaskRunner* file_task_runner); | 68 base::SingleThreadTaskRunner* file_task_runner); |
| 69 virtual ~CannedSyncableFileSystem(); | 69 virtual ~CannedSyncableFileSystem(); |
| 70 | 70 |
| 71 // SetUp must be called before using this instance. | 71 // SetUp must be called before using this instance. |
| 72 void SetUp(); | 72 void SetUp(); |
| 73 | 73 |
| 74 // TearDown must be called before destructing this instance. | 74 // TearDown must be called before destructing this instance. |
| 75 void TearDown(); | 75 void TearDown(); |
| 76 | 76 |
| 77 // Creates a FileSystemURL for the given (utf8) path string. | 77 // Creates a FileSystemURL for the given (utf8) path string. |
| 78 fileapi::FileSystemURL URL(const std::string& path) const; | 78 fileapi::FileSystemURL URL(const std::string& path) const; |
| 79 | 79 |
| 80 // Initialize this with given |sync_context| if it hasn't | 80 // Initialize this with given |sync_context| if it hasn't |
| 81 // been initialized. | 81 // been initialized. |
| 82 sync_file_system::SyncStatusCode MaybeInitializeFileSystemContext( | 82 sync_file_system::SyncStatusCode MaybeInitializeFileSystemContext( |
| 83 LocalFileSyncContext* sync_context); | 83 LocalFileSyncContext* sync_context); |
| 84 | 84 |
| 85 // Opens a new syncable file system. | 85 // Opens a new syncable file system. |
| 86 base::PlatformFileError OpenFileSystem(); | 86 base::File::Error OpenFileSystem(); |
| 87 | 87 |
| 88 // Register sync status observers. Unlike original | 88 // Register sync status observers. Unlike original |
| 89 // LocalFileSyncStatus::Observer implementation the observer methods | 89 // LocalFileSyncStatus::Observer implementation the observer methods |
| 90 // are called on the same thread where AddSyncStatusObserver were called. | 90 // are called on the same thread where AddSyncStatusObserver were called. |
| 91 void AddSyncStatusObserver(LocalFileSyncStatus::Observer* observer); | 91 void AddSyncStatusObserver(LocalFileSyncStatus::Observer* observer); |
| 92 void RemoveSyncStatusObserver(LocalFileSyncStatus::Observer* observer); | 92 void RemoveSyncStatusObserver(LocalFileSyncStatus::Observer* observer); |
| 93 | 93 |
| 94 // Accessors. | 94 // Accessors. |
| 95 fileapi::FileSystemContext* file_system_context() { | 95 fileapi::FileSystemContext* file_system_context() { |
| 96 return file_system_context_.get(); | 96 return file_system_context_.get(); |
| 97 } | 97 } |
| 98 quota::QuotaManager* quota_manager() { return quota_manager_.get(); } | 98 quota::QuotaManager* quota_manager() { return quota_manager_.get(); } |
| 99 GURL origin() const { return origin_; } | 99 GURL origin() const { return origin_; } |
| 100 fileapi::FileSystemType type() const { return type_; } | 100 fileapi::FileSystemType type() const { return type_; } |
| 101 quota::StorageType storage_type() const { | 101 quota::StorageType storage_type() const { |
| 102 return FileSystemTypeToQuotaStorageType(type_); | 102 return FileSystemTypeToQuotaStorageType(type_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Helper routines to perform file system operations. | 105 // Helper routines to perform file system operations. |
| 106 // OpenFileSystem() must have been called before calling any of them. | 106 // OpenFileSystem() must have been called before calling any of them. |
| 107 // They create an operation and run it on IO task runner, and the operation | 107 // They create an operation and run it on IO task runner, and the operation |
| 108 // posts a task on file runner. | 108 // posts a task on file runner. |
| 109 base::PlatformFileError CreateDirectory(const fileapi::FileSystemURL& url); | 109 base::File::Error CreateDirectory(const fileapi::FileSystemURL& url); |
| 110 base::PlatformFileError CreateFile(const fileapi::FileSystemURL& url); | 110 base::File::Error CreateFile(const fileapi::FileSystemURL& url); |
| 111 base::PlatformFileError Copy(const fileapi::FileSystemURL& src_url, | 111 base::File::Error Copy(const fileapi::FileSystemURL& src_url, |
| 112 const fileapi::FileSystemURL& dest_url); | 112 const fileapi::FileSystemURL& dest_url); |
| 113 base::PlatformFileError Move(const fileapi::FileSystemURL& src_url, | 113 base::File::Error Move(const fileapi::FileSystemURL& src_url, |
| 114 const fileapi::FileSystemURL& dest_url); | 114 const fileapi::FileSystemURL& dest_url); |
| 115 base::PlatformFileError TruncateFile(const fileapi::FileSystemURL& url, | 115 base::File::Error TruncateFile(const fileapi::FileSystemURL& url, |
| 116 int64 size); | 116 int64 size); |
| 117 base::PlatformFileError TouchFile(const fileapi::FileSystemURL& url, | 117 base::File::Error TouchFile(const fileapi::FileSystemURL& url, |
| 118 const base::Time& last_access_time, | 118 const base::Time& last_access_time, |
| 119 const base::Time& last_modified_time); | 119 const base::Time& last_modified_time); |
| 120 base::PlatformFileError Remove(const fileapi::FileSystemURL& url, | 120 base::File::Error Remove(const fileapi::FileSystemURL& url, bool recursive); |
| 121 bool recursive); | 121 base::File::Error FileExists(const fileapi::FileSystemURL& url); |
| 122 base::PlatformFileError FileExists(const fileapi::FileSystemURL& url); | 122 base::File::Error DirectoryExists(const fileapi::FileSystemURL& url); |
| 123 base::PlatformFileError DirectoryExists(const fileapi::FileSystemURL& url); | 123 base::File::Error VerifyFile(const fileapi::FileSystemURL& url, |
| 124 base::PlatformFileError VerifyFile(const fileapi::FileSystemURL& url, | 124 const std::string& expected_data); |
| 125 const std::string& expected_data); | 125 base::File::Error GetMetadataAndPlatformPath( |
| 126 base::PlatformFileError GetMetadataAndPlatformPath( | |
| 127 const fileapi::FileSystemURL& url, | 126 const fileapi::FileSystemURL& url, |
| 128 base::PlatformFileInfo* info, | 127 base::File::Info* info, |
| 129 base::FilePath* platform_path); | 128 base::FilePath* platform_path); |
| 130 base::PlatformFileError ReadDirectory(const fileapi::FileSystemURL& url, | 129 base::File::Error ReadDirectory(const fileapi::FileSystemURL& url, |
| 131 FileEntryList* entries); | 130 FileEntryList* entries); |
| 132 | 131 |
| 133 // Returns the # of bytes written (>=0) or an error code (<0). | 132 // Returns the # of bytes written (>=0) or an error code (<0). |
| 134 int64 Write(net::URLRequestContext* url_request_context, | 133 int64 Write(net::URLRequestContext* url_request_context, |
| 135 const fileapi::FileSystemURL& url, | 134 const fileapi::FileSystemURL& url, |
| 136 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle); | 135 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle); |
| 137 int64 WriteString(const fileapi::FileSystemURL& url, const std::string& data); | 136 int64 WriteString(const fileapi::FileSystemURL& url, const std::string& data); |
| 138 | 137 |
| 139 // Purges the file system local storage. | 138 // Purges the file system local storage. |
| 140 base::PlatformFileError DeleteFileSystem(); | 139 base::File::Error DeleteFileSystem(); |
| 141 | 140 |
| 142 // Retrieves the quota and usage. | 141 // Retrieves the quota and usage. |
| 143 quota::QuotaStatusCode GetUsageAndQuota(int64* usage, int64* quota); | 142 quota::QuotaStatusCode GetUsageAndQuota(int64* usage, int64* quota); |
| 144 | 143 |
| 145 // ChangeTracker related methods. They run on file task runner. | 144 // ChangeTracker related methods. They run on file task runner. |
| 146 void GetChangedURLsInTracker(fileapi::FileSystemURLSet* urls); | 145 void GetChangedURLsInTracker(fileapi::FileSystemURLSet* urls); |
| 147 void ClearChangeForURLInTracker(const fileapi::FileSystemURL& url); | 146 void ClearChangeForURLInTracker(const fileapi::FileSystemURL& url); |
| 148 void GetChangesForURLInTracker(const fileapi::FileSystemURL& url, | 147 void GetChangesForURLInTracker(const fileapi::FileSystemURL& url, |
| 149 FileChangeList* changes); | 148 FileChangeList* changes); |
| 150 | 149 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 179 bool recursive, | 178 bool recursive, |
| 180 const StatusCallback& callback); | 179 const StatusCallback& callback); |
| 181 void DoFileExists(const fileapi::FileSystemURL& url, | 180 void DoFileExists(const fileapi::FileSystemURL& url, |
| 182 const StatusCallback& callback); | 181 const StatusCallback& callback); |
| 183 void DoDirectoryExists(const fileapi::FileSystemURL& url, | 182 void DoDirectoryExists(const fileapi::FileSystemURL& url, |
| 184 const StatusCallback& callback); | 183 const StatusCallback& callback); |
| 185 void DoVerifyFile(const fileapi::FileSystemURL& url, | 184 void DoVerifyFile(const fileapi::FileSystemURL& url, |
| 186 const std::string& expected_data, | 185 const std::string& expected_data, |
| 187 const StatusCallback& callback); | 186 const StatusCallback& callback); |
| 188 void DoGetMetadataAndPlatformPath(const fileapi::FileSystemURL& url, | 187 void DoGetMetadataAndPlatformPath(const fileapi::FileSystemURL& url, |
| 189 base::PlatformFileInfo* info, | 188 base::File::Info* info, |
| 190 base::FilePath* platform_path, | 189 base::FilePath* platform_path, |
| 191 const StatusCallback& callback); | 190 const StatusCallback& callback); |
| 192 void DoReadDirectory(const fileapi::FileSystemURL& url, | 191 void DoReadDirectory(const fileapi::FileSystemURL& url, |
| 193 FileEntryList* entries, | 192 FileEntryList* entries, |
| 194 const StatusCallback& callback); | 193 const StatusCallback& callback); |
| 195 void DoWrite(net::URLRequestContext* url_request_context, | 194 void DoWrite(net::URLRequestContext* url_request_context, |
| 196 const fileapi::FileSystemURL& url, | 195 const fileapi::FileSystemURL& url, |
| 197 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle, | 196 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle, |
| 198 const WriteCallback& callback); | 197 const WriteCallback& callback); |
| 199 void DoWriteString(const fileapi::FileSystemURL& url, | 198 void DoWriteString(const fileapi::FileSystemURL& url, |
| 200 const std::string& data, | 199 const std::string& data, |
| 201 const WriteCallback& callback); | 200 const WriteCallback& callback); |
| 202 void DoGetUsageAndQuota(int64* usage, | 201 void DoGetUsageAndQuota(int64* usage, |
| 203 int64* quota, | 202 int64* quota, |
| 204 const quota::StatusCallback& callback); | 203 const quota::StatusCallback& callback); |
| 205 | 204 |
| 206 private: | 205 private: |
| 207 typedef ObserverListThreadSafe<LocalFileSyncStatus::Observer> ObserverList; | 206 typedef ObserverListThreadSafe<LocalFileSyncStatus::Observer> ObserverList; |
| 208 | 207 |
| 209 // Callbacks. | 208 // Callbacks. |
| 210 void DidOpenFileSystem(base::SingleThreadTaskRunner* original_task_runner, | 209 void DidOpenFileSystem(base::SingleThreadTaskRunner* original_task_runner, |
| 211 const GURL& root, | 210 const GURL& root, |
| 212 const std::string& name, | 211 const std::string& name, |
| 213 base::PlatformFileError result); | 212 base::File::Error result); |
| 214 void DidInitializeFileSystemContext(sync_file_system::SyncStatusCode status); | 213 void DidInitializeFileSystemContext(sync_file_system::SyncStatusCode status); |
| 215 | 214 |
| 216 void InitializeSyncStatusObserver(); | 215 void InitializeSyncStatusObserver(); |
| 217 | 216 |
| 218 base::ScopedTempDir data_dir_; | 217 base::ScopedTempDir data_dir_; |
| 219 const std::string service_name_; | 218 const std::string service_name_; |
| 220 | 219 |
| 221 scoped_refptr<quota::QuotaManager> quota_manager_; | 220 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 222 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 221 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 223 const GURL origin_; | 222 const GURL origin_; |
| 224 const fileapi::FileSystemType type_; | 223 const fileapi::FileSystemType type_; |
| 225 GURL root_url_; | 224 GURL root_url_; |
| 226 base::PlatformFileError result_; | 225 base::File::Error result_; |
| 227 sync_file_system::SyncStatusCode sync_status_; | 226 sync_file_system::SyncStatusCode sync_status_; |
| 228 | 227 |
| 229 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 228 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 230 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 229 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 231 | 230 |
| 232 // Boolean flags mainly for helping debug. | 231 // Boolean flags mainly for helping debug. |
| 233 bool is_filesystem_set_up_; | 232 bool is_filesystem_set_up_; |
| 234 bool is_filesystem_opened_; // Should be accessed only on the IO thread. | 233 bool is_filesystem_opened_; // Should be accessed only on the IO thread. |
| 235 | 234 |
| 236 scoped_refptr<ObserverList> sync_status_observers_; | 235 scoped_refptr<ObserverList> sync_status_observers_; |
| 237 | 236 |
| 238 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); | 237 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); |
| 239 }; | 238 }; |
| 240 | 239 |
| 241 } // namespace sync_file_system | 240 } // namespace sync_file_system |
| 242 | 241 |
| 243 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 242 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
| OLD | NEW |