OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 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 "webkit/fileapi/syncable/canned_syncable_file_system.h" | 5 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return; | 82 return; |
83 } | 83 } |
84 completion_callback.Run(error == base::PLATFORM_FILE_OK | 84 completion_callback.Run(error == base::PLATFORM_FILE_OK |
85 ? bytes_written_ : static_cast<int64>(error)); | 85 ? bytes_written_ : static_cast<int64>(error)); |
86 } | 86 } |
87 | 87 |
88 private: | 88 private: |
89 int64 bytes_written_; | 89 int64 bytes_written_; |
90 }; | 90 }; |
91 | 91 |
| 92 void DidGetUsageAndQuota(const quota::StatusCallback& callback, |
| 93 int64* usage_out, int64* quota_out, |
| 94 quota::QuotaStatusCode status, |
| 95 int64 usage, int64 quota) { |
| 96 *usage_out = usage; |
| 97 *quota_out = quota; |
| 98 callback.Run(status); |
| 99 } |
| 100 |
92 } // namespace | 101 } // namespace |
93 | 102 |
94 CannedSyncableFileSystem::CannedSyncableFileSystem( | 103 CannedSyncableFileSystem::CannedSyncableFileSystem( |
95 const GURL& origin, const std::string& service, | 104 const GURL& origin, const std::string& service, |
96 base::SingleThreadTaskRunner* io_task_runner) | 105 base::SingleThreadTaskRunner* io_task_runner) |
97 : service_name_(service), | 106 : service_name_(service), |
98 test_helper_(origin, kFileSystemTypeSyncable), | 107 test_helper_(origin, kFileSystemTypeSyncable), |
99 result_(base::PLATFORM_FILE_OK), | 108 result_(base::PLATFORM_FILE_OK), |
100 sync_status_(SYNC_STATUS_OK), | 109 sync_status_(SYNC_STATUS_OK), |
101 io_task_runner_(io_task_runner), | 110 io_task_runner_(io_task_runner), |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 EXPECT_TRUE(is_filesystem_set_up_); | 267 EXPECT_TRUE(is_filesystem_set_up_); |
259 return RunOnThread<PlatformFileError>( | 268 return RunOnThread<PlatformFileError>( |
260 io_task_runner_, | 269 io_task_runner_, |
261 FROM_HERE, | 270 FROM_HERE, |
262 base::Bind(&FileSystemContext::DeleteFileSystem, | 271 base::Bind(&FileSystemContext::DeleteFileSystem, |
263 file_system_context_, | 272 file_system_context_, |
264 test_helper_.origin(), | 273 test_helper_.origin(), |
265 test_helper_.type())); | 274 test_helper_.type())); |
266 } | 275 } |
267 | 276 |
| 277 quota::QuotaStatusCode CannedSyncableFileSystem::GetUsageAndQuota( |
| 278 int64* usage, int64* quota) { |
| 279 return RunOnThread<quota::QuotaStatusCode>( |
| 280 io_task_runner_, |
| 281 FROM_HERE, |
| 282 base::Bind(&CannedSyncableFileSystem::DoGetUsageAndQuota, |
| 283 base::Unretained(this), usage, quota)); |
| 284 } |
| 285 |
268 FileSystemOperation* CannedSyncableFileSystem::NewOperation() { | 286 FileSystemOperation* CannedSyncableFileSystem::NewOperation() { |
269 return file_system_context_->CreateFileSystemOperation(URL(""), NULL); | 287 return file_system_context_->CreateFileSystemOperation(URL(""), NULL); |
270 } | 288 } |
271 | 289 |
272 void CannedSyncableFileSystem::DoCreateDirectory( | 290 void CannedSyncableFileSystem::DoCreateDirectory( |
273 const FileSystemURL& url, | 291 const FileSystemURL& url, |
274 const StatusCallback& callback) { | 292 const StatusCallback& callback) { |
275 EXPECT_TRUE(is_filesystem_opened_); | 293 EXPECT_TRUE(is_filesystem_opened_); |
276 NewOperation()->CreateDirectory( | 294 NewOperation()->CreateDirectory( |
277 url, false /* exclusive */, false /* recursive */, callback); | 295 url, false /* exclusive */, false /* recursive */, callback); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 net::URLRequestContext* url_request_context, | 348 net::URLRequestContext* url_request_context, |
331 const FileSystemURL& url, const GURL& blob_url, | 349 const FileSystemURL& url, const GURL& blob_url, |
332 const WriteCallback& callback) { | 350 const WriteCallback& callback) { |
333 EXPECT_TRUE(is_filesystem_opened_); | 351 EXPECT_TRUE(is_filesystem_opened_); |
334 WriteHelper* helper = new WriteHelper; | 352 WriteHelper* helper = new WriteHelper; |
335 NewOperation()->Write(url_request_context, url, blob_url, 0, | 353 NewOperation()->Write(url_request_context, url, blob_url, 0, |
336 base::Bind(&WriteHelper::DidWrite, | 354 base::Bind(&WriteHelper::DidWrite, |
337 base::Owned(helper), callback)); | 355 base::Owned(helper), callback)); |
338 } | 356 } |
339 | 357 |
| 358 void CannedSyncableFileSystem::DoGetUsageAndQuota( |
| 359 int64* usage, |
| 360 int64* quota, |
| 361 const quota::StatusCallback& callback) { |
| 362 quota_manager_->GetUsageAndQuota( |
| 363 test_helper_.origin(), |
| 364 test_helper_.storage_type(), |
| 365 base::Bind(&DidGetUsageAndQuota, callback, usage, quota)); |
| 366 } |
| 367 |
340 void CannedSyncableFileSystem::DidOpenFileSystem( | 368 void CannedSyncableFileSystem::DidOpenFileSystem( |
341 PlatformFileError result, const std::string& name, const GURL& root) { | 369 PlatformFileError result, const std::string& name, const GURL& root) { |
342 result_ = result; | 370 result_ = result; |
343 root_url_ = root; | 371 root_url_ = root; |
344 is_filesystem_opened_ = true; | 372 is_filesystem_opened_ = true; |
345 } | 373 } |
346 | 374 |
347 void CannedSyncableFileSystem::DidInitializeFileSystemContext( | 375 void CannedSyncableFileSystem::DidInitializeFileSystemContext( |
348 SyncStatusCode status) { | 376 SyncStatusCode status) { |
349 sync_status_ = status; | 377 sync_status_ = status; |
350 MessageLoop::current()->Quit(); | 378 MessageLoop::current()->Quit(); |
351 } | 379 } |
352 | 380 |
353 } // namespace fileapi | 381 } // namespace fileapi |
OLD | NEW |