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 STORAGE_BROWSER_TEST_TEST_FILE_SYSTEM_BACKEND_H_ 6 #define STORAGE_BROWSER_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/file_system/async_file_util_adapter.h" 16 #include "storage/browser/file_system/file_system_backend.h" 17 #include "storage/browser/file_system/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 storage { 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 FileSystemBackend { 34 public: 35 TestFileSystemBackend(base::SequencedTaskRunner* task_runner, 36 const base::FilePath& base_path); 37 ~TestFileSystemBackend() override; 38 39 // FileSystemBackend implementation. 40 bool CanHandleType(FileSystemType type) const override; 41 void Initialize(FileSystemContext* context) override; 42 void ResolveURL(const FileSystemURL& url, 43 OpenFileSystemMode mode, 44 OpenFileSystemCallback callback) override; 45 AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) override; 46 WatcherManager* GetWatcherManager(FileSystemType type) override; 47 CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( 48 FileSystemType type, 49 base::File::Error* error_code) override; 50 FileSystemOperation* CreateFileSystemOperation( 51 const FileSystemURL& url, 52 FileSystemContext* context, 53 base::File::Error* error_code) const override; 54 bool SupportsStreaming(const FileSystemURL& url) const override; 55 bool HasInplaceCopyImplementation(FileSystemType type) const override; 56 std::unique_ptr<FileStreamReader> CreateFileStreamReader( 57 const FileSystemURL& url, 58 int64_t offset, 59 int64_t max_bytes_to_read, 60 const base::Time& expected_modification_time, 61 FileSystemContext* context) const override; 62 std::unique_ptr<FileStreamWriter> CreateFileStreamWriter( 63 const FileSystemURL& url, 64 int64_t offset, 65 FileSystemContext* context) const override; 66 FileSystemQuotaUtil* GetQuotaUtil() override; 67 const UpdateObserverList* GetUpdateObservers( 68 FileSystemType type) const override; 69 const ChangeObserverList* GetChangeObservers( 70 FileSystemType type) const override; 71 const AccessObserverList* GetAccessObservers( 72 FileSystemType type) const override; 73 74 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than 75 // once. 76 void InitializeCopyOrMoveFileValidatorFactory( 77 std::unique_ptr<CopyOrMoveFileValidatorFactory> factory); 78 79 void AddFileChangeObserver(FileChangeObserver* observer); 80 81 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true 82 // GetCopyOrMoveFileValidatorFactory will start returning security 83 // error if validator is not initialized. set_require_copy_or_move_validator(bool flag)84 void set_require_copy_or_move_validator(bool flag) { 85 require_copy_or_move_validator_ = flag; 86 } 87 88 private: 89 class QuotaUtil; 90 91 base::FilePath base_path_; 92 scoped_refptr<base::SequencedTaskRunner> task_runner_; 93 std::unique_ptr<AsyncFileUtilAdapter> file_util_; 94 std::unique_ptr<QuotaUtil> quota_util_; 95 UpdateObserverList update_observers_; 96 ChangeObserverList change_observers_; 97 98 bool require_copy_or_move_validator_; 99 std::unique_ptr<CopyOrMoveFileValidatorFactory> 100 copy_or_move_file_validator_factory_; 101 102 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend); 103 }; 104 105 } // namespace storage 106 107 #endif // STORAGE_BROWSER_TEST_TEST_FILE_SYSTEM_BACKEND_H_ 108