OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ | |
6 #define CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/files/file_path.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "storage/browser/fileapi/async_file_util_adapter.h" | |
16 #include "storage/browser/fileapi/file_system_backend.h" | |
17 #include "storage/browser/fileapi/task_runner_bound_observer_list.h" | |
18 | |
19 namespace base { | |
20 class SequencedTaskRunner; | |
21 } | |
22 | |
23 namespace storage { | |
24 class AsyncFileUtilAdapter; | |
25 class FileSystemQuotaUtil; | |
26 } | |
27 | |
28 namespace content { | |
29 | |
30 // This should be only used for testing. | |
31 // This file system backend uses LocalFileUtil and stores data file | |
32 // under the given directory. | |
33 class TestFileSystemBackend : public storage::FileSystemBackend { | |
34 public: | |
35 TestFileSystemBackend( | |
36 base::SequencedTaskRunner* task_runner, | |
37 const base::FilePath& base_path); | |
38 ~TestFileSystemBackend() override; | |
39 | |
40 // FileSystemBackend implementation. | |
41 bool CanHandleType(storage::FileSystemType type) const override; | |
42 void Initialize(storage::FileSystemContext* context) override; | |
43 void ResolveURL(const storage::FileSystemURL& url, | |
44 storage::OpenFileSystemMode mode, | |
45 const OpenFileSystemCallback& callback) override; | |
46 storage::AsyncFileUtil* GetAsyncFileUtil( | |
47 storage::FileSystemType type) override; | |
48 storage::WatcherManager* GetWatcherManager( | |
49 storage::FileSystemType type) override; | |
50 storage::CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( | |
51 storage::FileSystemType type, | |
52 base::File::Error* error_code) override; | |
53 storage::FileSystemOperation* CreateFileSystemOperation( | |
54 const storage::FileSystemURL& url, | |
55 storage::FileSystemContext* context, | |
56 base::File::Error* error_code) const override; | |
57 bool SupportsStreaming(const storage::FileSystemURL& url) const override; | |
58 bool HasInplaceCopyImplementation( | |
59 storage::FileSystemType type) const override; | |
60 std::unique_ptr<storage::FileStreamReader> CreateFileStreamReader( | |
61 const storage::FileSystemURL& url, | |
62 int64_t offset, | |
63 int64_t max_bytes_to_read, | |
64 const base::Time& expected_modification_time, | |
65 storage::FileSystemContext* context) const override; | |
66 std::unique_ptr<storage::FileStreamWriter> CreateFileStreamWriter( | |
67 const storage::FileSystemURL& url, | |
68 int64_t offset, | |
69 storage::FileSystemContext* context) const override; | |
70 storage::FileSystemQuotaUtil* GetQuotaUtil() override; | |
71 const storage::UpdateObserverList* GetUpdateObservers( | |
72 storage::FileSystemType type) const override; | |
73 const storage::ChangeObserverList* GetChangeObservers( | |
74 storage::FileSystemType type) const override; | |
75 const storage::AccessObserverList* GetAccessObservers( | |
76 storage::FileSystemType type) const override; | |
77 | |
78 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than | |
79 // once. | |
80 void InitializeCopyOrMoveFileValidatorFactory( | |
81 std::unique_ptr<storage::CopyOrMoveFileValidatorFactory> factory); | |
82 | |
83 void AddFileChangeObserver(storage::FileChangeObserver* observer); | |
84 | |
85 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true | |
86 // GetCopyOrMoveFileValidatorFactory will start returning security | |
87 // error if validator is not initialized. | |
88 void set_require_copy_or_move_validator(bool flag) { | |
89 require_copy_or_move_validator_ = flag; | |
90 } | |
91 | |
92 private: | |
93 class QuotaUtil; | |
94 | |
95 base::FilePath base_path_; | |
96 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
97 std::unique_ptr<storage::AsyncFileUtilAdapter> file_util_; | |
98 std::unique_ptr<QuotaUtil> quota_util_; | |
99 storage::UpdateObserverList update_observers_; | |
100 storage::ChangeObserverList change_observers_; | |
101 | |
102 bool require_copy_or_move_validator_; | |
103 std::unique_ptr<storage::CopyOrMoveFileValidatorFactory> | |
104 copy_or_move_file_validator_factory_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend); | |
107 }; | |
108 | |
109 } // namespace content | |
110 | |
111 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ | |
OLD | NEW |