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