OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/test_file_system_backend.h" | 5 #include "content/public/test/test_file_system_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "webkit/browser/blob/file_stream_reader.h" | 13 #include "storage/browser/blob/file_stream_reader.h" |
14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 14 #include "storage/browser/fileapi/copy_or_move_file_validator.h" |
15 #include "webkit/browser/fileapi/file_observers.h" | 15 #include "storage/browser/fileapi/file_observers.h" |
16 #include "webkit/browser/fileapi/file_system_operation.h" | 16 #include "storage/browser/fileapi/file_system_operation.h" |
17 #include "webkit/browser/fileapi/file_system_operation_context.h" | 17 #include "storage/browser/fileapi/file_system_operation_context.h" |
18 #include "webkit/browser/fileapi/file_system_quota_util.h" | 18 #include "storage/browser/fileapi/file_system_quota_util.h" |
19 #include "webkit/browser/fileapi/local_file_util.h" | 19 #include "storage/browser/fileapi/local_file_util.h" |
20 #include "webkit/browser/fileapi/native_file_util.h" | 20 #include "storage/browser/fileapi/native_file_util.h" |
21 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 21 #include "storage/browser/fileapi/quota/quota_reservation.h" |
22 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 22 #include "storage/browser/fileapi/sandbox_file_stream_writer.h" |
23 #include "webkit/browser/quota/quota_manager.h" | 23 #include "storage/browser/quota/quota_manager.h" |
24 #include "webkit/common/fileapi/file_system_util.h" | 24 #include "storage/common/fileapi/file_system_util.h" |
25 | 25 |
26 using fileapi::FileSystemContext; | 26 using storage::FileSystemContext; |
27 using fileapi::FileSystemOperation; | 27 using storage::FileSystemOperation; |
28 using fileapi::FileSystemOperationContext; | 28 using storage::FileSystemOperationContext; |
29 using fileapi::FileSystemURL; | 29 using storage::FileSystemURL; |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 class TestFileUtil : public fileapi::LocalFileUtil { | 35 class TestFileUtil : public storage::LocalFileUtil { |
36 public: | 36 public: |
37 explicit TestFileUtil(const base::FilePath& base_path) | 37 explicit TestFileUtil(const base::FilePath& base_path) |
38 : base_path_(base_path) {} | 38 : base_path_(base_path) {} |
39 virtual ~TestFileUtil() {} | 39 virtual ~TestFileUtil() {} |
40 | 40 |
41 // LocalFileUtil overrides. | 41 // LocalFileUtil overrides. |
42 virtual base::File::Error GetLocalFilePath( | 42 virtual base::File::Error GetLocalFilePath( |
43 FileSystemOperationContext* context, | 43 FileSystemOperationContext* context, |
44 const FileSystemURL& file_system_url, | 44 const FileSystemURL& file_system_url, |
45 base::FilePath* local_file_path) OVERRIDE { | 45 base::FilePath* local_file_path) OVERRIDE { |
46 *local_file_path = base_path_.Append(file_system_url.path()); | 46 *local_file_path = base_path_.Append(file_system_url.path()); |
47 return base::File::FILE_OK; | 47 return base::File::FILE_OK; |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 base::FilePath base_path_; | 51 base::FilePath base_path_; |
52 }; | 52 }; |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 // This only supports single origin. | 56 // This only supports single origin. |
57 class TestFileSystemBackend::QuotaUtil | 57 class TestFileSystemBackend::QuotaUtil : public storage::FileSystemQuotaUtil, |
58 : public fileapi::FileSystemQuotaUtil, | 58 public storage::FileUpdateObserver { |
59 public fileapi::FileUpdateObserver { | |
60 public: | 59 public: |
61 explicit QuotaUtil(base::SequencedTaskRunner* task_runner) | 60 explicit QuotaUtil(base::SequencedTaskRunner* task_runner) |
62 : usage_(0), | 61 : usage_(0), |
63 task_runner_(task_runner) { | 62 task_runner_(task_runner) { |
64 update_observers_ = update_observers_.AddObserver(this, task_runner_.get()); | 63 update_observers_ = update_observers_.AddObserver(this, task_runner_.get()); |
65 } | 64 } |
66 virtual ~QuotaUtil() {} | 65 virtual ~QuotaUtil() {} |
67 | 66 |
68 // FileSystemQuotaUtil overrides. | 67 // FileSystemQuotaUtil overrides. |
69 virtual base::File::Error DeleteOriginDataOnFileTaskRunner( | 68 virtual base::File::Error DeleteOriginDataOnFileTaskRunner( |
70 FileSystemContext* context, | 69 FileSystemContext* context, |
71 quota::QuotaManagerProxy* proxy, | 70 quota::QuotaManagerProxy* proxy, |
72 const GURL& origin_url, | 71 const GURL& origin_url, |
73 fileapi::FileSystemType type) OVERRIDE { | 72 storage::FileSystemType type) OVERRIDE { |
74 NOTREACHED(); | 73 NOTREACHED(); |
75 return base::File::FILE_OK; | 74 return base::File::FILE_OK; |
76 } | 75 } |
77 | 76 |
78 virtual scoped_refptr<fileapi::QuotaReservation> | 77 virtual scoped_refptr<storage::QuotaReservation> |
79 CreateQuotaReservationOnFileTaskRunner( | 78 CreateQuotaReservationOnFileTaskRunner( |
80 const GURL& origin_url, | 79 const GURL& origin_url, |
81 fileapi::FileSystemType type) OVERRIDE { | 80 storage::FileSystemType type) OVERRIDE { |
82 NOTREACHED(); | 81 NOTREACHED(); |
83 return scoped_refptr<fileapi::QuotaReservation>(); | 82 return scoped_refptr<storage::QuotaReservation>(); |
84 } | 83 } |
85 | 84 |
86 virtual void GetOriginsForTypeOnFileTaskRunner( | 85 virtual void GetOriginsForTypeOnFileTaskRunner( |
87 fileapi::FileSystemType type, | 86 storage::FileSystemType type, |
88 std::set<GURL>* origins) OVERRIDE { | 87 std::set<GURL>* origins) OVERRIDE { |
89 NOTREACHED(); | 88 NOTREACHED(); |
90 } | 89 } |
91 | 90 |
92 virtual void GetOriginsForHostOnFileTaskRunner( | 91 virtual void GetOriginsForHostOnFileTaskRunner( |
93 fileapi::FileSystemType type, | 92 storage::FileSystemType type, |
94 const std::string& host, | 93 const std::string& host, |
95 std::set<GURL>* origins) OVERRIDE { | 94 std::set<GURL>* origins) OVERRIDE { |
96 NOTREACHED(); | 95 NOTREACHED(); |
97 } | 96 } |
98 | 97 |
99 virtual int64 GetOriginUsageOnFileTaskRunner( | 98 virtual int64 GetOriginUsageOnFileTaskRunner( |
100 FileSystemContext* context, | 99 FileSystemContext* context, |
101 const GURL& origin_url, | 100 const GURL& origin_url, |
102 fileapi::FileSystemType type) OVERRIDE { | 101 storage::FileSystemType type) OVERRIDE { |
103 return usage_; | 102 return usage_; |
104 } | 103 } |
105 | 104 |
106 virtual void AddFileUpdateObserver( | 105 virtual void AddFileUpdateObserver( |
107 fileapi::FileSystemType type, | 106 storage::FileSystemType type, |
108 FileUpdateObserver* observer, | 107 FileUpdateObserver* observer, |
109 base::SequencedTaskRunner* task_runner) OVERRIDE { | 108 base::SequencedTaskRunner* task_runner) OVERRIDE { |
110 NOTIMPLEMENTED(); | 109 NOTIMPLEMENTED(); |
111 } | 110 } |
112 | 111 |
113 virtual void AddFileChangeObserver( | 112 virtual void AddFileChangeObserver( |
114 fileapi::FileSystemType type, | 113 storage::FileSystemType type, |
115 fileapi::FileChangeObserver* observer, | 114 storage::FileChangeObserver* observer, |
116 base::SequencedTaskRunner* task_runner) OVERRIDE { | 115 base::SequencedTaskRunner* task_runner) OVERRIDE { |
117 change_observers_ = change_observers_.AddObserver(observer, task_runner); | 116 change_observers_ = change_observers_.AddObserver(observer, task_runner); |
118 } | 117 } |
119 | 118 |
120 virtual void AddFileAccessObserver( | 119 virtual void AddFileAccessObserver( |
121 fileapi::FileSystemType type, | 120 storage::FileSystemType type, |
122 fileapi::FileAccessObserver* observer, | 121 storage::FileAccessObserver* observer, |
123 base::SequencedTaskRunner* task_runner) OVERRIDE { | 122 base::SequencedTaskRunner* task_runner) OVERRIDE { |
124 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
125 } | 124 } |
126 | 125 |
127 virtual const fileapi::UpdateObserverList* GetUpdateObservers( | 126 virtual const storage::UpdateObserverList* GetUpdateObservers( |
128 fileapi::FileSystemType type) const OVERRIDE { | 127 storage::FileSystemType type) const OVERRIDE { |
129 return &update_observers_; | 128 return &update_observers_; |
130 } | 129 } |
131 | 130 |
132 virtual const fileapi::ChangeObserverList* GetChangeObservers( | 131 virtual const storage::ChangeObserverList* GetChangeObservers( |
133 fileapi::FileSystemType type) const OVERRIDE { | 132 storage::FileSystemType type) const OVERRIDE { |
134 return &change_observers_; | 133 return &change_observers_; |
135 } | 134 } |
136 | 135 |
137 virtual const fileapi::AccessObserverList* GetAccessObservers( | 136 virtual const storage::AccessObserverList* GetAccessObservers( |
138 fileapi::FileSystemType type) const OVERRIDE { | 137 storage::FileSystemType type) const OVERRIDE { |
139 return NULL; | 138 return NULL; |
140 } | 139 } |
141 | 140 |
142 // FileUpdateObserver overrides. | 141 // FileUpdateObserver overrides. |
143 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} | 142 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} |
144 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { | 143 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { |
145 usage_ += delta; | 144 usage_ += delta; |
146 } | 145 } |
147 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} | 146 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} |
148 | 147 |
149 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } | 148 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } |
150 | 149 |
151 private: | 150 private: |
152 int64 usage_; | 151 int64 usage_; |
153 | 152 |
154 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 153 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
155 | 154 |
156 fileapi::UpdateObserverList update_observers_; | 155 storage::UpdateObserverList update_observers_; |
157 fileapi::ChangeObserverList change_observers_; | 156 storage::ChangeObserverList change_observers_; |
158 }; | 157 }; |
159 | 158 |
160 TestFileSystemBackend::TestFileSystemBackend( | 159 TestFileSystemBackend::TestFileSystemBackend( |
161 base::SequencedTaskRunner* task_runner, | 160 base::SequencedTaskRunner* task_runner, |
162 const base::FilePath& base_path) | 161 const base::FilePath& base_path) |
163 : base_path_(base_path), | 162 : base_path_(base_path), |
164 file_util_( | 163 file_util_( |
165 new fileapi::AsyncFileUtilAdapter(new TestFileUtil(base_path))), | 164 new storage::AsyncFileUtilAdapter(new TestFileUtil(base_path))), |
166 quota_util_(new QuotaUtil(task_runner)), | 165 quota_util_(new QuotaUtil(task_runner)), |
167 require_copy_or_move_validator_(false) { | 166 require_copy_or_move_validator_(false) { |
168 } | 167 } |
169 | 168 |
170 TestFileSystemBackend::~TestFileSystemBackend() { | 169 TestFileSystemBackend::~TestFileSystemBackend() { |
171 } | 170 } |
172 | 171 |
173 bool TestFileSystemBackend::CanHandleType(fileapi::FileSystemType type) const { | 172 bool TestFileSystemBackend::CanHandleType(storage::FileSystemType type) const { |
174 return (type == fileapi::kFileSystemTypeTest); | 173 return (type == storage::kFileSystemTypeTest); |
175 } | 174 } |
176 | 175 |
177 void TestFileSystemBackend::Initialize(FileSystemContext* context) { | 176 void TestFileSystemBackend::Initialize(FileSystemContext* context) { |
178 } | 177 } |
179 | 178 |
180 void TestFileSystemBackend::ResolveURL(const FileSystemURL& url, | 179 void TestFileSystemBackend::ResolveURL(const FileSystemURL& url, |
181 fileapi::OpenFileSystemMode mode, | 180 storage::OpenFileSystemMode mode, |
182 const OpenFileSystemCallback& callback) { | 181 const OpenFileSystemCallback& callback) { |
183 callback.Run(GetFileSystemRootURI(url.origin(), url.type()), | 182 callback.Run(GetFileSystemRootURI(url.origin(), url.type()), |
184 GetFileSystemName(url.origin(), url.type()), | 183 GetFileSystemName(url.origin(), url.type()), |
185 base::File::FILE_OK); | 184 base::File::FILE_OK); |
186 } | 185 } |
187 | 186 |
188 fileapi::AsyncFileUtil* TestFileSystemBackend::GetAsyncFileUtil( | 187 storage::AsyncFileUtil* TestFileSystemBackend::GetAsyncFileUtil( |
189 fileapi::FileSystemType type) { | 188 storage::FileSystemType type) { |
190 return file_util_.get(); | 189 return file_util_.get(); |
191 } | 190 } |
192 | 191 |
193 fileapi::CopyOrMoveFileValidatorFactory* | 192 storage::CopyOrMoveFileValidatorFactory* |
194 TestFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 193 TestFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
195 fileapi::FileSystemType type, | 194 storage::FileSystemType type, |
196 base::File::Error* error_code) { | 195 base::File::Error* error_code) { |
197 DCHECK(error_code); | 196 DCHECK(error_code); |
198 *error_code = base::File::FILE_OK; | 197 *error_code = base::File::FILE_OK; |
199 if (require_copy_or_move_validator_) { | 198 if (require_copy_or_move_validator_) { |
200 if (!copy_or_move_file_validator_factory_) | 199 if (!copy_or_move_file_validator_factory_) |
201 *error_code = base::File::FILE_ERROR_SECURITY; | 200 *error_code = base::File::FILE_ERROR_SECURITY; |
202 return copy_or_move_file_validator_factory_.get(); | 201 return copy_or_move_file_validator_factory_.get(); |
203 } | 202 } |
204 return NULL; | 203 return NULL; |
205 } | 204 } |
206 | 205 |
207 void TestFileSystemBackend::InitializeCopyOrMoveFileValidatorFactory( | 206 void TestFileSystemBackend::InitializeCopyOrMoveFileValidatorFactory( |
208 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory) { | 207 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory) { |
209 if (!copy_or_move_file_validator_factory_) | 208 if (!copy_or_move_file_validator_factory_) |
210 copy_or_move_file_validator_factory_ = factory.Pass(); | 209 copy_or_move_file_validator_factory_ = factory.Pass(); |
211 } | 210 } |
212 | 211 |
213 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( | 212 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( |
214 const FileSystemURL& url, | 213 const FileSystemURL& url, |
215 FileSystemContext* context, | 214 FileSystemContext* context, |
216 base::File::Error* error_code) const { | 215 base::File::Error* error_code) const { |
217 scoped_ptr<FileSystemOperationContext> operation_context( | 216 scoped_ptr<FileSystemOperationContext> operation_context( |
218 new FileSystemOperationContext(context)); | 217 new FileSystemOperationContext(context)); |
219 operation_context->set_update_observers(*GetUpdateObservers(url.type())); | 218 operation_context->set_update_observers(*GetUpdateObservers(url.type())); |
220 operation_context->set_change_observers( | 219 operation_context->set_change_observers( |
221 *quota_util_->GetChangeObservers(url.type())); | 220 *quota_util_->GetChangeObservers(url.type())); |
222 return FileSystemOperation::Create(url, context, operation_context.Pass()); | 221 return FileSystemOperation::Create(url, context, operation_context.Pass()); |
223 } | 222 } |
224 | 223 |
225 bool TestFileSystemBackend::SupportsStreaming( | 224 bool TestFileSystemBackend::SupportsStreaming( |
226 const fileapi::FileSystemURL& url) const { | 225 const storage::FileSystemURL& url) const { |
227 return false; | 226 return false; |
228 } | 227 } |
229 | 228 |
230 scoped_ptr<webkit_blob::FileStreamReader> | 229 scoped_ptr<storage::FileStreamReader> |
231 TestFileSystemBackend::CreateFileStreamReader( | 230 TestFileSystemBackend::CreateFileStreamReader( |
232 const FileSystemURL& url, | 231 const FileSystemURL& url, |
233 int64 offset, | 232 int64 offset, |
234 const base::Time& expected_modification_time, | 233 const base::Time& expected_modification_time, |
235 FileSystemContext* context) const { | 234 FileSystemContext* context) const { |
236 return scoped_ptr<webkit_blob::FileStreamReader>( | 235 return scoped_ptr<storage::FileStreamReader>( |
237 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 236 storage::FileStreamReader::CreateForFileSystemFile( |
238 context, url, offset, expected_modification_time)); | 237 context, url, offset, expected_modification_time)); |
239 } | 238 } |
240 | 239 |
241 scoped_ptr<fileapi::FileStreamWriter> | 240 scoped_ptr<storage::FileStreamWriter> |
242 TestFileSystemBackend::CreateFileStreamWriter( | 241 TestFileSystemBackend::CreateFileStreamWriter( |
243 const FileSystemURL& url, | 242 const FileSystemURL& url, |
244 int64 offset, | 243 int64 offset, |
245 FileSystemContext* context) const { | 244 FileSystemContext* context) const { |
246 return scoped_ptr<fileapi::FileStreamWriter>( | 245 return scoped_ptr<storage::FileStreamWriter>( |
247 new fileapi::SandboxFileStreamWriter(context, url, offset, | 246 new storage::SandboxFileStreamWriter( |
248 *GetUpdateObservers(url.type()))); | 247 context, url, offset, *GetUpdateObservers(url.type()))); |
249 } | 248 } |
250 | 249 |
251 fileapi::FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { | 250 storage::FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { |
252 return quota_util_.get(); | 251 return quota_util_.get(); |
253 } | 252 } |
254 | 253 |
255 const fileapi::UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( | 254 const storage::UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( |
256 fileapi::FileSystemType type) const { | 255 storage::FileSystemType type) const { |
257 return quota_util_->GetUpdateObservers(type); | 256 return quota_util_->GetUpdateObservers(type); |
258 } | 257 } |
259 | 258 |
260 void TestFileSystemBackend::AddFileChangeObserver( | 259 void TestFileSystemBackend::AddFileChangeObserver( |
261 fileapi::FileChangeObserver* observer) { | 260 storage::FileChangeObserver* observer) { |
262 quota_util_->AddFileChangeObserver( | 261 quota_util_->AddFileChangeObserver( |
263 fileapi::kFileSystemTypeTest, observer, quota_util_->task_runner()); | 262 storage::kFileSystemTypeTest, observer, quota_util_->task_runner()); |
264 } | 263 } |
265 | 264 |
266 } // namespace content | 265 } // namespace content |
OLD | NEW |