blob: e828f8f531b8f5980b7bc2811bdc4f5942b1c13c [file] [log] [blame]
[email protected]6faad822012-05-11 12:58:291// 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#include "webkit/fileapi/test_mount_point_provider.h"
6
7#include <set>
8#include <string>
9#include <vector>
10
11#include "base/file_util.h"
12#include "base/sequenced_task_runner.h"
[email protected]98407ee2013-04-04 08:52:1713#include "webkit/fileapi/copy_or_move_file_validator.h"
[email protected]caf66702012-09-07 07:02:2014#include "webkit/fileapi/file_observers.h"
[email protected]c4ca3b452012-05-31 03:15:4615#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]5f7782682013-03-04 02:43:3516#include "webkit/fileapi/file_system_operation_context.h"
[email protected]6faad822012-05-11 12:58:2917#include "webkit/fileapi/file_system_quota_util.h"
[email protected]7e836a3d2012-05-31 05:14:5918#include "webkit/fileapi/file_system_util.h"
[email protected]02a60542012-07-24 20:05:3319#include "webkit/fileapi/local_file_system_operation.h"
[email protected]6faad822012-05-11 12:58:2920#include "webkit/fileapi/local_file_util.h"
21#include "webkit/fileapi/native_file_util.h"
[email protected]74698902012-06-12 12:16:3822#include "webkit/fileapi/sandbox_file_stream_writer.h"
[email protected]6faad822012-05-11 12:58:2923#include "webkit/quota/quota_manager.h"
24
25namespace fileapi {
26
[email protected]6faad822012-05-11 12:58:2927// This only supports single origin.
[email protected]caf66702012-09-07 07:02:2028class TestMountPointProvider::QuotaUtil
29 : public FileSystemQuotaUtil,
30 public FileUpdateObserver {
[email protected]6faad822012-05-11 12:58:2931 public:
[email protected]caf66702012-09-07 07:02:2032 QuotaUtil() : usage_(0) {}
33 virtual ~QuotaUtil() {}
[email protected]6faad822012-05-11 12:58:2934
[email protected]caf66702012-09-07 07:02:2035 // FileSystemQuotaUtil overrides.
[email protected]6faad822012-05-11 12:58:2936 virtual void GetOriginsForTypeOnFileThread(
37 FileSystemType type,
38 std::set<GURL>* origins) OVERRIDE {
39 NOTREACHED();
40 }
41 virtual void GetOriginsForHostOnFileThread(
42 FileSystemType type,
43 const std::string& host,
44 std::set<GURL>* origins) OVERRIDE {
45 NOTREACHED();
46 }
47 virtual int64 GetOriginUsageOnFileThread(
[email protected]22894522012-05-23 07:14:5848 FileSystemContext* context,
[email protected]6faad822012-05-11 12:58:2949 const GURL& origin_url,
50 FileSystemType type) OVERRIDE {
51 return usage_;
52 }
[email protected]6faad822012-05-11 12:58:2953 virtual void InvalidateUsageCache(const GURL& origin_url,
54 FileSystemType type) OVERRIDE {
55 // Do nothing.
56 }
57
[email protected]caf66702012-09-07 07:02:2058 // FileUpdateObserver overrides.
59 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {}
60 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE {
61 usage_ += delta;
62 }
63 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {}
64
[email protected]6faad822012-05-11 12:58:2965 private:
66 int64 usage_;
67};
68
[email protected]6faad822012-05-11 12:58:2969TestMountPointProvider::TestMountPointProvider(
70 base::SequencedTaskRunner* task_runner,
[email protected]a3ef4832013-02-02 05:12:3371 const base::FilePath& base_path)
[email protected]6faad822012-05-11 12:58:2972 : base_path_(base_path),
[email protected]caf66702012-09-07 07:02:2073 task_runner_(task_runner),
[email protected]25b697992013-01-29 07:10:0574 local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
[email protected]caf66702012-09-07 07:02:2075 quota_util_(new QuotaUtil) {
76 UpdateObserverList::Source source;
77 source.AddObserver(quota_util_.get(), task_runner_);
78 observers_ = UpdateObserverList(source);
[email protected]6faad822012-05-11 12:58:2979}
80
81TestMountPointProvider::~TestMountPointProvider() {
82}
83
84void TestMountPointProvider::ValidateFileSystemRoot(
85 const GURL& origin_url,
86 FileSystemType type,
87 bool create,
88 const ValidateFileSystemCallback& callback) {
89 // This won't be called unless we add test code that opens a test
90 // filesystem by OpenFileSystem.
91 NOTREACHED();
92}
93
[email protected]a3ef4832013-02-02 05:12:3394base::FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread(
[email protected]199263e2012-12-14 07:14:2095 const FileSystemURL& url,
[email protected]6faad822012-05-11 12:58:2996 bool create) {
[email protected]199263e2012-12-14 07:14:2097 DCHECK_EQ(kFileSystemTypeTest, url.type());
[email protected]6faad822012-05-11 12:58:2998 bool success = true;
99 if (create)
100 success = file_util::CreateDirectory(base_path_);
101 else
102 success = file_util::DirectoryExists(base_path_);
[email protected]a3ef4832013-02-02 05:12:33103 return success ? base_path_ : base::FilePath();
[email protected]6faad822012-05-11 12:58:29104}
105
[email protected]d6afd112012-07-25 22:55:04106FileSystemFileUtil* TestMountPointProvider::GetFileUtil(FileSystemType type) {
[email protected]25b697992013-01-29 07:10:05107 DCHECK(local_file_util_.get());
108 return local_file_util_->sync_file_util();
109}
110
111AsyncFileUtil* TestMountPointProvider::GetAsyncFileUtil(FileSystemType type) {
[email protected]6faad822012-05-11 12:58:29112 return local_file_util_.get();
113}
114
[email protected]98407ee2013-04-04 08:52:17115CopyOrMoveFileValidatorFactory*
116TestMountPointProvider::GetCopyOrMoveFileValidatorFactory(
117 FileSystemType type, base::PlatformFileError* error_code) {
118 DCHECK(error_code);
119 *error_code = base::PLATFORM_FILE_OK;
120 return NULL;
121}
122
123void TestMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
124 FileSystemType type, scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
125 DCHECK(!factory);
126}
127
[email protected]b40ffe72013-01-10 04:05:31128FilePermissionPolicy TestMountPointProvider::GetPermissionPolicy(
129 const FileSystemURL& url, int permissions) const {
130 return FILE_PERMISSION_ALWAYS_DENY;
[email protected]6faad822012-05-11 12:58:29131}
132
[email protected]8e3bc3e2012-08-24 13:12:53133FileSystemOperation* TestMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09134 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:13135 FileSystemContext* context,
136 base::PlatformFileError* error_code) const {
[email protected]75af1a42012-07-26 04:06:20137 scoped_ptr<FileSystemOperationContext> operation_context(
138 new FileSystemOperationContext(context));
[email protected]caf66702012-09-07 07:02:20139 operation_context->set_update_observers(observers_);
[email protected]75af1a42012-07-26 04:06:20140 return new LocalFileSystemOperation(context, operation_context.Pass());
[email protected]6faad822012-05-11 12:58:29141}
142
[email protected]3ee9eb02013-04-10 09:17:05143scoped_ptr<webkit_blob::FileStreamReader>
144TestMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09145 const FileSystemURL& url,
[email protected]6faad822012-05-11 12:58:29146 int64 offset,
[email protected]a1057832012-10-15 13:28:06147 const base::Time& expected_modification_time,
[email protected]6faad822012-05-11 12:58:29148 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05149 return scoped_ptr<webkit_blob::FileStreamReader>(
150 new FileSystemFileStreamReader(
151 context, url, offset, expected_modification_time));
[email protected]6faad822012-05-11 12:58:29152}
153
[email protected]3ee9eb02013-04-10 09:17:05154scoped_ptr<fileapi::FileStreamWriter>
155TestMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09156 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01157 int64 offset,
158 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05159 return scoped_ptr<fileapi::FileStreamWriter>(
160 new SandboxFileStreamWriter(context, url, offset, observers_));
[email protected]7e84b912012-05-16 04:42:01161}
162
[email protected]6faad822012-05-11 12:58:29163FileSystemQuotaUtil* TestMountPointProvider::GetQuotaUtil() {
164 return quota_util_.get();
165}
166
[email protected]d5e08552012-08-02 21:43:40167void TestMountPointProvider::DeleteFileSystem(
168 const GURL& origin_url,
169 FileSystemType type,
170 FileSystemContext* context,
171 const DeleteFileSystemCallback& callback) {
172 // This won't be called unless we add test code that opens a test
173 // filesystem by OpenFileSystem.
174 NOTREACHED();
175 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
176}
177
[email protected]caf66702012-09-07 07:02:20178const UpdateObserverList* TestMountPointProvider::GetUpdateObservers(
179 FileSystemType type) const {
180 return &observers_;
181}
182
[email protected]6faad822012-05-11 12:58:29183} // namespace fileapi