[email protected] | d77ecbf6 | 2013-10-02 06:43:08 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d77ecbf6 | 2013-10-02 06:43:08 | [diff] [blame] | 5 | #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ |
| 6 | #define CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 7 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 11 | #include "webkit/browser/fileapi/async_file_util_adapter.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 12 | #include "webkit/browser/fileapi/file_system_backend.h" |
[email protected] | f25e113 | 2013-05-24 13:58:04 | [diff] [blame] | 13 | #include "webkit/browser/fileapi/task_runner_bound_observer_list.h" |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | class SequencedTaskRunner; |
| 17 | } |
| 18 | |
| 19 | namespace fileapi { |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 20 | class AsyncFileUtilAdapter; |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 21 | class FileSystemQuotaUtil; |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | namespace content { |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 25 | |
| 26 | // This should be only used for testing. |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 27 | // This file system backend uses LocalFileUtil and stores data file |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 28 | // under the given directory. |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 29 | class TestFileSystemBackend : public fileapi::FileSystemBackend { |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 30 | public: |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 31 | TestFileSystemBackend( |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 32 | base::SequencedTaskRunner* task_runner, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 33 | const base::FilePath& base_path); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 34 | virtual ~TestFileSystemBackend(); |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 35 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 36 | // FileSystemBackend implementation. |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 37 | virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; |
| 38 | virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE; |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 39 | virtual void OpenFileSystem( |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 40 | const GURL& origin_url, |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 41 | fileapi::FileSystemType type, |
| 42 | fileapi::OpenFileSystemMode mode, |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 43 | const OpenFileSystemCallback& callback) OVERRIDE; |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 44 | virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( |
| 45 | fileapi::FileSystemType type) OVERRIDE; |
| 46 | virtual fileapi::CopyOrMoveFileValidatorFactory* |
| 47 | GetCopyOrMoveFileValidatorFactory( |
| 48 | fileapi::FileSystemType type, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame^] | 49 | base::File::Error* error_code) OVERRIDE; |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 50 | virtual fileapi::FileSystemOperation* CreateFileSystemOperation( |
| 51 | const fileapi::FileSystemURL& url, |
| 52 | fileapi::FileSystemContext* context, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame^] | 53 | base::File::Error* error_code) const OVERRIDE; |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 54 | virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 55 | const fileapi::FileSystemURL& url, |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 56 | int64 offset, |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame] | 57 | const base::Time& expected_modification_time, |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 58 | fileapi::FileSystemContext* context) const OVERRIDE; |
| 59 | virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( |
| 60 | const fileapi::FileSystemURL& url, |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 61 | int64 offset, |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 62 | fileapi::FileSystemContext* context) const OVERRIDE; |
| 63 | virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 64 | |
[email protected] | 96f03c4 | 2013-05-29 08:51:32 | [diff] [blame] | 65 | // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than |
| 66 | // once. |
| 67 | void InitializeCopyOrMoveFileValidatorFactory( |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 68 | scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory); |
[email protected] | 96f03c4 | 2013-05-29 08:51:32 | [diff] [blame] | 69 | |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 70 | const fileapi::UpdateObserverList* |
| 71 | GetUpdateObservers(fileapi::FileSystemType type) const; |
| 72 | void AddFileChangeObserver(fileapi::FileChangeObserver* observer); |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 73 | |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 74 | // For CopyOrMoveFileValidatorFactory testing. Once it's set to true |
| 75 | // GetCopyOrMoveFileValidatorFactory will start returning security |
| 76 | // error if validator is not initialized. |
| 77 | void set_require_copy_or_move_validator(bool flag) { |
| 78 | require_copy_or_move_validator_ = flag; |
| 79 | } |
| 80 | |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 81 | private: |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 82 | class QuotaUtil; |
| 83 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 84 | base::FilePath base_path_; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 85 | scoped_refptr<base::SequencedTaskRunner> task_runner_; |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 86 | scoped_ptr<fileapi::AsyncFileUtilAdapter> file_util_; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 87 | scoped_ptr<QuotaUtil> quota_util_; |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 88 | |
| 89 | bool require_copy_or_move_validator_; |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 90 | scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 91 | copy_or_move_file_validator_factory_; |
| 92 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(TestFileSystemBackend); |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 94 | }; |
| 95 | |
[email protected] | 7ade66ee | 2014-01-16 17:35:53 | [diff] [blame] | 96 | } // namespace content |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 97 | |
[email protected] | d77ecbf6 | 2013-10-02 06:43:08 | [diff] [blame] | 98 | #endif // CONTENT_PUBLIC_TEST_TEST_FILE_SYSTEM_BACKEND_H_ |