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 "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" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 fake_free_disk_space_getter_.get())); | 92 fake_free_disk_space_getter_.get())); |
93 | 93 |
94 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); | 94 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); |
95 | 95 |
96 ASSERT_TRUE(cache_->Initialize()); | 96 ASSERT_TRUE(cache_->Initialize()); |
97 | 97 |
98 SetUpResourceMetadataAndFileSystem(); | 98 SetUpResourceMetadataAndFileSystem(); |
99 } | 99 } |
100 | 100 |
101 void SetUpResourceMetadataAndFileSystem() { | 101 void SetUpResourceMetadataAndFileSystem() { |
102 resource_metadata_.reset(new internal::ResourceMetadata( | 102 metadata_storage_.reset(new internal::ResourceMetadataStorage( |
103 util::GetCacheRootPath(profile_.get()).Append(util::kMetadataDirectory), | 103 util::GetCacheRootPath(profile_.get()).Append(util::kMetadataDirectory), |
104 base::MessageLoopProxy::current())); | 104 base::MessageLoopProxy::current())); |
| 105 ASSERT_TRUE(metadata_storage_->Initialize()); |
| 106 |
| 107 resource_metadata_.reset(new internal::ResourceMetadata( |
| 108 metadata_storage_.get(), base::MessageLoopProxy::current())); |
105 | 109 |
106 file_system_.reset(new FileSystem( | 110 file_system_.reset(new FileSystem( |
107 profile_.get(), | 111 profile_.get(), |
108 cache_.get(), | 112 cache_.get(), |
109 fake_drive_service_.get(), | 113 fake_drive_service_.get(), |
110 scheduler_.get(), | 114 scheduler_.get(), |
111 resource_metadata_.get(), | 115 resource_metadata_.get(), |
112 base::MessageLoopProxy::current(), | 116 base::MessageLoopProxy::current(), |
113 util::GetCacheRootPath(profile_.get()).Append( | 117 util::GetCacheRootPath(profile_.get()).Append( |
114 util::kTemporaryFileDirectory))); | 118 util::kTemporaryFileDirectory))); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 196 |
193 // Sets up a filesystem with directories: drive/root, drive/root/Dir1, | 197 // Sets up a filesystem with directories: drive/root, drive/root/Dir1, |
194 // drive/root/Dir1/SubDir2 and files drive/root/File1, drive/root/Dir1/File2, | 198 // drive/root/Dir1/SubDir2 and files drive/root/File1, drive/root/Dir1/File2, |
195 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets | 199 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets |
196 // the changestamp to 654321, equal to that of "account_metadata.json" test | 200 // the changestamp to 654321, equal to that of "account_metadata.json" test |
197 // data, indicating the cache is holding the latest file system info. | 201 // data, indicating the cache is holding the latest file system info. |
198 bool SetUpTestFileSystem(SetUpTestFileSystemParam param) { | 202 bool SetUpTestFileSystem(SetUpTestFileSystemParam param) { |
199 // Destroy the existing resource metadata to close DB. | 203 // Destroy the existing resource metadata to close DB. |
200 resource_metadata_.reset(); | 204 resource_metadata_.reset(); |
201 | 205 |
202 const std::string root_resource_id = | 206 base::FilePath metadata_directory = |
203 fake_drive_service_->GetRootResourceId(); | 207 util::GetCacheRootPath(profile_.get()).Append(util::kMetadataDirectory); |
| 208 scoped_ptr<internal::ResourceMetadataStorage, |
| 209 test_util::DestroyHelperForTests> metadata_storage( |
| 210 new internal::ResourceMetadataStorage( |
| 211 metadata_directory, base::MessageLoopProxy::current())); |
| 212 |
204 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> | 213 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
205 resource_metadata(new internal::ResourceMetadata( | 214 resource_metadata(new internal::ResourceMetadata( |
206 util::GetCacheRootPath(profile_.get()).Append( | 215 metadata_storage_.get(), base::MessageLoopProxy::current())); |
207 util::kMetadataDirectory), | |
208 base::MessageLoopProxy::current())); | |
209 | 216 |
210 if (resource_metadata->Initialize() != FILE_ERROR_OK) | 217 if (resource_metadata->Initialize() != FILE_ERROR_OK) |
211 return false; | 218 return false; |
212 | 219 |
213 const int64 changestamp = param == USE_SERVER_TIMESTAMP ? 654321 : 1; | 220 const int64 changestamp = param == USE_SERVER_TIMESTAMP ? 654321 : 1; |
214 if (resource_metadata->SetLargestChangestamp(changestamp) != FILE_ERROR_OK) | 221 if (resource_metadata->SetLargestChangestamp(changestamp) != FILE_ERROR_OK) |
215 return false; | 222 return false; |
216 | 223 |
217 // drive/root | 224 // drive/root |
| 225 const std::string root_resource_id = |
| 226 fake_drive_service_->GetRootResourceId(); |
218 if (resource_metadata->AddEntry(util::CreateMyDriveRootEntry( | 227 if (resource_metadata->AddEntry(util::CreateMyDriveRootEntry( |
219 root_resource_id)) != FILE_ERROR_OK) | 228 root_resource_id)) != FILE_ERROR_OK) |
220 return false; | 229 return false; |
221 | 230 |
222 // drive/root/File1 | 231 // drive/root/File1 |
223 ResourceEntry file1; | 232 ResourceEntry file1; |
224 file1.set_title("File1"); | 233 file1.set_title("File1"); |
225 file1.set_resource_id("resource_id:File1"); | 234 file1.set_resource_id("resource_id:File1"); |
226 file1.set_parent_resource_id(root_resource_id); | 235 file1.set_parent_resource_id(root_resource_id); |
227 file1.mutable_file_specific_info()->set_md5("md5"); | 236 file1.mutable_file_specific_info()->set_md5("md5"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 281 |
273 // Recreate resource metadata. | 282 // Recreate resource metadata. |
274 SetUpResourceMetadataAndFileSystem(); | 283 SetUpResourceMetadataAndFileSystem(); |
275 | 284 |
276 return true; | 285 return true; |
277 } | 286 } |
278 | 287 |
279 content::TestBrowserThreadBundle thread_bundle_; | 288 content::TestBrowserThreadBundle thread_bundle_; |
280 scoped_ptr<TestingProfile> profile_; | 289 scoped_ptr<TestingProfile> profile_; |
281 | 290 |
| 291 scoped_ptr<internal::ResourceMetadataStorage, |
| 292 test_util::DestroyHelperForTests> metadata_storage_; |
282 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; | 293 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; |
283 scoped_ptr<FileSystem> file_system_; | 294 scoped_ptr<FileSystem> file_system_; |
284 scoped_ptr<FakeDriveService> fake_drive_service_; | 295 scoped_ptr<FakeDriveService> fake_drive_service_; |
285 scoped_ptr<JobScheduler> scheduler_; | 296 scoped_ptr<JobScheduler> scheduler_; |
286 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> | 297 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
287 resource_metadata_; | 298 resource_metadata_; |
288 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 299 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
289 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; | 300 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; |
290 }; | 301 }; |
291 | 302 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 file_path, | 837 file_path, |
827 google_apis::test_util::CreateCopyResultCallback(&error)); | 838 google_apis::test_util::CreateCopyResultCallback(&error)); |
828 google_apis::test_util::RunBlockingPoolTask(); | 839 google_apis::test_util::RunBlockingPoolTask(); |
829 EXPECT_EQ(FILE_ERROR_OK, error); | 840 EXPECT_EQ(FILE_ERROR_OK, error); |
830 | 841 |
831 // Now able to remove the cache entry. | 842 // Now able to remove the cache entry. |
832 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); | 843 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); |
833 } | 844 } |
834 | 845 |
835 } // namespace drive | 846 } // namespace drive |
OLD | NEW |