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 "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" 14 15 namespace base { 16 class SequencedTaskRunner; 17 } 18 19 namespace fileapi { 20 class AsyncFileUtilAdapter; 21 class FileSystemQuotaUtil; 22 } 23 24 namespace content { 25 26 // This should be only used for testing. 27 // This file system backend uses LocalFileUtil and stores data file 28 // under the given directory. 29 class TestFileSystemBackend : public fileapi::FileSystemBackend { 30 public: 31 TestFileSystemBackend( 32 base::SequencedTaskRunner* task_runner, 33 const base::FilePath& base_path); 34 virtual ~TestFileSystemBackend(); 35 36 // FileSystemBackend implementation. 37 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; 38 virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE; 39 virtual void ResolveURL(const fileapi::FileSystemURL& url, 40 fileapi::OpenFileSystemMode mode, 41 const OpenFileSystemCallback& callback) OVERRIDE; 42 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( 43 fileapi::FileSystemType type) OVERRIDE; 44 virtual fileapi::CopyOrMoveFileValidatorFactory* 45 GetCopyOrMoveFileValidatorFactory( 46 fileapi::FileSystemType type, 47 base::File::Error* error_code) OVERRIDE; 48 virtual fileapi::FileSystemOperation* CreateFileSystemOperation( 49 const fileapi::FileSystemURL& url, 50 fileapi::FileSystemContext* context, 51 base::File::Error* error_code) const OVERRIDE; 52 virtual bool SupportsStreaming( 53 const fileapi::FileSystemURL& url) const OVERRIDE; 54 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( 55 const fileapi::FileSystemURL& url, 56 int64 offset, 57 const base::Time& expected_modification_time, 58 fileapi::FileSystemContext* context) const OVERRIDE; 59 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( 60 const fileapi::FileSystemURL& url, 61 int64 offset, 62 fileapi::FileSystemContext* context) const OVERRIDE; 63 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 64 65 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than 66 // once. 67 void InitializeCopyOrMoveFileValidatorFactory( 68 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory); 69 70 const fileapi::UpdateObserverList* 71 GetUpdateObservers(fileapi::FileSystemType type) const; 72 void AddFileChangeObserver(fileapi::FileChangeObserver* observer); 73 74 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true 75 // GetCopyOrMoveFileValidatorFactory will start returning security 76 // error if validator is not initialized. 77 void set_require_copy_or_move_validator(bool flag) { 78 require_copy_or_move_validator_ = flag; 79 } 80 81 private: 82 class QuotaUtil; 83 84 base::FilePath base_path_; 85 scoped_refptr<base::SequencedTaskRunner> task_runner_; 86 scoped_ptr<fileapi::AsyncFileUtilAdapter> file_util_; 87 scoped_ptr<QuotaUtil> quota_util_; 88 89 bool require_copy_or_move_validator_; 90 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> 91 copy_or_move_file_validator_factory_; 92 93 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend); 94 }; 95 96 } // namespace content 97 98 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ 99