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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
14 #include "base/guid.h" | 14 #include "base/guid.h" |
15 #include "base/message_loop/message_loop_proxy.h" | |
16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
18 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 18 #include "base/thread_task_runner_handle.h" |
19 #include "chrome/browser/sync_file_system/file_change.h" | 19 #include "chrome/browser/sync_file_system/file_change.h" |
20 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 20 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
21 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 21 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
22 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 22 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
24 #include "content/public/test/mock_blob_url_request_context.h" | 24 #include "content/public/test/mock_blob_url_request_context.h" |
25 #include "content/public/test/mock_special_storage_policy.h" | 25 #include "content/public/test/mock_special_storage_policy.h" |
26 #include "content/public/test/test_file_system_options.h" | 26 #include "content/public/test/test_file_system_options.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "webkit/browser/fileapi/external_mount_points.h" | 28 #include "webkit/browser/fileapi/external_mount_points.h" |
(...skipping 29 matching lines...) Expand all Loading... |
58 | 58 |
59 template <typename R> | 59 template <typename R> |
60 R RunOnThread( | 60 R RunOnThread( |
61 base::SingleThreadTaskRunner* task_runner, | 61 base::SingleThreadTaskRunner* task_runner, |
62 const tracked_objects::Location& location, | 62 const tracked_objects::Location& location, |
63 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { | 63 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { |
64 R result; | 64 R result; |
65 task_runner->PostTask( | 65 task_runner->PostTask( |
66 location, | 66 location, |
67 base::Bind(task, base::Bind(&AssignAndQuit<R>, | 67 base::Bind(task, base::Bind(&AssignAndQuit<R>, |
68 base::MessageLoopProxy::current(), | 68 base::ThreadTaskRunnerHandle::Get(), |
69 &result))); | 69 &result))); |
70 base::MessageLoop::current()->Run(); | 70 base::MessageLoop::current()->Run(); |
71 return result; | 71 return result; |
72 } | 72 } |
73 | 73 |
74 void RunOnThread(base::SingleThreadTaskRunner* task_runner, | 74 void RunOnThread(base::SingleThreadTaskRunner* task_runner, |
75 const tracked_objects::Location& location, | 75 const tracked_objects::Location& location, |
76 const base::Closure& task) { | 76 const base::Closure& task) { |
77 task_runner->PostTaskAndReply( | 77 task_runner->PostTaskAndReply( |
78 location, task, | 78 location, task, |
79 base::Bind(base::IgnoreResult( | 79 base::Bind(base::IgnoreResult( |
80 base::Bind(&base::MessageLoopProxy::PostTask, | 80 base::Bind(&base::SingleThreadTaskRunner::PostTask, |
81 base::MessageLoopProxy::current(), | 81 base::ThreadTaskRunnerHandle::Get(), |
82 FROM_HERE, base::Bind(&Quit))))); | 82 FROM_HERE, base::Bind(&Quit))))); |
83 base::MessageLoop::current()->Run(); | 83 base::MessageLoop::current()->Run(); |
84 } | 84 } |
85 | 85 |
86 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { | 86 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { |
87 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); | 87 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); |
88 } | 88 } |
89 | 89 |
90 void VerifySameTaskRunner( | 90 void VerifySameTaskRunner( |
91 base::SingleThreadTaskRunner* runner1, | 91 base::SingleThreadTaskRunner* runner1, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 ASSERT_FALSE(is_filesystem_set_up_); | 226 ASSERT_FALSE(is_filesystem_set_up_); |
227 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 227 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
228 | 228 |
229 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 229 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
230 new content::MockSpecialStoragePolicy(); | 230 new content::MockSpecialStoragePolicy(); |
231 | 231 |
232 if (quota_mode == QUOTA_ENABLED) { | 232 if (quota_mode == QUOTA_ENABLED) { |
233 quota_manager_ = new QuotaManager(false /* is_incognito */, | 233 quota_manager_ = new QuotaManager(false /* is_incognito */, |
234 data_dir_.path(), | 234 data_dir_.path(), |
235 io_task_runner_.get(), | 235 io_task_runner_.get(), |
236 base::MessageLoopProxy::current().get(), | 236 base::ThreadTaskRunnerHandle::Get().get(), |
237 storage_policy.get()); | 237 storage_policy.get()); |
238 } | 238 } |
239 | 239 |
240 std::vector<std::string> additional_allowed_schemes; | 240 std::vector<std::string> additional_allowed_schemes; |
241 additional_allowed_schemes.push_back(origin_.scheme()); | 241 additional_allowed_schemes.push_back(origin_.scheme()); |
242 fileapi::FileSystemOptions options( | 242 fileapi::FileSystemOptions options( |
243 fileapi::FileSystemOptions::PROFILE_MODE_NORMAL, | 243 fileapi::FileSystemOptions::PROFILE_MODE_NORMAL, |
244 additional_allowed_schemes, | 244 additional_allowed_schemes, |
245 env_override_); | 245 env_override_); |
246 | 246 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 279 |
280 File::Error CannedSyncableFileSystem::OpenFileSystem() { | 280 File::Error CannedSyncableFileSystem::OpenFileSystem() { |
281 EXPECT_TRUE(is_filesystem_set_up_); | 281 EXPECT_TRUE(is_filesystem_set_up_); |
282 | 282 |
283 io_task_runner_->PostTask( | 283 io_task_runner_->PostTask( |
284 FROM_HERE, | 284 FROM_HERE, |
285 base::Bind(&CannedSyncableFileSystem::DoOpenFileSystem, | 285 base::Bind(&CannedSyncableFileSystem::DoOpenFileSystem, |
286 base::Unretained(this), | 286 base::Unretained(this), |
287 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, | 287 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, |
288 base::Unretained(this), | 288 base::Unretained(this), |
289 base::MessageLoopProxy::current()))); | 289 base::ThreadTaskRunnerHandle::Get()))); |
290 base::MessageLoop::current()->Run(); | 290 base::MessageLoop::current()->Run(); |
291 | 291 |
292 if (backend()->sync_context()) { | 292 if (backend()->sync_context()) { |
293 // Register 'this' as a sync status observer. | 293 // Register 'this' as a sync status observer. |
294 RunOnThread( | 294 RunOnThread( |
295 io_task_runner_.get(), | 295 io_task_runner_.get(), |
296 FROM_HERE, | 296 FROM_HERE, |
297 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver, | 297 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver, |
298 base::Unretained(this))); | 298 base::Unretained(this))); |
299 } | 299 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 sync_status_ = status; | 746 sync_status_ = status; |
747 base::MessageLoop::current()->Quit(); | 747 base::MessageLoop::current()->Quit(); |
748 } | 748 } |
749 | 749 |
750 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { | 750 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { |
751 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 751 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); |
752 backend()->sync_context()->sync_status()->AddObserver(this); | 752 backend()->sync_context()->sync_status()->AddObserver(this); |
753 } | 753 } |
754 | 754 |
755 } // namespace sync_file_system | 755 } // namespace sync_file_system |
OLD | NEW |