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