test_file_system_backend.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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 15namespace base { 16class SequencedTaskRunner; 17} 18 19namespace storage { 20class AsyncFileUtilAdapter; 21class FileSystemQuotaUtil; 22} 23 24namespace 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. 29class TestFileSystemBackend : public storage::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(storage::FileSystemType type) const OVERRIDE; 38 virtual void Initialize(storage::FileSystemContext* context) OVERRIDE; 39 virtual void ResolveURL(const storage::FileSystemURL& url, 40 storage::OpenFileSystemMode mode, 41 const OpenFileSystemCallback& callback) OVERRIDE; 42 virtual storage::AsyncFileUtil* GetAsyncFileUtil( 43 storage::FileSystemType type) OVERRIDE; 44 virtual storage::CopyOrMoveFileValidatorFactory* 45 GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type, 46 base::File::Error* error_code) OVERRIDE; 47 virtual storage::FileSystemOperation* CreateFileSystemOperation( 48 const storage::FileSystemURL& url, 49 storage::FileSystemContext* context, 50 base::File::Error* error_code) const OVERRIDE; 51 virtual bool SupportsStreaming( 52 const storage::FileSystemURL& url) const OVERRIDE; 53 virtual bool HasInplaceCopyImplementation( 54 storage::FileSystemType type) const OVERRIDE; 55 virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader( 56 const storage::FileSystemURL& url, 57 int64 offset, 58 const base::Time& expected_modification_time, 59 storage::FileSystemContext* context) const OVERRIDE; 60 virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter( 61 const storage::FileSystemURL& url, 62 int64 offset, 63 storage::FileSystemContext* context) const OVERRIDE; 64 virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 65 66 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than 67 // once. 68 void InitializeCopyOrMoveFileValidatorFactory( 69 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory); 70 71 const storage::UpdateObserverList* GetUpdateObservers( 72 storage::FileSystemType type) const; 73 void AddFileChangeObserver(storage::FileChangeObserver* observer); 74 75 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true 76 // GetCopyOrMoveFileValidatorFactory will start returning security 77 // error if validator is not initialized. 78 void set_require_copy_or_move_validator(bool flag) { 79 require_copy_or_move_validator_ = flag; 80 } 81 82 private: 83 class QuotaUtil; 84 85 base::FilePath base_path_; 86 scoped_refptr<base::SequencedTaskRunner> task_runner_; 87 scoped_ptr<storage::AsyncFileUtilAdapter> file_util_; 88 scoped_ptr<QuotaUtil> quota_util_; 89 90 bool require_copy_or_move_validator_; 91 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> 92 copy_or_move_file_validator_factory_; 93 94 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend); 95}; 96 97} // namespace content 98 99#endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ 100