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 #include "content/public/test/test_file_system_backend.h" | 5 #include "content/public/test/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 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 base::WeakPtrFactory<TestWatcherManager> weak_ptr_factory_; | 152 base::WeakPtrFactory<TestWatcherManager> weak_ptr_factory_; |
153 }; | 153 }; |
154 | 154 |
155 } // namespace | 155 } // namespace |
156 | 156 |
157 // This only supports single origin. | 157 // This only supports single origin. |
158 class TestFileSystemBackend::QuotaUtil : public storage::FileSystemQuotaUtil, | 158 class TestFileSystemBackend::QuotaUtil : public storage::FileSystemQuotaUtil, |
159 public storage::FileUpdateObserver { | 159 public storage::FileUpdateObserver { |
160 public: | 160 public: |
161 explicit QuotaUtil(base::SequencedTaskRunner* task_runner) | 161 QuotaUtil() : usage_(0) {} |
162 : usage_(0), | |
163 task_runner_(task_runner) { | |
164 update_observers_ = update_observers_.AddObserver(this, task_runner_.get()); | |
165 } | |
166 virtual ~QuotaUtil() {} | 162 virtual ~QuotaUtil() {} |
167 | 163 |
168 // FileSystemQuotaUtil overrides. | 164 // FileSystemQuotaUtil overrides. |
169 virtual base::File::Error DeleteOriginDataOnFileTaskRunner( | 165 virtual base::File::Error DeleteOriginDataOnFileTaskRunner( |
170 FileSystemContext* context, | 166 FileSystemContext* context, |
171 storage::QuotaManagerProxy* proxy, | 167 storage::QuotaManagerProxy* proxy, |
172 const GURL& origin_url, | 168 const GURL& origin_url, |
173 storage::FileSystemType type) OVERRIDE { | 169 storage::FileSystemType type) OVERRIDE { |
174 NOTREACHED(); | 170 NOTREACHED(); |
175 return base::File::FILE_OK; | 171 return base::File::FILE_OK; |
(...skipping 20 matching lines...) Expand all Loading... |
196 NOTREACHED(); | 192 NOTREACHED(); |
197 } | 193 } |
198 | 194 |
199 virtual int64 GetOriginUsageOnFileTaskRunner( | 195 virtual int64 GetOriginUsageOnFileTaskRunner( |
200 FileSystemContext* context, | 196 FileSystemContext* context, |
201 const GURL& origin_url, | 197 const GURL& origin_url, |
202 storage::FileSystemType type) OVERRIDE { | 198 storage::FileSystemType type) OVERRIDE { |
203 return usage_; | 199 return usage_; |
204 } | 200 } |
205 | 201 |
206 virtual void AddFileUpdateObserver( | |
207 storage::FileSystemType type, | |
208 FileUpdateObserver* observer, | |
209 base::SequencedTaskRunner* task_runner) OVERRIDE { | |
210 NOTIMPLEMENTED(); | |
211 } | |
212 | |
213 virtual void AddFileChangeObserver( | |
214 storage::FileSystemType type, | |
215 storage::FileChangeObserver* observer, | |
216 base::SequencedTaskRunner* task_runner) OVERRIDE { | |
217 change_observers_ = change_observers_.AddObserver(observer, task_runner); | |
218 } | |
219 | |
220 virtual void AddFileAccessObserver( | |
221 storage::FileSystemType type, | |
222 storage::FileAccessObserver* observer, | |
223 base::SequencedTaskRunner* task_runner) OVERRIDE { | |
224 NOTIMPLEMENTED(); | |
225 } | |
226 | |
227 virtual const storage::UpdateObserverList* GetUpdateObservers( | |
228 storage::FileSystemType type) const OVERRIDE { | |
229 return &update_observers_; | |
230 } | |
231 | |
232 virtual const storage::ChangeObserverList* GetChangeObservers( | |
233 storage::FileSystemType type) const OVERRIDE { | |
234 return &change_observers_; | |
235 } | |
236 | |
237 virtual const storage::AccessObserverList* GetAccessObservers( | |
238 storage::FileSystemType type) const OVERRIDE { | |
239 return NULL; | |
240 } | |
241 | |
242 // FileUpdateObserver overrides. | 202 // FileUpdateObserver overrides. |
243 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} | 203 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} |
244 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { | 204 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { |
245 usage_ += delta; | 205 usage_ += delta; |
246 } | 206 } |
247 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} | 207 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} |
248 | 208 |
249 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } | |
250 | |
251 private: | 209 private: |
252 int64 usage_; | 210 int64 usage_; |
253 | 211 DISALLOW_COPY_AND_ASSIGN(QuotaUtil); |
254 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
255 | |
256 storage::UpdateObserverList update_observers_; | |
257 storage::ChangeObserverList change_observers_; | |
258 }; | 212 }; |
259 | 213 |
260 TestFileSystemBackend::TestFileSystemBackend( | 214 TestFileSystemBackend::TestFileSystemBackend( |
261 base::SequencedTaskRunner* task_runner, | 215 base::SequencedTaskRunner* task_runner, |
262 const base::FilePath& base_path) | 216 const base::FilePath& base_path) |
263 : base_path_(base_path), | 217 : base_path_(base_path), |
| 218 task_runner_(task_runner), |
264 file_util_( | 219 file_util_( |
265 new storage::AsyncFileUtilAdapter(new TestFileUtil(base_path))), | 220 new storage::AsyncFileUtilAdapter(new TestFileUtil(base_path))), |
266 watcher_manager_(new TestWatcherManager()), | 221 watcher_manager_(new TestWatcherManager()), |
267 quota_util_(new QuotaUtil(task_runner)), | 222 quota_util_(new QuotaUtil), |
268 require_copy_or_move_validator_(false) { | 223 require_copy_or_move_validator_(false) { |
| 224 update_observers_ = |
| 225 update_observers_.AddObserver(quota_util_.get(), task_runner_.get()); |
269 } | 226 } |
270 | 227 |
271 TestFileSystemBackend::~TestFileSystemBackend() { | 228 TestFileSystemBackend::~TestFileSystemBackend() { |
272 } | 229 } |
273 | 230 |
274 bool TestFileSystemBackend::CanHandleType(storage::FileSystemType type) const { | 231 bool TestFileSystemBackend::CanHandleType(storage::FileSystemType type) const { |
275 return (type == storage::kFileSystemTypeTest); | 232 return (type == storage::kFileSystemTypeTest); |
276 } | 233 } |
277 | 234 |
278 void TestFileSystemBackend::Initialize(FileSystemContext* context) { | 235 void TestFileSystemBackend::Initialize(FileSystemContext* context) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 copy_or_move_file_validator_factory_ = factory.Pass(); | 273 copy_or_move_file_validator_factory_ = factory.Pass(); |
317 } | 274 } |
318 | 275 |
319 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( | 276 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( |
320 const FileSystemURL& url, | 277 const FileSystemURL& url, |
321 FileSystemContext* context, | 278 FileSystemContext* context, |
322 base::File::Error* error_code) const { | 279 base::File::Error* error_code) const { |
323 scoped_ptr<FileSystemOperationContext> operation_context( | 280 scoped_ptr<FileSystemOperationContext> operation_context( |
324 new FileSystemOperationContext(context)); | 281 new FileSystemOperationContext(context)); |
325 operation_context->set_update_observers(*GetUpdateObservers(url.type())); | 282 operation_context->set_update_observers(*GetUpdateObservers(url.type())); |
326 operation_context->set_change_observers( | 283 operation_context->set_change_observers(*GetChangeObservers(url.type())); |
327 *quota_util_->GetChangeObservers(url.type())); | |
328 return FileSystemOperation::Create(url, context, operation_context.Pass()); | 284 return FileSystemOperation::Create(url, context, operation_context.Pass()); |
329 } | 285 } |
330 | 286 |
331 bool TestFileSystemBackend::SupportsStreaming( | 287 bool TestFileSystemBackend::SupportsStreaming( |
332 const storage::FileSystemURL& url) const { | 288 const storage::FileSystemURL& url) const { |
333 return false; | 289 return false; |
334 } | 290 } |
335 | 291 |
336 bool TestFileSystemBackend::HasInplaceCopyImplementation( | 292 bool TestFileSystemBackend::HasInplaceCopyImplementation( |
337 storage::FileSystemType type) const { | 293 storage::FileSystemType type) const { |
(...skipping 20 matching lines...) Expand all Loading... |
358 new storage::SandboxFileStreamWriter( | 314 new storage::SandboxFileStreamWriter( |
359 context, url, offset, *GetUpdateObservers(url.type()))); | 315 context, url, offset, *GetUpdateObservers(url.type()))); |
360 } | 316 } |
361 | 317 |
362 storage::FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { | 318 storage::FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { |
363 return quota_util_.get(); | 319 return quota_util_.get(); |
364 } | 320 } |
365 | 321 |
366 const storage::UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( | 322 const storage::UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( |
367 storage::FileSystemType type) const { | 323 storage::FileSystemType type) const { |
368 return quota_util_->GetUpdateObservers(type); | 324 return &update_observers_; |
| 325 } |
| 326 |
| 327 const storage::ChangeObserverList* TestFileSystemBackend::GetChangeObservers( |
| 328 storage::FileSystemType type) const { |
| 329 return &change_observers_; |
| 330 } |
| 331 |
| 332 const storage::AccessObserverList* TestFileSystemBackend::GetAccessObservers( |
| 333 storage::FileSystemType type) const { |
| 334 return NULL; |
369 } | 335 } |
370 | 336 |
371 void TestFileSystemBackend::AddFileChangeObserver( | 337 void TestFileSystemBackend::AddFileChangeObserver( |
372 storage::FileChangeObserver* observer) { | 338 storage::FileChangeObserver* observer) { |
373 quota_util_->AddFileChangeObserver( | 339 change_observers_ = |
374 storage::kFileSystemTypeTest, observer, quota_util_->task_runner()); | 340 change_observers_.AddObserver(observer, task_runner_.get()); |
375 } | 341 } |
376 | 342 |
377 } // namespace content | 343 } // namespace content |
OLD | NEW |