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 "webkit/browser/fileapi/syncable/canned_syncable_file_system.h" | 5 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webkit/browser/blob/mock_blob_url_request_context.h" | 17 #include "webkit/browser/blob/mock_blob_url_request_context.h" |
18 #include "webkit/browser/fileapi/external_mount_points.h" | 18 #include "webkit/browser/fileapi/external_mount_points.h" |
19 #include "webkit/browser/fileapi/file_system_backend.h" | 19 #include "webkit/browser/fileapi/file_system_backend.h" |
20 #include "webkit/browser/fileapi/file_system_context.h" | 20 #include "webkit/browser/fileapi/file_system_context.h" |
21 #include "webkit/browser/fileapi/file_system_operation_context.h" | 21 #include "webkit/browser/fileapi/file_system_operation_context.h" |
22 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 22 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
23 #include "webkit/browser/fileapi/file_system_task_runners.h" | 23 #include "webkit/browser/fileapi/file_system_task_runners.h" |
24 #include "webkit/browser/fileapi/mock_file_system_options.h" | 24 #include "webkit/browser/fileapi/mock_file_system_options.h" |
25 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 25 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
26 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" | 26 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" |
27 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" | 27 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" |
| 28 #include "webkit/browser/fileapi/syncable/sync_file_system_backend.h" |
28 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | 29 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
29 #include "webkit/browser/quota/mock_special_storage_policy.h" | 30 #include "webkit/browser/quota/mock_special_storage_policy.h" |
30 #include "webkit/browser/quota/quota_manager.h" | 31 #include "webkit/browser/quota/quota_manager.h" |
31 #include "webkit/common/blob/shareable_file_reference.h" | 32 #include "webkit/common/blob/shareable_file_reference.h" |
32 | 33 |
33 using base::PlatformFileError; | 34 using base::PlatformFileError; |
34 using fileapi::FileSystemContext; | 35 using fileapi::FileSystemContext; |
35 using fileapi::FileSystemOperationRunner; | 36 using fileapi::FileSystemOperationRunner; |
36 using fileapi::FileSystemURL; | 37 using fileapi::FileSystemURL; |
37 using fileapi::FileSystemURLSet; | 38 using fileapi::FileSystemURLSet; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 io_task_runner_.get(), | 226 io_task_runner_.get(), |
226 base::MessageLoopProxy::current().get(), | 227 base::MessageLoopProxy::current().get(), |
227 storage_policy.get()); | 228 storage_policy.get()); |
228 | 229 |
229 std::vector<std::string> additional_allowed_schemes; | 230 std::vector<std::string> additional_allowed_schemes; |
230 additional_allowed_schemes.push_back(origin_.scheme()); | 231 additional_allowed_schemes.push_back(origin_.scheme()); |
231 fileapi::FileSystemOptions options( | 232 fileapi::FileSystemOptions options( |
232 fileapi::FileSystemOptions::PROFILE_MODE_NORMAL, | 233 fileapi::FileSystemOptions::PROFILE_MODE_NORMAL, |
233 additional_allowed_schemes); | 234 additional_allowed_schemes); |
234 | 235 |
| 236 ScopedVector<fileapi::FileSystemBackend> additional_backends; |
| 237 additional_backends.push_back(new SyncFileSystemBackend( |
| 238 file_task_runner_.get(), options)); |
| 239 |
235 file_system_context_ = new FileSystemContext( | 240 file_system_context_ = new FileSystemContext( |
236 make_scoped_ptr( | 241 make_scoped_ptr( |
237 new fileapi::FileSystemTaskRunners(io_task_runner_.get(), | 242 new fileapi::FileSystemTaskRunners(io_task_runner_.get(), |
238 file_task_runner_.get())), | 243 file_task_runner_.get())), |
239 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 244 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
240 storage_policy.get(), | 245 storage_policy.get(), |
241 quota_manager_->proxy(), | 246 quota_manager_->proxy(), |
242 ScopedVector<fileapi::FileSystemBackend>(), | 247 additional_backends.Pass(), |
243 data_dir_.path(), options); | 248 data_dir_.path(), options); |
244 | 249 |
245 is_filesystem_set_up_ = true; | 250 is_filesystem_set_up_ = true; |
246 } | 251 } |
247 | 252 |
248 void CannedSyncableFileSystem::TearDown() { | 253 void CannedSyncableFileSystem::TearDown() { |
249 quota_manager_ = NULL; | 254 quota_manager_ = NULL; |
250 file_system_context_ = NULL; | 255 file_system_context_ = NULL; |
251 | 256 |
252 // Make sure we give some more time to finish tasks on other threads. | 257 // Make sure we give some more time to finish tasks on other threads. |
(...skipping 11 matching lines...) Expand all Loading... |
264 | 269 |
265 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { | 270 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { |
266 EXPECT_TRUE(is_filesystem_set_up_); | 271 EXPECT_TRUE(is_filesystem_set_up_); |
267 EXPECT_FALSE(is_filesystem_opened_); | 272 EXPECT_FALSE(is_filesystem_opened_); |
268 file_system_context_->OpenFileSystem( | 273 file_system_context_->OpenFileSystem( |
269 origin_, type_, | 274 origin_, type_, |
270 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 275 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
271 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, | 276 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, |
272 base::Unretained(this))); | 277 base::Unretained(this))); |
273 base::MessageLoop::current()->Run(); | 278 base::MessageLoop::current()->Run(); |
274 if (file_system_context_->sync_context()) { | 279 if (backend()->sync_context()) { |
275 // Register 'this' as a sync status observer. | 280 // Register 'this' as a sync status observer. |
276 RunOnThread( | 281 RunOnThread( |
277 io_task_runner_.get(), | 282 io_task_runner_.get(), |
278 FROM_HERE, | 283 FROM_HERE, |
279 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver, | 284 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver, |
280 base::Unretained(this))); | 285 base::Unretained(this))); |
281 } | 286 } |
282 return result_; | 287 return result_; |
283 } | 288 } |
284 | 289 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 usage, | 491 usage, |
487 quota)); | 492 quota)); |
488 } | 493 } |
489 | 494 |
490 void CannedSyncableFileSystem::GetChangedURLsInTracker( | 495 void CannedSyncableFileSystem::GetChangedURLsInTracker( |
491 FileSystemURLSet* urls) { | 496 FileSystemURLSet* urls) { |
492 return RunOnThread( | 497 return RunOnThread( |
493 file_task_runner_.get(), | 498 file_task_runner_.get(), |
494 FROM_HERE, | 499 FROM_HERE, |
495 base::Bind(&LocalFileChangeTracker::GetAllChangedURLs, | 500 base::Bind(&LocalFileChangeTracker::GetAllChangedURLs, |
496 base::Unretained(file_system_context_->change_tracker()), | 501 base::Unretained(backend()->change_tracker()), |
497 urls)); | 502 urls)); |
498 } | 503 } |
499 | 504 |
500 void CannedSyncableFileSystem::ClearChangeForURLInTracker( | 505 void CannedSyncableFileSystem::ClearChangeForURLInTracker( |
501 const FileSystemURL& url) { | 506 const FileSystemURL& url) { |
502 return RunOnThread( | 507 return RunOnThread( |
503 file_task_runner_.get(), | 508 file_task_runner_.get(), |
504 FROM_HERE, | 509 FROM_HERE, |
505 base::Bind(&LocalFileChangeTracker::ClearChangesForURL, | 510 base::Bind(&LocalFileChangeTracker::ClearChangesForURL, |
506 base::Unretained(file_system_context_->change_tracker()), | 511 base::Unretained(backend()->change_tracker()), |
507 url)); | 512 url)); |
508 } | 513 } |
509 | 514 |
| 515 SyncFileSystemBackend* CannedSyncableFileSystem::backend() { |
| 516 return SyncFileSystemBackend::GetBackend(file_system_context_); |
| 517 } |
| 518 |
510 FileSystemOperationRunner* CannedSyncableFileSystem::operation_runner() { | 519 FileSystemOperationRunner* CannedSyncableFileSystem::operation_runner() { |
511 return file_system_context_->operation_runner(); | 520 return file_system_context_->operation_runner(); |
512 } | 521 } |
513 | 522 |
514 void CannedSyncableFileSystem::OnSyncEnabled(const FileSystemURL& url) { | 523 void CannedSyncableFileSystem::OnSyncEnabled(const FileSystemURL& url) { |
515 sync_status_observers_->Notify(&LocalFileSyncStatus::Observer::OnSyncEnabled, | 524 sync_status_observers_->Notify(&LocalFileSyncStatus::Observer::OnSyncEnabled, |
516 url); | 525 url); |
517 } | 526 } |
518 | 527 |
519 void CannedSyncableFileSystem::OnWriteEnabled(const FileSystemURL& url) { | 528 void CannedSyncableFileSystem::OnWriteEnabled(const FileSystemURL& url) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 } | 668 } |
660 | 669 |
661 void CannedSyncableFileSystem::DidInitializeFileSystemContext( | 670 void CannedSyncableFileSystem::DidInitializeFileSystemContext( |
662 SyncStatusCode status) { | 671 SyncStatusCode status) { |
663 sync_status_ = status; | 672 sync_status_ = status; |
664 base::MessageLoop::current()->Quit(); | 673 base::MessageLoop::current()->Quit(); |
665 } | 674 } |
666 | 675 |
667 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { | 676 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { |
668 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 677 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); |
669 file_system_context_->sync_context()->sync_status()->AddObserver(this); | 678 backend()->sync_context()->sync_status()->AddObserver(this); |
670 } | 679 } |
671 | 680 |
672 } // namespace sync_file_system | 681 } // namespace sync_file_system |
OLD | NEW |