Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 1124813003: [chrome/browser/chromeos/drive] Avoid use of MessageLoopProxy by use of TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments 3 : Indent Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/prefs/testing_pref_service.h" 15 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h"
18 #include "base/thread_task_runner_handle.h"
18 #include "chrome/browser/chromeos/drive/change_list_loader.h" 19 #include "chrome/browser/chromeos/drive/change_list_loader.h"
19 #include "chrome/browser/chromeos/drive/drive.pb.h" 20 #include "chrome/browser/chromeos/drive/drive.pb.h"
20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 21 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
21 #include "chrome/browser/chromeos/drive/file_change.h" 22 #include "chrome/browser/chromeos/drive/file_change.h"
22 #include "chrome/browser/chromeos/drive/file_system_observer.h" 23 #include "chrome/browser/chromeos/drive/file_system_observer.h"
23 #include "chrome/browser/chromeos/drive/file_system_util.h" 24 #include "chrome/browser/chromeos/drive/file_system_util.h"
24 #include "chrome/browser/chromeos/drive/job_scheduler.h" 25 #include "chrome/browser/chromeos/drive/job_scheduler.h"
25 #include "chrome/browser/chromeos/drive/sync_client.h" 26 #include "chrome/browser/chromeos/drive/sync_client.h"
26 #include "chrome/browser/chromeos/drive/test_util.h" 27 #include "chrome/browser/chromeos/drive/test_util.h"
27 #include "chrome/browser/drive/drive_api_util.h" 28 #include "chrome/browser/drive/drive_api_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
100 pref_service_.reset(new TestingPrefServiceSimple); 101 pref_service_.reset(new TestingPrefServiceSimple);
101 test_util::RegisterDrivePrefs(pref_service_->registry()); 102 test_util::RegisterDrivePrefs(pref_service_->registry());
102 103
103 logger_.reset(new EventLogger); 104 logger_.reset(new EventLogger);
104 fake_drive_service_.reset(new FakeDriveService); 105 fake_drive_service_.reset(new FakeDriveService);
105 test_util::SetUpTestEntries(fake_drive_service_.get()); 106 test_util::SetUpTestEntries(fake_drive_service_.get());
106 107
107 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); 108 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
108 109
109 scheduler_.reset(new JobScheduler(pref_service_.get(), 110 scheduler_.reset(new JobScheduler(
110 logger_.get(), 111 pref_service_.get(),
111 fake_drive_service_.get(), 112 logger_.get(),
112 base::MessageLoopProxy::current().get())); 113 fake_drive_service_.get(),
114 base::ThreadTaskRunnerHandle::Get().get()));
113 115
114 mock_directory_observer_.reset(new MockDirectoryChangeObserver); 116 mock_directory_observer_.reset(new MockDirectoryChangeObserver);
115 117
116 SetUpResourceMetadataAndFileSystem(); 118 SetUpResourceMetadataAndFileSystem();
117 } 119 }
118 120
119 void SetUpResourceMetadataAndFileSystem() { 121 void SetUpResourceMetadataAndFileSystem() {
120 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); 122 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta");
121 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); 123 ASSERT_TRUE(base::CreateDirectory(metadata_dir));
122 metadata_storage_.reset(new internal::ResourceMetadataStorage( 124 metadata_storage_.reset(new internal::ResourceMetadataStorage(
123 metadata_dir, base::MessageLoopProxy::current().get())); 125 metadata_dir, base::ThreadTaskRunnerHandle::Get().get()));
124 ASSERT_TRUE(metadata_storage_->Initialize()); 126 ASSERT_TRUE(metadata_storage_->Initialize());
125 127
126 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files"); 128 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files");
127 ASSERT_TRUE(base::CreateDirectory(cache_dir)); 129 ASSERT_TRUE(base::CreateDirectory(cache_dir));
128 cache_.reset(new internal::FileCache( 130 cache_.reset(new internal::FileCache(
129 metadata_storage_.get(), 131 metadata_storage_.get(),
130 cache_dir, 132 cache_dir,
131 base::MessageLoopProxy::current().get(), 133 base::ThreadTaskRunnerHandle::Get().get(),
132 fake_free_disk_space_getter_.get())); 134 fake_free_disk_space_getter_.get()));
133 ASSERT_TRUE(cache_->Initialize()); 135 ASSERT_TRUE(cache_->Initialize());
134 136
135 resource_metadata_.reset(new internal::ResourceMetadata( 137 resource_metadata_.reset(new internal::ResourceMetadata(
136 metadata_storage_.get(), cache_.get(), 138 metadata_storage_.get(), cache_.get(),
137 base::MessageLoopProxy::current())); 139 base::ThreadTaskRunnerHandle::Get()));
138 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); 140 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
139 141
140 const base::FilePath temp_file_dir = temp_dir_.path().AppendASCII("tmp"); 142 const base::FilePath temp_file_dir = temp_dir_.path().AppendASCII("tmp");
141 ASSERT_TRUE(base::CreateDirectory(temp_file_dir)); 143 ASSERT_TRUE(base::CreateDirectory(temp_file_dir));
142 file_system_.reset(new FileSystem( 144 file_system_.reset(new FileSystem(
143 pref_service_.get(), 145 pref_service_.get(),
144 logger_.get(), 146 logger_.get(),
145 cache_.get(), 147 cache_.get(),
146 scheduler_.get(), 148 scheduler_.get(),
147 resource_metadata_.get(), 149 resource_metadata_.get(),
148 base::MessageLoopProxy::current().get(), 150 base::ThreadTaskRunnerHandle::Get().get(),
149 temp_file_dir)); 151 temp_file_dir));
150 file_system_->AddObserver(mock_directory_observer_.get()); 152 file_system_->AddObserver(mock_directory_observer_.get());
151 153
152 // Disable delaying so that the sync starts immediately. 154 // Disable delaying so that the sync starts immediately.
153 file_system_->sync_client_for_testing()->set_delay_for_testing( 155 file_system_->sync_client_for_testing()->set_delay_for_testing(
154 base::TimeDelta::FromSeconds(0)); 156 base::TimeDelta::FromSeconds(0));
155 } 157 }
156 158
157 // Loads the full resource list via FakeDriveService. 159 // Loads the full resource list via FakeDriveService.
158 bool LoadFullResourceList() { 160 bool LoadFullResourceList() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // holding the latest file system info. 219 // holding the latest file system info.
218 void SetUpTestFileSystem(SetUpTestFileSystemParam param) { 220 void SetUpTestFileSystem(SetUpTestFileSystemParam param) {
219 // Destroy the existing resource metadata to close DB. 221 // Destroy the existing resource metadata to close DB.
220 resource_metadata_.reset(); 222 resource_metadata_.reset();
221 223
222 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); 224 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta");
223 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); 225 ASSERT_TRUE(base::CreateDirectory(metadata_dir));
224 scoped_ptr<internal::ResourceMetadataStorage, 226 scoped_ptr<internal::ResourceMetadataStorage,
225 test_util::DestroyHelperForTests> metadata_storage( 227 test_util::DestroyHelperForTests> metadata_storage(
226 new internal::ResourceMetadataStorage( 228 new internal::ResourceMetadataStorage(
227 metadata_dir, base::MessageLoopProxy::current().get())); 229 metadata_dir, base::ThreadTaskRunnerHandle::Get().get()));
228 230
229 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files"); 231 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files");
230 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache( 232 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache(
231 new internal::FileCache(metadata_storage.get(), 233 new internal::FileCache(metadata_storage.get(),
232 cache_dir, 234 cache_dir,
233 base::MessageLoopProxy::current().get(), 235 base::ThreadTaskRunnerHandle::Get().get(),
234 fake_free_disk_space_getter_.get())); 236 fake_free_disk_space_getter_.get()));
235 237
236 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 238 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
237 resource_metadata(new internal::ResourceMetadata( 239 resource_metadata(new internal::ResourceMetadata(
238 metadata_storage_.get(), cache.get(), 240 metadata_storage_.get(), cache.get(),
239 base::MessageLoopProxy::current())); 241 base::ThreadTaskRunnerHandle::Get()));
240 242
241 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize()); 243 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize());
242 244
243 const int64 changestamp = param == USE_SERVER_TIMESTAMP ? 245 const int64 changestamp = param == USE_SERVER_TIMESTAMP ?
244 fake_drive_service_->about_resource().largest_change_id() : 1; 246 fake_drive_service_->about_resource().largest_change_id() : 1;
245 ASSERT_EQ(FILE_ERROR_OK, 247 ASSERT_EQ(FILE_ERROR_OK,
246 resource_metadata->SetLargestChangestamp(changestamp)); 248 resource_metadata->SetLargestChangestamp(changestamp));
247 249
248 // drive/root 250 // drive/root
249 ResourceEntry root; 251 ResourceEntry root;
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 google_apis::test_util::CreateCopyResultCallback(&available)); 1052 google_apis::test_util::CreateCopyResultCallback(&available));
1051 content::RunAllBlockingPoolTasksUntilIdle(); 1053 content::RunAllBlockingPoolTasksUntilIdle();
1052 ASSERT_FALSE(available); 1054 ASSERT_FALSE(available);
1053 1055
1054 entry = GetResourceEntrySync(file_in_root); 1056 entry = GetResourceEntrySync(file_in_root);
1055 ASSERT_TRUE(entry); 1057 ASSERT_TRUE(entry);
1056 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); 1058 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present());
1057 } 1059 }
1058 1060
1059 } // namespace drive 1061 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/truncate_operation.cc ('k') | chrome/browser/chromeos/drive/file_system_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698