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 WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 5 #ifndef WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
6 #define WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 6 #define WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "webkit/fileapi/file_system_types.h" | 14 #include "webkit/fileapi/file_system_types.h" |
15 #include "webkit/fileapi/local_file_system_test_helper.h" | 15 #include "webkit/fileapi/local_file_system_test_helper.h" |
16 #include "webkit/fileapi/syncable/sync_status_code.h" | 16 #include "webkit/fileapi/syncable/sync_status_code.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class Thread; | 19 class Thread; |
20 class MessageLoopProxy; | 20 class MessageLoopProxy; |
21 } | 21 } |
22 | 22 |
23 namespace quota { | 23 namespace quota { |
24 class QuotaManager; | 24 class QuotaManager; |
25 } | 25 } |
26 | 26 |
27 namespace fileapi { | 27 namespace fileapi { |
28 | 28 |
29 class FileSystemContext; | 29 class FileSystemContext; |
| 30 class LocalFileSyncContext; |
30 | 31 |
31 // A canned syncable filesystem for testing. | 32 // A canned syncable filesystem for testing. |
32 // This internally creates its own QuotaManager and FileSystemContext | 33 // This internally creates its own QuotaManager and FileSystemContext |
33 // (as we do so for each isolated application). | 34 // (as we do so for each isolated application). |
34 class CannedSyncableFileSystem { | 35 class CannedSyncableFileSystem { |
35 public: | 36 public: |
36 CannedSyncableFileSystem(const GURL& origin, const std::string& service); | 37 CannedSyncableFileSystem(const GURL& origin, const std::string& service); |
37 ~CannedSyncableFileSystem(); | 38 ~CannedSyncableFileSystem(); |
38 | 39 |
39 // SetUp must be called before using this instance. | 40 // SetUp must be called before using this instance. |
40 void SetUp(); | 41 void SetUp(); |
41 | 42 |
42 // TearDown must be called before destructing this instance. | 43 // TearDown must be called before destructing this instance. |
43 void TearDown(); | 44 void TearDown(); |
44 | 45 |
45 // Creates a FileSystemURL for the given (utf8) path string. | 46 // Creates a FileSystemURL for the given (utf8) path string. |
46 FileSystemURL URL(const std::string& path) const; | 47 FileSystemURL URL(const std::string& path) const; |
47 | 48 |
| 49 // Initialize this with given |sync_context| if it hasn't |
| 50 // been initialized. |
| 51 SyncStatusCode MaybeInitializeFileSystemContext( |
| 52 LocalFileSyncContext* sync_context); |
| 53 |
48 // Opens a new syncable file system. | 54 // Opens a new syncable file system. |
49 base::PlatformFileError OpenFileSystem(); | 55 base::PlatformFileError OpenFileSystem(); |
50 | 56 |
51 // Accessors. | 57 // Accessors. |
52 FileSystemContext* file_system_context() { | 58 FileSystemContext* file_system_context() { |
53 return file_system_context_.get(); | 59 return file_system_context_.get(); |
54 } | 60 } |
55 quota::QuotaManager* quota_manager() { return quota_manager_.get(); } | 61 quota::QuotaManager* quota_manager() { return quota_manager_.get(); } |
56 GURL origin() const { return test_helper_.origin(); } | 62 GURL origin() const { return test_helper_.origin(); } |
57 FileSystemType type() const { return test_helper_.type(); } | 63 FileSystemType type() const { return test_helper_.type(); } |
58 quota::StorageType storage_type() const { | 64 quota::StorageType storage_type() const { |
59 return test_helper_.storage_type(); | 65 return test_helper_.storage_type(); |
60 } | 66 } |
61 | 67 |
62 // Helper routines to perform file system operations. | 68 // Helper routines to perform file system operations. |
| 69 // OpenFileSystem() must have been called before calling any of them. |
63 // (They run on the current thread and returns synchronously). | 70 // (They run on the current thread and returns synchronously). |
64 base::PlatformFileError CreateDirectory(const FileSystemURL& url); | 71 base::PlatformFileError CreateDirectory(const FileSystemURL& url); |
65 base::PlatformFileError CreateFile(const FileSystemURL& url); | 72 base::PlatformFileError CreateFile(const FileSystemURL& url); |
66 base::PlatformFileError Copy(const FileSystemURL& src_url, | 73 base::PlatformFileError Copy(const FileSystemURL& src_url, |
67 const FileSystemURL& dest_url); | 74 const FileSystemURL& dest_url); |
68 base::PlatformFileError Move(const FileSystemURL& src_url, | 75 base::PlatformFileError Move(const FileSystemURL& src_url, |
69 const FileSystemURL& dest_url); | 76 const FileSystemURL& dest_url); |
70 base::PlatformFileError TruncateFile(const FileSystemURL& url, int64 size); | 77 base::PlatformFileError TruncateFile(const FileSystemURL& url, int64 size); |
71 base::PlatformFileError Remove(const FileSystemURL& url, bool recursive); | 78 base::PlatformFileError Remove(const FileSystemURL& url, bool recursive); |
72 | 79 |
73 // Pruges the file system local storage. | 80 // Pruges the file system local storage. |
74 base::PlatformFileError DeleteFileSystem(); | 81 base::PlatformFileError DeleteFileSystem(); |
75 | 82 |
76 private: | 83 private: |
77 // Callbacks. | 84 // Callbacks. |
78 void DidOpenFileSystem(base::PlatformFileError result, | 85 void DidOpenFileSystem(base::PlatformFileError result, |
79 const std::string& name, | 86 const std::string& name, |
80 const GURL& root); | 87 const GURL& root); |
| 88 void DidInitializeFileSystemContext(SyncStatusCode status); |
81 void StatusCallback(base::PlatformFileError result); | 89 void StatusCallback(base::PlatformFileError result); |
82 | 90 |
83 FileSystemOperationContext* NewOperationContext(); | 91 FileSystemOperationContext* NewOperationContext(); |
84 | 92 |
85 ScopedTempDir data_dir_; | 93 ScopedTempDir data_dir_; |
86 const std::string service_name_; | 94 const std::string service_name_; |
87 | 95 |
88 scoped_refptr<quota::QuotaManager> quota_manager_; | 96 scoped_refptr<quota::QuotaManager> quota_manager_; |
89 scoped_refptr<FileSystemContext> file_system_context_; | 97 scoped_refptr<FileSystemContext> file_system_context_; |
90 LocalFileSystemTestOriginHelper test_helper_; | 98 LocalFileSystemTestOriginHelper test_helper_; |
91 GURL root_url_; | 99 GURL root_url_; |
92 base::PlatformFileError result_; | 100 base::PlatformFileError result_; |
93 SyncStatusCode sync_status_; | 101 SyncStatusCode sync_status_; |
94 | 102 |
| 103 // Boolean flags mainly for helping debug. |
| 104 bool is_filesystem_set_up_; |
| 105 bool is_filesystem_opened_; |
| 106 |
95 base::WeakPtrFactory<CannedSyncableFileSystem> weak_factory_; | 107 base::WeakPtrFactory<CannedSyncableFileSystem> weak_factory_; |
96 | 108 |
97 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); | 109 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); |
98 }; | 110 }; |
99 | 111 |
100 } // namespace fileapi | 112 } // namespace fileapi |
101 | 113 |
102 #endif // WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 114 #endif // WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
OLD | NEW |