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 SyncableContext; |
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 |syncable_context| if it hasn't |
| 50 // been initialized. |
| 51 SyncStatusCode MaybeInitializeFileSystemContext( |
| 52 SyncableContext* syncable_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 TruncateFile(const FileSystemURL& url, int64 size); | 73 base::PlatformFileError TruncateFile(const FileSystemURL& url, int64 size); |
67 base::PlatformFileError Remove(const FileSystemURL& url, bool recursive); | 74 base::PlatformFileError Remove(const FileSystemURL& url, bool recursive); |
68 | 75 |
69 // Pruges the file system local storage. | 76 // Pruges the file system local storage. |
70 base::PlatformFileError DeleteFileSystem(); | 77 base::PlatformFileError DeleteFileSystem(); |
71 | 78 |
72 private: | 79 private: |
73 // Callbacks. | 80 // Callbacks. |
74 void DidOpenFileSystem(base::PlatformFileError result, | 81 void DidOpenFileSystem(base::PlatformFileError result, |
75 const std::string& name, | 82 const std::string& name, |
76 const GURL& root); | 83 const GURL& root); |
| 84 void DidInitializeFileSystemContext(SyncStatusCode status); |
77 void StatusCallback(base::PlatformFileError result); | 85 void StatusCallback(base::PlatformFileError result); |
78 | 86 |
79 FileSystemOperationContext* NewOperationContext(); | 87 FileSystemOperationContext* NewOperationContext(); |
80 | 88 |
81 ScopedTempDir data_dir_; | 89 ScopedTempDir data_dir_; |
82 const std::string service_name_; | 90 const std::string service_name_; |
83 | 91 |
84 scoped_refptr<quota::QuotaManager> quota_manager_; | 92 scoped_refptr<quota::QuotaManager> quota_manager_; |
85 scoped_refptr<FileSystemContext> file_system_context_; | 93 scoped_refptr<FileSystemContext> file_system_context_; |
86 LocalFileSystemTestOriginHelper test_helper_; | 94 LocalFileSystemTestOriginHelper test_helper_; |
87 GURL root_url_; | 95 GURL root_url_; |
88 base::PlatformFileError result_; | 96 base::PlatformFileError result_; |
89 SyncStatusCode sync_status_; | 97 SyncStatusCode sync_status_; |
90 | 98 |
| 99 // Boolean flags mainly for helping debug. |
| 100 bool is_filesystem_set_up_; |
| 101 bool is_filesystem_opened_; |
| 102 |
91 base::WeakPtrFactory<CannedSyncableFileSystem> weak_factory_; | 103 base::WeakPtrFactory<CannedSyncableFileSystem> weak_factory_; |
92 | 104 |
93 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); | 105 DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem); |
94 }; | 106 }; |
95 | 107 |
96 } // namespace fileapi | 108 } // namespace fileapi |
97 | 109 |
98 #endif // WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ | 110 #endif // WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_ |
OLD | NEW |