Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / test / test_file_system_backend.h
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   ~TestFileSystemBackend() override;
35
36   // FileSystemBackend implementation.
37   bool CanHandleType(storage::FileSystemType type) const override;
38   void Initialize(storage::FileSystemContext* context) override;
39   void ResolveURL(const storage::FileSystemURL& url,
40                   storage::OpenFileSystemMode mode,
41                   const OpenFileSystemCallback& callback) override;
42   storage::AsyncFileUtil* GetAsyncFileUtil(
43       storage::FileSystemType type) override;
44   storage::WatcherManager* GetWatcherManager(
45       storage::FileSystemType type) override;
46   storage::CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
47       storage::FileSystemType type,
48       base::File::Error* error_code) override;
49   storage::FileSystemOperation* CreateFileSystemOperation(
50       const storage::FileSystemURL& url,
51       storage::FileSystemContext* context,
52       base::File::Error* error_code) const override;
53   bool SupportsStreaming(const storage::FileSystemURL& url) const override;
54   bool HasInplaceCopyImplementation(
55       storage::FileSystemType type) const override;
56   scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
57       const storage::FileSystemURL& url,
58       int64 offset,
59       int64 max_bytes_to_read,
60       const base::Time& expected_modification_time,
61       storage::FileSystemContext* context) const override;
62   scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
63       const storage::FileSystemURL& url,
64       int64 offset,
65       storage::FileSystemContext* context) const override;
66   storage::FileSystemQuotaUtil* GetQuotaUtil() override;
67   const storage::UpdateObserverList* GetUpdateObservers(
68       storage::FileSystemType type) const override;
69   const storage::ChangeObserverList* GetChangeObservers(
70       storage::FileSystemType type) const override;
71   const storage::AccessObserverList* GetAccessObservers(
72       storage::FileSystemType type) const override;
73
74   // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than
75   // once.
76   void InitializeCopyOrMoveFileValidatorFactory(
77       scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory);
78
79   void AddFileChangeObserver(storage::FileChangeObserver* observer);
80
81   // For CopyOrMoveFileValidatorFactory testing. Once it's set to true
82   // GetCopyOrMoveFileValidatorFactory will start returning security
83   // error if validator is not initialized.
84   void set_require_copy_or_move_validator(bool flag) {
85     require_copy_or_move_validator_ = flag;
86   }
87
88  private:
89   class QuotaUtil;
90
91   base::FilePath base_path_;
92   scoped_refptr<base::SequencedTaskRunner> task_runner_;
93   scoped_ptr<storage::AsyncFileUtilAdapter> file_util_;
94   scoped_ptr<QuotaUtil> quota_util_;
95   storage::UpdateObserverList update_observers_;
96   storage::ChangeObserverList change_observers_;
97
98   bool require_copy_or_move_validator_;
99   scoped_ptr<storage::CopyOrMoveFileValidatorFactory>
100       copy_or_move_file_validator_factory_;
101
102   DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend);
103 };
104
105 }  // namespace content
106
107 #endif  // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_