| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <stack> | 6 #include <stack> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); | 105 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); |
| 106 | 106 |
| 107 scoped_ptr<drive::DriveUploaderInterface> uploader( | 107 scoped_ptr<drive::DriveUploaderInterface> uploader( |
| 108 new drive::DriveUploader(drive_service.get(), | 108 new drive::DriveUploader(drive_service.get(), |
| 109 file_task_runner_.get())); | 109 file_task_runner_.get())); |
| 110 | 110 |
| 111 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( | 111 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( |
| 112 drive_service.get(), uploader.get(), | 112 drive_service.get(), uploader.get(), |
| 113 kSyncRootFolderTitle)); | 113 kSyncRootFolderTitle)); |
| 114 | 114 |
| 115 remote_sync_service_.reset(new SyncEngine( | 115 remote_sync_service_.reset( |
| 116 base::ThreadTaskRunnerHandle::Get(), // ui_task_runner | 116 new SyncEngine(base::ThreadTaskRunnerHandle::Get(), // ui_task_runner |
| 117 worker_task_runner_, | 117 worker_task_runner_.get(), |
| 118 drive_task_runner, | 118 drive_task_runner.get(), |
| 119 base_dir_.path(), | 119 base_dir_.path(), |
| 120 NULL, // task_logger | 120 NULL, // task_logger |
| 121 NULL, // notification_manager | 121 NULL, // notification_manager |
| 122 NULL, // extension_service | 122 NULL, // extension_service |
| 123 NULL, // signin_manager | 123 NULL, // signin_manager |
| 124 NULL, // token_service | 124 NULL, // token_service |
| 125 NULL, // request_context | 125 NULL, // request_context |
| 126 scoped_ptr<SyncEngine::DriveServiceFactory>(), | 126 scoped_ptr<SyncEngine::DriveServiceFactory>(), |
| 127 in_memory_env_.get())); | 127 in_memory_env_.get())); |
| 128 remote_sync_service_->AddServiceObserver(this); | 128 remote_sync_service_->AddServiceObserver(this); |
| 129 remote_sync_service_->InitializeForTesting( | 129 remote_sync_service_->InitializeForTesting( |
| 130 drive_service.PassAs<drive::DriveServiceInterface>(), | 130 drive_service.PassAs<drive::DriveServiceInterface>(), |
| 131 uploader.Pass(), | 131 uploader.Pass(), |
| 132 scoped_ptr<SyncWorkerInterface>()); | 132 scoped_ptr<SyncWorkerInterface>()); |
| 133 remote_sync_service_->SetSyncEnabled(true); | 133 remote_sync_service_->SetSyncEnabled(true); |
| 134 | 134 |
| 135 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); | 135 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); |
| 136 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); | 136 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); |
| 137 } | 137 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); | 175 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); |
| 176 return CreateSyncableFileSystemURL(origin, path); | 176 return CreateSyncableFileSystemURL(origin, path); |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool GetAppRootFolderID(const std::string& app_id, | 179 bool GetAppRootFolderID(const std::string& app_id, |
| 180 std::string* folder_id) { | 180 std::string* folder_id) { |
| 181 base::RunLoop run_loop; | 181 base::RunLoop run_loop; |
| 182 bool success = false; | 182 bool success = false; |
| 183 FileTracker tracker; | 183 FileTracker tracker; |
| 184 PostTaskAndReplyWithResult( | 184 PostTaskAndReplyWithResult( |
| 185 worker_task_runner_, | 185 worker_task_runner_.get(), |
| 186 FROM_HERE, | 186 FROM_HERE, |
| 187 base::Bind(&MetadataDatabase::FindAppRootTracker, | 187 base::Bind(&MetadataDatabase::FindAppRootTracker, |
| 188 base::Unretained(metadata_database()), | 188 base::Unretained(metadata_database()), |
| 189 app_id, | 189 app_id, |
| 190 &tracker), | 190 &tracker), |
| 191 base::Bind(&SetValueAndCallClosure<bool>, | 191 base::Bind( |
| 192 run_loop.QuitClosure(), | 192 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success)); |
| 193 &success)); | |
| 194 run_loop.Run(); | 193 run_loop.Run(); |
| 195 if (!success) | 194 if (!success) |
| 196 return false; | 195 return false; |
| 197 *folder_id = tracker.file_id(); | 196 *folder_id = tracker.file_id(); |
| 198 return true; | 197 return true; |
| 199 } | 198 } |
| 200 | 199 |
| 201 std::string GetFileIDByPath(const std::string& app_id, | 200 std::string GetFileIDByPath(const std::string& app_id, |
| 202 const base::FilePath::StringType& path) { | 201 const base::FilePath::StringType& path) { |
| 203 return GetFileIDByPath(app_id, base::FilePath(path)); | 202 return GetFileIDByPath(app_id, base::FilePath(path)); |
| 204 } | 203 } |
| 205 | 204 |
| 206 std::string GetFileIDByPath(const std::string& app_id, | 205 std::string GetFileIDByPath(const std::string& app_id, |
| 207 const base::FilePath& path) { | 206 const base::FilePath& path) { |
| 208 base::RunLoop run_loop; | 207 base::RunLoop run_loop; |
| 209 bool success = false; | 208 bool success = false; |
| 210 FileTracker tracker; | 209 FileTracker tracker; |
| 211 base::FilePath result_path; | 210 base::FilePath result_path; |
| 212 base::FilePath normalized_path = path.NormalizePathSeparators(); | 211 base::FilePath normalized_path = path.NormalizePathSeparators(); |
| 213 PostTaskAndReplyWithResult( | 212 PostTaskAndReplyWithResult( |
| 214 worker_task_runner_, | 213 worker_task_runner_.get(), |
| 215 FROM_HERE, | 214 FROM_HERE, |
| 216 base::Bind(&MetadataDatabase::FindNearestActiveAncestor, | 215 base::Bind(&MetadataDatabase::FindNearestActiveAncestor, |
| 217 base::Unretained(metadata_database()), | 216 base::Unretained(metadata_database()), |
| 218 app_id, | 217 app_id, |
| 219 normalized_path, | 218 normalized_path, |
| 220 &tracker, | 219 &tracker, |
| 221 &result_path), | 220 &result_path), |
| 222 base::Bind(&SetValueAndCallClosure<bool>, | 221 base::Bind( |
| 223 run_loop.QuitClosure(), | 222 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success)); |
| 224 &success)); | |
| 225 run_loop.Run(); | 223 run_loop.Run(); |
| 226 EXPECT_TRUE(success); | 224 EXPECT_TRUE(success); |
| 227 EXPECT_EQ(normalized_path, result_path); | 225 EXPECT_EQ(normalized_path, result_path); |
| 228 return tracker.file_id(); | 226 return tracker.file_id(); |
| 229 } | 227 } |
| 230 | 228 |
| 231 SyncStatusCode RegisterApp(const std::string& app_id) { | 229 SyncStatusCode RegisterApp(const std::string& app_id) { |
| 232 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); | 230 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); |
| 233 if (!ContainsKey(file_systems_, app_id)) { | 231 if (!ContainsKey(file_systems_, app_id)) { |
| 234 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( | 232 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 local_sync_service_->PromoteDemotedChanges(run_loop.QuitClosure()); | 370 local_sync_service_->PromoteDemotedChanges(run_loop.QuitClosure()); |
| 373 run_loop.Run(); | 371 run_loop.Run(); |
| 374 } | 372 } |
| 375 | 373 |
| 376 if (pending_remote_changes_ || pending_local_changes_) | 374 if (pending_remote_changes_ || pending_local_changes_) |
| 377 continue; | 375 continue; |
| 378 | 376 |
| 379 base::RunLoop run_loop; | 377 base::RunLoop run_loop; |
| 380 int64 largest_fetched_change_id = -1; | 378 int64 largest_fetched_change_id = -1; |
| 381 PostTaskAndReplyWithResult( | 379 PostTaskAndReplyWithResult( |
| 382 worker_task_runner_, | 380 worker_task_runner_.get(), |
| 383 FROM_HERE, | 381 FROM_HERE, |
| 384 base::Bind(&MetadataDatabase::GetLargestFetchedChangeID, | 382 base::Bind(&MetadataDatabase::GetLargestFetchedChangeID, |
| 385 base::Unretained(metadata_database())), | 383 base::Unretained(metadata_database())), |
| 386 base::Bind(&SetValueAndCallClosure<int64>, | 384 base::Bind(&SetValueAndCallClosure<int64>, |
| 387 run_loop.QuitClosure(), | 385 run_loop.QuitClosure(), |
| 388 &largest_fetched_change_id)); | 386 &largest_fetched_change_id)); |
| 389 run_loop.Run(); | 387 run_loop.Run(); |
| 390 if (largest_fetched_change_id != GetLargestChangeID()) { | 388 if (largest_fetched_change_id != GetLargestChangeID()) { |
| 391 FetchRemoteChanges(); | 389 FetchRemoteChanges(); |
| 392 continue; | 390 continue; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 << ", path = " << path); | 556 << ", path = " << path); |
| 559 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 557 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); |
| 560 EXPECT_EQ(base::File::FILE_OK, | 558 EXPECT_EQ(base::File::FILE_OK, |
| 561 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path))); | 559 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path))); |
| 562 } | 560 } |
| 563 | 561 |
| 564 size_t CountMetadata() { | 562 size_t CountMetadata() { |
| 565 size_t count = 0; | 563 size_t count = 0; |
| 566 base::RunLoop run_loop; | 564 base::RunLoop run_loop; |
| 567 PostTaskAndReplyWithResult( | 565 PostTaskAndReplyWithResult( |
| 568 worker_task_runner_, | 566 worker_task_runner_.get(), |
| 569 FROM_HERE, | 567 FROM_HERE, |
| 570 base::Bind(&MetadataDatabase::CountFileMetadata, | 568 base::Bind(&MetadataDatabase::CountFileMetadata, |
| 571 base::Unretained(metadata_database())), | 569 base::Unretained(metadata_database())), |
| 572 base::Bind(&SetValueAndCallClosure<size_t>, | 570 base::Bind( |
| 573 run_loop.QuitClosure(), | 571 &SetValueAndCallClosure<size_t>, run_loop.QuitClosure(), &count)); |
| 574 &count)); | |
| 575 run_loop.Run(); | 572 run_loop.Run(); |
| 576 return count; | 573 return count; |
| 577 } | 574 } |
| 578 | 575 |
| 579 size_t CountTracker() { | 576 size_t CountTracker() { |
| 580 size_t count = 0; | 577 size_t count = 0; |
| 581 base::RunLoop run_loop; | 578 base::RunLoop run_loop; |
| 582 PostTaskAndReplyWithResult( | 579 PostTaskAndReplyWithResult( |
| 583 worker_task_runner_, | 580 worker_task_runner_.get(), |
| 584 FROM_HERE, | 581 FROM_HERE, |
| 585 base::Bind(&MetadataDatabase::CountFileTracker, | 582 base::Bind(&MetadataDatabase::CountFileTracker, |
| 586 base::Unretained(metadata_database())), | 583 base::Unretained(metadata_database())), |
| 587 base::Bind(&SetValueAndCallClosure<size_t>, | 584 base::Bind( |
| 588 run_loop.QuitClosure(), &count)); | 585 &SetValueAndCallClosure<size_t>, run_loop.QuitClosure(), &count)); |
| 589 run_loop.Run(); | 586 run_loop.Run(); |
| 590 return count; | 587 return count; |
| 591 } | 588 } |
| 592 | 589 |
| 593 drive::FakeDriveService* fake_drive_service() { | 590 drive::FakeDriveService* fake_drive_service() { |
| 594 return static_cast<drive::FakeDriveService*>( | 591 return static_cast<drive::FakeDriveService*>( |
| 595 remote_sync_service_->drive_service_.get()); | 592 remote_sync_service_->drive_service_.get()); |
| 596 } | 593 } |
| 597 | 594 |
| 598 FakeDriveServiceHelper* fake_drive_service_helper() { | 595 FakeDriveServiceHelper* fake_drive_service_helper() { |
| (...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 | 1721 |
| 1725 EXPECT_EQ(1u, CountApp()); | 1722 EXPECT_EQ(1u, CountApp()); |
| 1726 EXPECT_EQ(1u, CountLocalFile(app_id)); | 1723 EXPECT_EQ(1u, CountLocalFile(app_id)); |
| 1727 | 1724 |
| 1728 EXPECT_EQ(2u, CountMetadata()); | 1725 EXPECT_EQ(2u, CountMetadata()); |
| 1729 EXPECT_EQ(2u, CountTracker()); | 1726 EXPECT_EQ(2u, CountTracker()); |
| 1730 } | 1727 } |
| 1731 | 1728 |
| 1732 } // namespace drive_backend | 1729 } // namespace drive_backend |
| 1733 } // namespace sync_file_system | 1730 } // namespace sync_file_system |
| OLD | NEW |