IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / public / test / test_file_system_backend.h
blobbe7f9f7cd994c2caa36e32e40322260c95a2c0e8
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_
6 #define CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "webkit/browser/fileapi/async_file_util_adapter.h"
12 #include "webkit/browser/fileapi/file_system_backend.h"
13 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h"
15 namespace base {
16 class SequencedTaskRunner;
19 namespace fileapi {
21 class AsyncFileUtilAdapter;
22 class FileSystemQuotaUtil;
24 // This should be only used for testing.
25 // This file system backend uses LocalFileUtil and stores data file
26 // under the given directory.
27 class TestFileSystemBackend : public FileSystemBackend {
28 public:
29 TestFileSystemBackend(
30 base::SequencedTaskRunner* task_runner,
31 const base::FilePath& base_path);
32 virtual ~TestFileSystemBackend();
34 // FileSystemBackend implementation.
35 virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
36 virtual void Initialize(FileSystemContext* context) OVERRIDE;
37 virtual void OpenFileSystem(
38 const GURL& origin_url,
39 FileSystemType type,
40 OpenFileSystemMode mode,
41 const OpenFileSystemCallback& callback) OVERRIDE;
42 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
43 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
44 FileSystemType type,
45 base::PlatformFileError* error_code) OVERRIDE;
46 virtual FileSystemOperation* CreateFileSystemOperation(
47 const FileSystemURL& url,
48 FileSystemContext* context,
49 base::PlatformFileError* error_code) const OVERRIDE;
50 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
51 const FileSystemURL& url,
52 int64 offset,
53 const base::Time& expected_modification_time,
54 FileSystemContext* context) const OVERRIDE;
55 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter(
56 const FileSystemURL& url,
57 int64 offset,
58 FileSystemContext* context) const OVERRIDE;
59 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
61 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than
62 // once.
63 void InitializeCopyOrMoveFileValidatorFactory(
64 scoped_ptr<CopyOrMoveFileValidatorFactory> factory);
66 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
67 void AddFileChangeObserver(FileChangeObserver* observer);
69 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true
70 // GetCopyOrMoveFileValidatorFactory will start returning security
71 // error if validator is not initialized.
72 void set_require_copy_or_move_validator(bool flag) {
73 require_copy_or_move_validator_ = flag;
76 private:
77 class QuotaUtil;
79 base::FilePath base_path_;
80 scoped_refptr<base::SequencedTaskRunner> task_runner_;
81 scoped_ptr<AsyncFileUtilAdapter> file_util_;
82 scoped_ptr<QuotaUtil> quota_util_;
84 bool require_copy_or_move_validator_;
85 scoped_ptr<CopyOrMoveFileValidatorFactory>
86 copy_or_move_file_validator_factory_;
88 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend);
91 } // namespace fileapi
93 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_