| 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 "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 5 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 template <typename R> | 62 template <typename R> |
| 63 R RunOnThread( | 63 R RunOnThread( |
| 64 base::SingleThreadTaskRunner* task_runner, | 64 base::SingleThreadTaskRunner* task_runner, |
| 65 const tracked_objects::Location& location, | 65 const tracked_objects::Location& location, |
| 66 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { | 66 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { |
| 67 R result; | 67 R result; |
| 68 base::RunLoop run_loop; | 68 base::RunLoop run_loop; |
| 69 task_runner->PostTask( | 69 task_runner->PostTask( |
| 70 location, | 70 location, |
| 71 base::Bind(task, base::Bind(&AssignAndQuit<R>, | 71 base::BindOnce(task, base::Bind(&AssignAndQuit<R>, |
| 72 base::RetainedRef( | 72 base::RetainedRef( |
| 73 base::ThreadTaskRunnerHandle::Get()), | 73 base::ThreadTaskRunnerHandle::Get()), |
| 74 run_loop.QuitClosure(), &result))); | 74 run_loop.QuitClosure(), &result))); |
| 75 run_loop.Run(); | 75 run_loop.Run(); |
| 76 return result; | 76 return result; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void RunOnThread(base::SingleThreadTaskRunner* task_runner, | 79 void RunOnThread(base::SingleThreadTaskRunner* task_runner, |
| 80 const tracked_objects::Location& location, | 80 const tracked_objects::Location& location, |
| 81 const base::Closure& task) { | 81 const base::Closure& task) { |
| 82 base::RunLoop run_loop; | 82 base::RunLoop run_loop; |
| 83 task_runner->PostTaskAndReply( | 83 task_runner->PostTaskAndReply(location, task, |
| 84 location, task, | 84 base::BindOnce(base::IgnoreResult(base::Bind( |
| 85 base::Bind(base::IgnoreResult( | 85 &base::SingleThreadTaskRunner::PostTask, |
| 86 base::Bind(&base::SingleThreadTaskRunner::PostTask, | 86 base::ThreadTaskRunnerHandle::Get(), |
| 87 base::ThreadTaskRunnerHandle::Get(), | 87 FROM_HERE, run_loop.QuitClosure())))); |
| 88 FROM_HERE, run_loop.QuitClosure())))); | |
| 89 run_loop.Run(); | 88 run_loop.Run(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { | 91 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { |
| 93 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); | 92 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void VerifySameTaskRunner( | 95 void VerifySameTaskRunner( |
| 97 base::SingleThreadTaskRunner* runner1, | 96 base::SingleThreadTaskRunner* runner1, |
| 98 base::SingleThreadTaskRunner* runner2) { | 97 base::SingleThreadTaskRunner* runner2) { |
| 99 ASSERT_TRUE(runner1 != nullptr); | 98 ASSERT_TRUE(runner1 != nullptr); |
| 100 ASSERT_TRUE(runner2 != nullptr); | 99 ASSERT_TRUE(runner2 != nullptr); |
| 101 runner1->PostTask(FROM_HERE, | 100 runner1->PostTask( |
| 102 base::Bind(&EnsureRunningOn, base::RetainedRef(runner2))); | 101 FROM_HERE, base::BindOnce(&EnsureRunningOn, base::RetainedRef(runner2))); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void OnCreateSnapshotFileAndVerifyData( | 104 void OnCreateSnapshotFileAndVerifyData( |
| 106 const std::string& expected_data, | 105 const std::string& expected_data, |
| 107 const CannedSyncableFileSystem::StatusCallback& callback, | 106 const CannedSyncableFileSystem::StatusCallback& callback, |
| 108 base::File::Error result, | 107 base::File::Error result, |
| 109 const base::File::Info& file_info, | 108 const base::File::Info& file_info, |
| 110 const base::FilePath& platform_path, | 109 const base::FilePath& platform_path, |
| 111 const scoped_refptr<storage::ShareableFileReference>& /* file_ref */) { | 110 const scoped_refptr<storage::ShareableFileReference>& /* file_ref */) { |
| 112 if (result != base::File::FILE_OK) { | 111 if (result != base::File::FILE_OK) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 storage::QuotaStatusCode status, | 198 storage::QuotaStatusCode status, |
| 200 int64_t usage, | 199 int64_t usage, |
| 201 int64_t quota) { | 200 int64_t quota) { |
| 202 *usage_out = usage; | 201 *usage_out = usage; |
| 203 *quota_out = quota; | 202 *quota_out = quota; |
| 204 callback.Run(status); | 203 callback.Run(status); |
| 205 } | 204 } |
| 206 | 205 |
| 207 void EnsureLastTaskRuns(base::SingleThreadTaskRunner* runner) { | 206 void EnsureLastTaskRuns(base::SingleThreadTaskRunner* runner) { |
| 208 base::RunLoop run_loop; | 207 base::RunLoop run_loop; |
| 209 runner->PostTaskAndReply( | 208 runner->PostTaskAndReply(FROM_HERE, base::BindOnce(&base::DoNothing), |
| 210 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure()); | 209 run_loop.QuitClosure()); |
| 211 run_loop.Run(); | 210 run_loop.Run(); |
| 212 } | 211 } |
| 213 | 212 |
| 214 } // namespace | 213 } // namespace |
| 215 | 214 |
| 216 CannedSyncableFileSystem::CannedSyncableFileSystem( | 215 CannedSyncableFileSystem::CannedSyncableFileSystem( |
| 217 const GURL& origin, | 216 const GURL& origin, |
| 218 leveldb::Env* env_override, | 217 leveldb::Env* env_override, |
| 219 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 218 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 220 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 219 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 GURL url(root_url_.spec() + path); | 283 GURL url(root_url_.spec() + path); |
| 285 return file_system_context_->CrackURL(url); | 284 return file_system_context_->CrackURL(url); |
| 286 } | 285 } |
| 287 | 286 |
| 288 File::Error CannedSyncableFileSystem::OpenFileSystem() { | 287 File::Error CannedSyncableFileSystem::OpenFileSystem() { |
| 289 EXPECT_TRUE(is_filesystem_set_up_); | 288 EXPECT_TRUE(is_filesystem_set_up_); |
| 290 | 289 |
| 291 base::RunLoop run_loop; | 290 base::RunLoop run_loop; |
| 292 io_task_runner_->PostTask( | 291 io_task_runner_->PostTask( |
| 293 FROM_HERE, | 292 FROM_HERE, |
| 294 base::Bind( | 293 base::BindOnce( |
| 295 &CannedSyncableFileSystem::DoOpenFileSystem, base::Unretained(this), | 294 &CannedSyncableFileSystem::DoOpenFileSystem, base::Unretained(this), |
| 296 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, | 295 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, |
| 297 base::Unretained(this), | 296 base::Unretained(this), |
| 298 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), | 297 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), |
| 299 run_loop.QuitClosure()))); | 298 run_loop.QuitClosure()))); |
| 300 run_loop.Run(); | 299 run_loop.Run(); |
| 301 | 300 |
| 302 if (backend()->sync_context()) { | 301 if (backend()->sync_context()) { |
| 303 // Register 'this' as a sync status observer. | 302 // Register 'this' as a sync status observer. |
| 304 RunOnThread( | 303 RunOnThread( |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 const GURL& root, | 729 const GURL& root, |
| 731 const std::string& name, | 730 const std::string& name, |
| 732 File::Error result) { | 731 File::Error result) { |
| 733 if (io_task_runner_->RunsTasksOnCurrentThread()) { | 732 if (io_task_runner_->RunsTasksOnCurrentThread()) { |
| 734 EXPECT_FALSE(is_filesystem_opened_); | 733 EXPECT_FALSE(is_filesystem_opened_); |
| 735 is_filesystem_opened_ = true; | 734 is_filesystem_opened_ = true; |
| 736 } | 735 } |
| 737 if (!original_task_runner->RunsTasksOnCurrentThread()) { | 736 if (!original_task_runner->RunsTasksOnCurrentThread()) { |
| 738 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 737 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 739 original_task_runner->PostTask( | 738 original_task_runner->PostTask( |
| 740 FROM_HERE, base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, | 739 FROM_HERE, base::BindOnce(&CannedSyncableFileSystem::DidOpenFileSystem, |
| 741 base::Unretained(this), | 740 base::Unretained(this), |
| 742 base::RetainedRef(original_task_runner), | 741 base::RetainedRef(original_task_runner), |
| 743 quit_closure, root, name, result)); | 742 quit_closure, root, name, result)); |
| 744 return; | 743 return; |
| 745 } | 744 } |
| 746 result_ = result; | 745 result_ = result; |
| 747 root_url_ = root; | 746 root_url_ = root; |
| 748 quit_closure.Run(); | 747 quit_closure.Run(); |
| 749 } | 748 } |
| 750 | 749 |
| 751 void CannedSyncableFileSystem::DidInitializeFileSystemContext( | 750 void CannedSyncableFileSystem::DidInitializeFileSystemContext( |
| 752 const base::Closure& quit_closure, | 751 const base::Closure& quit_closure, |
| 753 SyncStatusCode status) { | 752 SyncStatusCode status) { |
| 754 sync_status_ = status; | 753 sync_status_ = status; |
| 755 quit_closure.Run(); | 754 quit_closure.Run(); |
| 756 } | 755 } |
| 757 | 756 |
| 758 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { | 757 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { |
| 759 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 758 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); |
| 760 backend()->sync_context()->sync_status()->AddObserver(this); | 759 backend()->sync_context()->sync_status()->AddObserver(this); |
| 761 } | 760 } |
| 762 | 761 |
| 763 } // namespace sync_file_system | 762 } // namespace sync_file_system |
| OLD | NEW |