| 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 "components/sync_driver/glue/sync_backend_host_impl.h" | 5 #include "components/sync_driver/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
| 8 #include <cstddef> | 9 #include <cstddef> |
| 9 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 10 #include <utility> | 12 #include <utility> |
| 11 | 13 |
| 12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/location.h" | 16 #include "base/location.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
| 20 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "components/invalidation/impl/invalidator_storage.h" | 23 #include "components/invalidation/impl/invalidator_storage.h" |
| 23 #include "components/invalidation/impl/profile_invalidation_provider.h" | 24 #include "components/invalidation/impl/profile_invalidation_provider.h" |
| 24 #include "components/invalidation/public/invalidator_state.h" | 25 #include "components/invalidation/public/invalidator_state.h" |
| 25 #include "components/invalidation/public/object_id_invalidation_map.h" | 26 #include "components/invalidation/public/object_id_invalidation_map.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 120 |
| 120 class FakeSyncManagerFactory : public syncer::SyncManagerFactory { | 121 class FakeSyncManagerFactory : public syncer::SyncManagerFactory { |
| 121 public: | 122 public: |
| 122 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager) | 123 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager) |
| 123 : fake_manager_(fake_manager) { | 124 : fake_manager_(fake_manager) { |
| 124 *fake_manager_ = NULL; | 125 *fake_manager_ = NULL; |
| 125 } | 126 } |
| 126 ~FakeSyncManagerFactory() override {} | 127 ~FakeSyncManagerFactory() override {} |
| 127 | 128 |
| 128 // SyncManagerFactory implementation. Called on the sync thread. | 129 // SyncManagerFactory implementation. Called on the sync thread. |
| 129 scoped_ptr<SyncManager> CreateSyncManager( | 130 std::unique_ptr<SyncManager> CreateSyncManager( |
| 130 const std::string& /* name */) override { | 131 const std::string& /* name */) override { |
| 131 *fake_manager_ = new FakeSyncManager(initial_sync_ended_types_, | 132 *fake_manager_ = new FakeSyncManager(initial_sync_ended_types_, |
| 132 progress_marker_types_, | 133 progress_marker_types_, |
| 133 configure_fail_types_); | 134 configure_fail_types_); |
| 134 return scoped_ptr<SyncManager>(*fake_manager_); | 135 return std::unique_ptr<SyncManager>(*fake_manager_); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void set_initial_sync_ended_types(syncer::ModelTypeSet types) { | 138 void set_initial_sync_ended_types(syncer::ModelTypeSet types) { |
| 138 initial_sync_ended_types_ = types; | 139 initial_sync_ended_types_ = types; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void set_progress_marker_types(syncer::ModelTypeSet types) { | 142 void set_progress_marker_types(syncer::ModelTypeSet types) { |
| 142 progress_marker_types_ = types; | 143 progress_marker_types_ = types; |
| 143 } | 144 } |
| 144 | 145 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void InitializeBackend(bool expect_success) { | 223 void InitializeBackend(bool expect_success) { |
| 223 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)). | 224 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)). |
| 224 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 225 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 225 SyncBackendHost::HttpPostProviderFactoryGetter | 226 SyncBackendHost::HttpPostProviderFactoryGetter |
| 226 http_post_provider_factory_getter = | 227 http_post_provider_factory_getter = |
| 227 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 228 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 228 base::Unretained(network_resources_.get()), | 229 base::Unretained(network_resources_.get()), |
| 229 nullptr, | 230 nullptr, |
| 230 base::Bind(&EmptyNetworkTimeUpdate)); | 231 base::Bind(&EmptyNetworkTimeUpdate)); |
| 231 backend_->Initialize( | 232 backend_->Initialize( |
| 232 &mock_frontend_, scoped_ptr<base::Thread>(), | 233 &mock_frontend_, std::unique_ptr<base::Thread>(), |
| 233 base::ThreadTaskRunnerHandle::Get(), | 234 base::ThreadTaskRunnerHandle::Get(), |
| 234 base::ThreadTaskRunnerHandle::Get(), | 235 base::ThreadTaskRunnerHandle::Get(), |
| 235 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), | 236 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), |
| 236 std::string(), credentials_, true, std::move(fake_manager_factory_), | 237 std::string(), credentials_, true, std::move(fake_manager_factory_), |
| 237 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), | 238 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), |
| 238 base::Closure(), http_post_provider_factory_getter, | 239 base::Closure(), http_post_provider_factory_getter, |
| 239 std::move(saved_nigori_state_)); | 240 std::move(saved_nigori_state_)); |
| 240 base::RunLoop run_loop; | 241 base::RunLoop run_loop; |
| 241 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, | 242 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, |
| 242 run_loop.QuitClosure(), | 243 run_loop.QuitClosure(), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 NOTIMPLEMENTED(); | 291 NOTIMPLEMENTED(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 base::MessageLoop message_loop_; | 294 base::MessageLoop message_loop_; |
| 294 base::ScopedTempDir temp_dir_; | 295 base::ScopedTempDir temp_dir_; |
| 295 syncable_prefs::TestingPrefServiceSyncable pref_service_; | 296 syncable_prefs::TestingPrefServiceSyncable pref_service_; |
| 296 StrictMock<MockSyncFrontend> mock_frontend_; | 297 StrictMock<MockSyncFrontend> mock_frontend_; |
| 297 syncer::SyncCredentials credentials_; | 298 syncer::SyncCredentials credentials_; |
| 298 BackendSyncClient sync_client_; | 299 BackendSyncClient sync_client_; |
| 299 syncer::TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; | 300 syncer::TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; |
| 300 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; | 301 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; |
| 301 scoped_ptr<SyncBackendHostImpl> backend_; | 302 std::unique_ptr<SyncBackendHostImpl> backend_; |
| 302 scoped_ptr<FakeSyncManagerFactory> fake_manager_factory_; | 303 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_; |
| 303 FakeSyncManager* fake_manager_; | 304 FakeSyncManager* fake_manager_; |
| 304 syncer::ModelTypeSet enabled_types_; | 305 syncer::ModelTypeSet enabled_types_; |
| 305 scoped_ptr<syncer::NetworkResources> network_resources_; | 306 std::unique_ptr<syncer::NetworkResources> network_resources_; |
| 306 scoped_ptr<syncer::SyncEncryptionHandler::NigoriState> saved_nigori_state_; | 307 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> |
| 308 saved_nigori_state_; |
| 307 }; | 309 }; |
| 308 | 310 |
| 309 // Test basic initialization with no initial types (first time initialization). | 311 // Test basic initialization with no initial types (first time initialization). |
| 310 // Only the nigori should be configured. | 312 // Only the nigori should be configured. |
| 311 TEST_F(SyncBackendHostTest, InitShutdown) { | 313 TEST_F(SyncBackendHostTest, InitShutdown) { |
| 312 InitializeBackend(true); | 314 InitializeBackend(true); |
| 313 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 315 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
| 314 syncer::ControlTypes())); | 316 syncer::ControlTypes())); |
| 315 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 317 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
| 316 syncer::ControlTypes())); | 318 syncer::ControlTypes())); |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 EXPECT_EQ(invalidation_versions.size(), | 851 EXPECT_EQ(invalidation_versions.size(), |
| 850 persisted_invalidation_versions.size()); | 852 persisted_invalidation_versions.size()); |
| 851 for (auto iter : persisted_invalidation_versions) { | 853 for (auto iter : persisted_invalidation_versions) { |
| 852 EXPECT_EQ(invalidation_versions[iter.first], iter.second); | 854 EXPECT_EQ(invalidation_versions[iter.first], iter.second); |
| 853 } | 855 } |
| 854 } | 856 } |
| 855 | 857 |
| 856 } // namespace | 858 } // namespace |
| 857 | 859 |
| 858 } // namespace browser_sync | 860 } // namespace browser_sync |
| OLD | NEW |