Home | History | Annotate | Download | only in test
      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 "storage/browser/fileapi/async_file_util_adapter.h"
     12 #include "storage/browser/fileapi/file_system_backend.h"
     13 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
     14 
     15 namespace base {
     16 class SequencedTaskRunner;
     17 }
     18 
     19 namespace storage {
     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 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::WatcherManager* GetWatcherManager(
     45       storage::FileSystemType type) OVERRIDE;
     46   virtual storage::CopyOrMoveFileValidatorFactory*
     47       GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type,
     48                                         base::File::Error* error_code) OVERRIDE;
     49   virtual storage::FileSystemOperation* CreateFileSystemOperation(
     50       const storage::FileSystemURL& url,
     51       storage::FileSystemContext* context,
     52       base::File::Error* error_code) const OVERRIDE;
     53   virtual bool SupportsStreaming(
     54       const storage::FileSystemURL& url) const OVERRIDE;
     55   virtual bool HasInplaceCopyImplementation(
     56       storage::FileSystemType type) const OVERRIDE;
     57   virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
     58       const storage::FileSystemURL& url,
     59       int64 offset,
     60       int64 max_bytes_to_read,
     61       const base::Time& expected_modification_time,
     62       storage::FileSystemContext* context) const OVERRIDE;
     63   virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
     64       const storage::FileSystemURL& url,
     65       int64 offset,
     66       storage::FileSystemContext* context) const OVERRIDE;
     67   virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
     68   virtual const storage::UpdateObserverList* GetUpdateObservers(
     69       storage::FileSystemType type) const OVERRIDE;
     70   virtual const storage::ChangeObserverList* GetChangeObservers(
     71       storage::FileSystemType type) const OVERRIDE;
     72   virtual const storage::AccessObserverList* GetAccessObservers(
     73       storage::FileSystemType type) const OVERRIDE;
     74 
     75   // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than
     76   // once.
     77   void InitializeCopyOrMoveFileValidatorFactory(
     78       scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory);
     79 
     80   void AddFileChangeObserver(storage::FileChangeObserver* observer);
     81 
     82   // For CopyOrMoveFileValidatorFactory testing. Once it's set to true
     83   // GetCopyOrMoveFileValidatorFactory will start returning security
     84   // error if validator is not initialized.
     85   void set_require_copy_or_move_validator(bool flag) {
     86     require_copy_or_move_validator_ = flag;
     87   }
     88 
     89  private:
     90   class QuotaUtil;
     91 
     92   base::FilePath base_path_;
     93   scoped_refptr<base::SequencedTaskRunner> task_runner_;
     94   scoped_ptr<storage::AsyncFileUtilAdapter> file_util_;
     95   scoped_ptr<storage::WatcherManager> watcher_manager_;
     96   scoped_ptr<QuotaUtil> quota_util_;
     97   storage::UpdateObserverList update_observers_;
     98   storage::ChangeObserverList change_observers_;
     99 
    100   bool require_copy_or_move_validator_;
    101   scoped_ptr<storage::CopyOrMoveFileValidatorFactory>
    102       copy_or_move_file_validator_factory_;
    103 
    104   DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend);
    105 };
    106 
    107 }  // namespace content
    108 
    109 #endif  // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_
    110