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.
5 #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_
6 #define CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_
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"
16 class SequencedTaskRunner
;
20 class AsyncFileUtilAdapter
;
21 class FileSystemQuotaUtil
;
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
{
31 TestFileSystemBackend(
32 base::SequencedTaskRunner
* task_runner
,
33 const base::FilePath
& base_path
);
34 virtual ~TestFileSystemBackend();
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
,
60 const base::Time
& expected_modification_time
,
61 storage::FileSystemContext
* context
) const OVERRIDE
;
62 virtual scoped_ptr
<storage::FileStreamWriter
> CreateFileStreamWriter(
63 const storage::FileSystemURL
& url
,
65 storage::FileSystemContext
* context
) const OVERRIDE
;
66 virtual storage::FileSystemQuotaUtil
* GetQuotaUtil() OVERRIDE
;
68 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than
70 void InitializeCopyOrMoveFileValidatorFactory(
71 scoped_ptr
<storage::CopyOrMoveFileValidatorFactory
> factory
);
73 const storage::UpdateObserverList
* GetUpdateObservers(
74 storage::FileSystemType type
) const;
75 void AddFileChangeObserver(storage::FileChangeObserver
* observer
);
77 // For CopyOrMoveFileValidatorFactory testing. Once it's set to true
78 // GetCopyOrMoveFileValidatorFactory will start returning security
79 // error if validator is not initialized.
80 void set_require_copy_or_move_validator(bool flag
) {
81 require_copy_or_move_validator_
= flag
;
87 base::FilePath base_path_
;
88 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
89 scoped_ptr
<storage::AsyncFileUtilAdapter
> file_util_
;
90 scoped_ptr
<storage::WatcherManager
> watcher_manager_
;
91 scoped_ptr
<QuotaUtil
> quota_util_
;
93 bool require_copy_or_move_validator_
;
94 scoped_ptr
<storage::CopyOrMoveFileValidatorFactory
>
95 copy_or_move_file_validator_factory_
;
97 DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend
);
100 } // namespace content
102 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_