| 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 "components/sync_driver/generic_change_processor.h" | 5 #include "components/sync_driver/generic_change_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <string> | 10 #include <string> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "components/sync_driver/data_type_error_handler_mock.h" | 17 #include "components/sync_driver/data_type_error_handler_mock.h" |
| 17 #include "components/sync_driver/fake_sync_client.h" | 18 #include "components/sync_driver/fake_sync_client.h" |
| 18 #include "components/sync_driver/local_device_info_provider.h" | 19 #include "components/sync_driver/local_device_info_provider.h" |
| 19 #include "components/sync_driver/sync_api_component_factory.h" | 20 #include "components/sync_driver/sync_api_component_factory.h" |
| 20 #include "sync/api/attachments/attachment_id.h" | 21 #include "sync/api/attachments/attachment_id.h" |
| 21 #include "sync/api/attachments/attachment_store.h" | 22 #include "sync/api/attachments/attachment_store.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 39 |
| 39 namespace sync_driver { | 40 namespace sync_driver { |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // A mock that keeps track of attachments passed to UploadAttachments. | 44 // A mock that keeps track of attachments passed to UploadAttachments. |
| 44 class MockAttachmentService : public syncer::AttachmentServiceImpl { | 45 class MockAttachmentService : public syncer::AttachmentServiceImpl { |
| 45 public: | 46 public: |
| 46 MockAttachmentService( | 47 MockAttachmentService( |
| 47 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store); | 48 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store); |
| 48 ~MockAttachmentService() override; | 49 ~MockAttachmentService() override; |
| 49 void UploadAttachments( | 50 void UploadAttachments( |
| 50 const syncer::AttachmentIdList& attachment_ids) override; | 51 const syncer::AttachmentIdList& attachment_ids) override; |
| 51 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); | 52 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 std::vector<syncer::AttachmentIdList> attachment_id_lists_; | 55 std::vector<syncer::AttachmentIdList> attachment_id_lists_; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 MockAttachmentService::MockAttachmentService( | 58 MockAttachmentService::MockAttachmentService( |
| 58 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store) | 59 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store) |
| 59 : AttachmentServiceImpl(std::move(attachment_store), | 60 : AttachmentServiceImpl(std::move(attachment_store), |
| 60 scoped_ptr<syncer::AttachmentUploader>( | 61 std::unique_ptr<syncer::AttachmentUploader>( |
| 61 new syncer::FakeAttachmentUploader), | 62 new syncer::FakeAttachmentUploader), |
| 62 scoped_ptr<syncer::AttachmentDownloader>( | 63 std::unique_ptr<syncer::AttachmentDownloader>( |
| 63 new syncer::FakeAttachmentDownloader), | 64 new syncer::FakeAttachmentDownloader), |
| 64 NULL, | 65 NULL, |
| 65 base::TimeDelta(), | 66 base::TimeDelta(), |
| 66 base::TimeDelta()) {} | 67 base::TimeDelta()) {} |
| 67 | 68 |
| 68 MockAttachmentService::~MockAttachmentService() { | 69 MockAttachmentService::~MockAttachmentService() { |
| 69 } | 70 } |
| 70 | 71 |
| 71 void MockAttachmentService::UploadAttachments( | 72 void MockAttachmentService::UploadAttachments( |
| 72 const syncer::AttachmentIdList& attachment_ids) { | 73 const syncer::AttachmentIdList& attachment_ids) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 98 sync_driver::DataTypeManagerObserver* observer) override{ | 99 sync_driver::DataTypeManagerObserver* observer) override{ |
| 99 return nullptr; | 100 return nullptr; |
| 100 }; | 101 }; |
| 101 browser_sync::SyncBackendHost* CreateSyncBackendHost( | 102 browser_sync::SyncBackendHost* CreateSyncBackendHost( |
| 102 const std::string& name, | 103 const std::string& name, |
| 103 invalidation::InvalidationService* invalidator, | 104 invalidation::InvalidationService* invalidator, |
| 104 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | 105 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
| 105 const base::FilePath& sync_folder) override { | 106 const base::FilePath& sync_folder) override { |
| 106 return nullptr; | 107 return nullptr; |
| 107 } | 108 } |
| 108 scoped_ptr<sync_driver::LocalDeviceInfoProvider> | 109 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> |
| 109 CreateLocalDeviceInfoProvider() override { return nullptr; } | 110 CreateLocalDeviceInfoProvider() override { |
| 111 return nullptr; |
| 112 } |
| 110 SyncComponents CreateBookmarkSyncComponents( | 113 SyncComponents CreateBookmarkSyncComponents( |
| 111 sync_driver::SyncService* sync_service, | 114 sync_driver::SyncService* sync_service, |
| 112 sync_driver::DataTypeErrorHandler* error_handler) override { | 115 sync_driver::DataTypeErrorHandler* error_handler) override { |
| 113 return SyncComponents(nullptr, nullptr); | 116 return SyncComponents(nullptr, nullptr); |
| 114 } | 117 } |
| 115 | 118 |
| 116 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | 119 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( |
| 117 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, | 120 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, |
| 118 const syncer::UserShare& user_share, | 121 const syncer::UserShare& user_share, |
| 119 const std::string& store_birthday, | 122 const std::string& store_birthday, |
| 120 syncer::ModelType model_type, | 123 syncer::ModelType model_type, |
| 121 syncer::AttachmentService::Delegate* delegate) override { | 124 syncer::AttachmentService::Delegate* delegate) override { |
| 122 scoped_ptr<MockAttachmentService> attachment_service( | 125 std::unique_ptr<MockAttachmentService> attachment_service( |
| 123 new MockAttachmentService(std::move(attachment_store))); | 126 new MockAttachmentService(std::move(attachment_store))); |
| 124 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 127 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
| 125 // need to have a pointer to it so we can see that it was used properly. | 128 // need to have a pointer to it so we can see that it was used properly. |
| 126 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 129 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
| 127 // destroy it. | 130 // destroy it. |
| 128 mock_attachment_service_ = attachment_service.get(); | 131 mock_attachment_service_ = attachment_service.get(); |
| 129 return std::move(attachment_service); | 132 return std::move(attachment_service); |
| 130 } | 133 } |
| 131 | 134 |
| 132 MockAttachmentService* GetMockAttachmentService() { | 135 MockAttachmentService* GetMockAttachmentService() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); | 180 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); |
| 178 iter.Inc()) { | 181 iter.Inc()) { |
| 179 syncer::TestUserShare::CreateRoot(iter.Get(), | 182 syncer::TestUserShare::CreateRoot(iter.Get(), |
| 180 test_user_share_->user_share()); | 183 test_user_share_->user_share()); |
| 181 } | 184 } |
| 182 test_user_share_->encryption_handler()->Init(); | 185 test_user_share_->encryption_handler()->Init(); |
| 183 ConstructGenericChangeProcessor(type); | 186 ConstructGenericChangeProcessor(type); |
| 184 } | 187 } |
| 185 | 188 |
| 186 void ConstructGenericChangeProcessor(syncer::ModelType type) { | 189 void ConstructGenericChangeProcessor(syncer::ModelType type) { |
| 187 scoped_ptr<syncer::AttachmentStore> attachment_store = | 190 std::unique_ptr<syncer::AttachmentStore> attachment_store = |
| 188 syncer::AttachmentStore::CreateInMemoryStore(); | 191 syncer::AttachmentStore::CreateInMemoryStore(); |
| 189 change_processor_.reset(new GenericChangeProcessor( | 192 change_processor_.reset(new GenericChangeProcessor( |
| 190 type, &data_type_error_handler_, | 193 type, &data_type_error_handler_, |
| 191 syncable_service_ptr_factory_.GetWeakPtr(), | 194 syncable_service_ptr_factory_.GetWeakPtr(), |
| 192 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), | 195 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), |
| 193 &sync_client_, attachment_store->CreateAttachmentStoreForSync())); | 196 &sync_client_, attachment_store->CreateAttachmentStoreForSync())); |
| 194 mock_attachment_service_ = sync_factory_.GetMockAttachmentService(); | 197 mock_attachment_service_ = sync_factory_.GetMockAttachmentService(); |
| 195 } | 198 } |
| 196 | 199 |
| 197 void BuildChildNodes(syncer::ModelType type, int n) { | 200 void BuildChildNodes(syncer::ModelType type, int n) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 215 } | 218 } |
| 216 | 219 |
| 217 void RunLoop() { | 220 void RunLoop() { |
| 218 base::RunLoop run_loop; | 221 base::RunLoop run_loop; |
| 219 run_loop.RunUntilIdle(); | 222 run_loop.RunUntilIdle(); |
| 220 } | 223 } |
| 221 | 224 |
| 222 private: | 225 private: |
| 223 base::MessageLoopForUI loop_; | 226 base::MessageLoopForUI loop_; |
| 224 | 227 |
| 225 scoped_ptr<syncer::SyncMergeResult> sync_merge_result_; | 228 std::unique_ptr<syncer::SyncMergeResult> sync_merge_result_; |
| 226 scoped_ptr<base::WeakPtrFactory<syncer::SyncMergeResult> > | 229 std::unique_ptr<base::WeakPtrFactory<syncer::SyncMergeResult>> |
| 227 merge_result_ptr_factory_; | 230 merge_result_ptr_factory_; |
| 228 | 231 |
| 229 syncer::FakeSyncableService fake_syncable_service_; | 232 syncer::FakeSyncableService fake_syncable_service_; |
| 230 base::WeakPtrFactory<syncer::FakeSyncableService> | 233 base::WeakPtrFactory<syncer::FakeSyncableService> |
| 231 syncable_service_ptr_factory_; | 234 syncable_service_ptr_factory_; |
| 232 | 235 |
| 233 DataTypeErrorHandlerMock data_type_error_handler_; | 236 DataTypeErrorHandlerMock data_type_error_handler_; |
| 234 scoped_ptr<syncer::TestUserShare> test_user_share_; | 237 std::unique_ptr<syncer::TestUserShare> test_user_share_; |
| 235 MockAttachmentService* mock_attachment_service_; | 238 MockAttachmentService* mock_attachment_service_; |
| 236 FakeSyncClient sync_client_; | 239 FakeSyncClient sync_client_; |
| 237 MockSyncApiComponentFactory sync_factory_; | 240 MockSyncApiComponentFactory sync_factory_; |
| 238 | 241 |
| 239 scoped_ptr<GenericChangeProcessor> change_processor_; | 242 std::unique_ptr<GenericChangeProcessor> change_processor_; |
| 240 }; | 243 }; |
| 241 | 244 |
| 242 // Similar to above, but focused on the method that implements sync/api | 245 // Similar to above, but focused on the method that implements sync/api |
| 243 // interfaces and is hence exposed to datatypes directly. | 246 // interfaces and is hence exposed to datatypes directly. |
| 244 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { | 247 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { |
| 245 const int kNumChildNodes = 1000; | 248 const int kNumChildNodes = 1000; |
| 246 const int kRepeatCount = 1; | 249 const int kRepeatCount = 1; |
| 247 | 250 |
| 248 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes)); | 251 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes)); |
| 249 | 252 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 syncer::SyncDataList sync_data = | 539 syncer::SyncDataList sync_data = |
| 537 change_processor()->GetAllSyncData(syncer::SESSIONS); | 540 change_processor()->GetAllSyncData(syncer::SESSIONS); |
| 538 ASSERT_EQ(sync_data.size(), 1U); | 541 ASSERT_EQ(sync_data.size(), 1U); |
| 539 ASSERT_EQ("session tag 2", | 542 ASSERT_EQ("session tag 2", |
| 540 sync_data[0].GetSpecifics().session().session_tag()); | 543 sync_data[0].GetSpecifics().session().session_tag()); |
| 541 } | 544 } |
| 542 | 545 |
| 543 } // namespace | 546 } // namespace |
| 544 | 547 |
| 545 } // namespace sync_driver | 548 } // namespace sync_driver |
| OLD | NEW |