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 #include "webkit/browser/fileapi/test_mount_point_provider.h" | 5 #include "webkit/browser/fileapi/test_file_system_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
14 #include "webkit/browser/fileapi/file_observers.h" | 14 #include "webkit/browser/fileapi/file_observers.h" |
15 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" | 15 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
16 #include "webkit/browser/fileapi/file_system_operation_context.h" | 16 #include "webkit/browser/fileapi/file_system_operation_context.h" |
17 #include "webkit/browser/fileapi/file_system_quota_util.h" | 17 #include "webkit/browser/fileapi/file_system_quota_util.h" |
18 #include "webkit/browser/fileapi/local_file_system_operation.h" | 18 #include "webkit/browser/fileapi/local_file_system_operation.h" |
19 #include "webkit/browser/fileapi/local_file_util.h" | 19 #include "webkit/browser/fileapi/local_file_util.h" |
20 #include "webkit/browser/fileapi/native_file_util.h" | 20 #include "webkit/browser/fileapi/native_file_util.h" |
21 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 21 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" |
22 #include "webkit/browser/quota/quota_manager.h" | 22 #include "webkit/browser/quota/quota_manager.h" |
23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
24 | 24 |
25 namespace fileapi { | 25 namespace fileapi { |
26 | 26 |
27 // This only supports single origin. | 27 // This only supports single origin. |
28 class TestMountPointProvider::QuotaUtil | 28 class TestFileSystemBackend::QuotaUtil |
29 : public FileSystemQuotaUtil, | 29 : public FileSystemQuotaUtil, |
30 public FileUpdateObserver { | 30 public FileUpdateObserver { |
31 public: | 31 public: |
32 QuotaUtil() : usage_(0) {} | 32 QuotaUtil() : usage_(0) {} |
33 virtual ~QuotaUtil() {} | 33 virtual ~QuotaUtil() {} |
34 | 34 |
35 // FileSystemQuotaUtil overrides. | 35 // FileSystemQuotaUtil overrides. |
36 virtual base::PlatformFileError DeleteOriginDataOnFileThread( | 36 virtual base::PlatformFileError DeleteOriginDataOnFileThread( |
37 FileSystemContext* context, | 37 FileSystemContext* context, |
38 quota::QuotaManagerProxy* proxy, | 38 quota::QuotaManagerProxy* proxy, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} | 72 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} |
73 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { | 73 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { |
74 usage_ += delta; | 74 usage_ += delta; |
75 } | 75 } |
76 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} | 76 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} |
77 | 77 |
78 private: | 78 private: |
79 int64 usage_; | 79 int64 usage_; |
80 }; | 80 }; |
81 | 81 |
82 TestMountPointProvider::TestMountPointProvider( | 82 TestFileSystemBackend::TestFileSystemBackend( |
83 base::SequencedTaskRunner* task_runner, | 83 base::SequencedTaskRunner* task_runner, |
84 const base::FilePath& base_path) | 84 const base::FilePath& base_path) |
85 : base_path_(base_path), | 85 : base_path_(base_path), |
86 task_runner_(task_runner), | 86 task_runner_(task_runner), |
87 local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())), | 87 local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())), |
88 quota_util_(new QuotaUtil), | 88 quota_util_(new QuotaUtil), |
89 require_copy_or_move_validator_(false) { | 89 require_copy_or_move_validator_(false) { |
90 UpdateObserverList::Source source; | 90 UpdateObserverList::Source source; |
91 source.AddObserver(quota_util_.get(), task_runner_.get()); | 91 source.AddObserver(quota_util_.get(), task_runner_.get()); |
92 update_observers_ = UpdateObserverList(source); | 92 update_observers_ = UpdateObserverList(source); |
93 } | 93 } |
94 | 94 |
95 TestMountPointProvider::~TestMountPointProvider() { | 95 TestFileSystemBackend::~TestFileSystemBackend() { |
96 } | 96 } |
97 | 97 |
98 bool TestMountPointProvider::CanHandleType(FileSystemType type) const { | 98 bool TestFileSystemBackend::CanHandleType(FileSystemType type) const { |
99 return (type == kFileSystemTypeTest); | 99 return (type == kFileSystemTypeTest); |
100 } | 100 } |
101 | 101 |
102 void TestMountPointProvider::OpenFileSystem( | 102 void TestFileSystemBackend::OpenFileSystem( |
103 const GURL& origin_url, | 103 const GURL& origin_url, |
104 FileSystemType type, | 104 FileSystemType type, |
105 OpenFileSystemMode mode, | 105 OpenFileSystemMode mode, |
106 const OpenFileSystemCallback& callback) { | 106 const OpenFileSystemCallback& callback) { |
107 callback.Run(base::PLATFORM_FILE_OK); | 107 callback.Run(base::PLATFORM_FILE_OK); |
108 } | 108 } |
109 | 109 |
110 FileSystemFileUtil* TestMountPointProvider::GetFileUtil(FileSystemType type) { | 110 FileSystemFileUtil* TestFileSystemBackend::GetFileUtil(FileSystemType type) { |
111 DCHECK(local_file_util_.get()); | 111 DCHECK(local_file_util_.get()); |
112 return local_file_util_->sync_file_util(); | 112 return local_file_util_->sync_file_util(); |
113 } | 113 } |
114 | 114 |
115 AsyncFileUtil* TestMountPointProvider::GetAsyncFileUtil(FileSystemType type) { | 115 AsyncFileUtil* TestFileSystemBackend::GetAsyncFileUtil(FileSystemType type) { |
116 return local_file_util_.get(); | 116 return local_file_util_.get(); |
117 } | 117 } |
118 | 118 |
119 CopyOrMoveFileValidatorFactory* | 119 CopyOrMoveFileValidatorFactory* |
120 TestMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 120 TestFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
121 FileSystemType type, base::PlatformFileError* error_code) { | 121 FileSystemType type, base::PlatformFileError* error_code) { |
122 DCHECK(error_code); | 122 DCHECK(error_code); |
123 *error_code = base::PLATFORM_FILE_OK; | 123 *error_code = base::PLATFORM_FILE_OK; |
124 if (require_copy_or_move_validator_) { | 124 if (require_copy_or_move_validator_) { |
125 if (!copy_or_move_file_validator_factory_) | 125 if (!copy_or_move_file_validator_factory_) |
126 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 126 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
127 return copy_or_move_file_validator_factory_.get(); | 127 return copy_or_move_file_validator_factory_.get(); |
128 } | 128 } |
129 return NULL; | 129 return NULL; |
130 } | 130 } |
131 | 131 |
132 void TestMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( | 132 void TestFileSystemBackend::InitializeCopyOrMoveFileValidatorFactory( |
133 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { | 133 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { |
134 if (!require_copy_or_move_validator_) { | 134 if (!require_copy_or_move_validator_) { |
135 DCHECK(!factory); | 135 DCHECK(!factory); |
136 return; | 136 return; |
137 } | 137 } |
138 if (!copy_or_move_file_validator_factory_) | 138 if (!copy_or_move_file_validator_factory_) |
139 copy_or_move_file_validator_factory_ = factory.Pass(); | 139 copy_or_move_file_validator_factory_ = factory.Pass(); |
140 } | 140 } |
141 | 141 |
142 FileSystemOperation* TestMountPointProvider::CreateFileSystemOperation( | 142 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( |
143 const FileSystemURL& url, | 143 const FileSystemURL& url, |
144 FileSystemContext* context, | 144 FileSystemContext* context, |
145 base::PlatformFileError* error_code) const { | 145 base::PlatformFileError* error_code) const { |
146 scoped_ptr<FileSystemOperationContext> operation_context( | 146 scoped_ptr<FileSystemOperationContext> operation_context( |
147 new FileSystemOperationContext(context)); | 147 new FileSystemOperationContext(context)); |
148 operation_context->set_update_observers(update_observers_); | 148 operation_context->set_update_observers(update_observers_); |
149 operation_context->set_change_observers(change_observers_); | 149 operation_context->set_change_observers(change_observers_); |
150 operation_context->set_root_path(base_path_); | 150 operation_context->set_root_path(base_path_); |
151 return new LocalFileSystemOperation(url, context, operation_context.Pass()); | 151 return new LocalFileSystemOperation(url, context, operation_context.Pass()); |
152 } | 152 } |
153 | 153 |
154 scoped_ptr<webkit_blob::FileStreamReader> | 154 scoped_ptr<webkit_blob::FileStreamReader> |
155 TestMountPointProvider::CreateFileStreamReader( | 155 TestFileSystemBackend::CreateFileStreamReader( |
156 const FileSystemURL& url, | 156 const FileSystemURL& url, |
157 int64 offset, | 157 int64 offset, |
158 const base::Time& expected_modification_time, | 158 const base::Time& expected_modification_time, |
159 FileSystemContext* context) const { | 159 FileSystemContext* context) const { |
160 return scoped_ptr<webkit_blob::FileStreamReader>( | 160 return scoped_ptr<webkit_blob::FileStreamReader>( |
161 new FileSystemFileStreamReader( | 161 new FileSystemFileStreamReader( |
162 context, url, offset, expected_modification_time)); | 162 context, url, offset, expected_modification_time)); |
163 } | 163 } |
164 | 164 |
165 scoped_ptr<fileapi::FileStreamWriter> | 165 scoped_ptr<fileapi::FileStreamWriter> |
166 TestMountPointProvider::CreateFileStreamWriter( | 166 TestFileSystemBackend::CreateFileStreamWriter( |
167 const FileSystemURL& url, | 167 const FileSystemURL& url, |
168 int64 offset, | 168 int64 offset, |
169 FileSystemContext* context) const { | 169 FileSystemContext* context) const { |
170 return scoped_ptr<fileapi::FileStreamWriter>( | 170 return scoped_ptr<fileapi::FileStreamWriter>( |
171 new SandboxFileStreamWriter(context, url, offset, update_observers_)); | 171 new SandboxFileStreamWriter(context, url, offset, update_observers_)); |
172 } | 172 } |
173 | 173 |
174 FileSystemQuotaUtil* TestMountPointProvider::GetQuotaUtil() { | 174 FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { |
175 return quota_util_.get(); | 175 return quota_util_.get(); |
176 } | 176 } |
177 | 177 |
178 const UpdateObserverList* TestMountPointProvider::GetUpdateObservers( | 178 const UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( |
179 FileSystemType type) const { | 179 FileSystemType type) const { |
180 return &update_observers_; | 180 return &update_observers_; |
181 } | 181 } |
182 | 182 |
183 void TestMountPointProvider::AddFileChangeObserver( | 183 void TestFileSystemBackend::AddFileChangeObserver( |
184 FileChangeObserver* observer) { | 184 FileChangeObserver* observer) { |
185 ChangeObserverList::Source source = change_observers_.source(); | 185 ChangeObserverList::Source source = change_observers_.source(); |
186 source.AddObserver(observer, task_runner_.get()); | 186 source.AddObserver(observer, task_runner_.get()); |
187 change_observers_ = ChangeObserverList(source); | 187 change_observers_ = ChangeObserverList(source); |
188 } | 188 } |
189 | 189 |
190 } // namespace fileapi | 190 } // namespace fileapi |
OLD | NEW |