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

Side by Side Diff: components/browser_sync/abstract_profile_sync_service_test.cc

Issue 2533083002: [Sync] SyncEngine refactor part 1: interfaces. (Closed)
Patch Set: Rebase. Created 4 years 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 "components/browser_sync/abstract_profile_sync_service_test.h" 5 #include "components/browser_sync/abstract_profile_sync_service_test.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 13 matching lines...) Expand all
24 24
25 using syncer::SyncBackendHostImpl; 25 using syncer::SyncBackendHostImpl;
26 using syncer::ModelType; 26 using syncer::ModelType;
27 using testing::_; 27 using testing::_;
28 using testing::Return; 28 using testing::Return;
29 29
30 namespace browser_sync { 30 namespace browser_sync {
31 31
32 namespace { 32 namespace {
33 33
34 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { 34 class SyncEngineForProfileSyncTest : public SyncBackendHostImpl {
35 public: 35 public:
36 SyncBackendHostForProfileSyncTest( 36 SyncEngineForProfileSyncTest(
37 const base::FilePath& temp_dir, 37 const base::FilePath& temp_dir,
38 syncer::SyncClient* sync_client, 38 syncer::SyncClient* sync_client,
39 invalidation::InvalidationService* invalidator, 39 invalidation::InvalidationService* invalidator,
40 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs, 40 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs,
41 const base::Closure& callback); 41 const base::Closure& callback);
42 ~SyncBackendHostForProfileSyncTest() override; 42 ~SyncEngineForProfileSyncTest() override;
43 43
44 void RequestConfigureSyncer( 44 void RequestConfigureSyncer(
45 syncer::ConfigureReason reason, 45 syncer::ConfigureReason reason,
46 syncer::ModelTypeSet to_download, 46 syncer::ModelTypeSet to_download,
47 syncer::ModelTypeSet to_purge, 47 syncer::ModelTypeSet to_purge,
48 syncer::ModelTypeSet to_journal, 48 syncer::ModelTypeSet to_journal,
49 syncer::ModelTypeSet to_unapply, 49 syncer::ModelTypeSet to_unapply,
50 syncer::ModelTypeSet to_ignore, 50 syncer::ModelTypeSet to_ignore,
51 const syncer::ModelSafeRoutingInfo& routing_info, 51 const syncer::ModelSafeRoutingInfo& routing_info,
52 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 52 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
53 ready_task, 53 ready_task,
54 const base::Closure& retry_callback) override; 54 const base::Closure& retry_callback) override;
55 55
56 protected: 56 protected:
57 void InitCore(std::unique_ptr<syncer::DoInitializeOptions> options) override; 57 void InitCore(std::unique_ptr<syncer::DoInitializeOptions> options) override;
58 58
59 private: 59 private:
60 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. 60 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
61 // Allows extra initialization work to be performed before the backend comes 61 // Allows extra initialization work to be performed before the engine comes
62 // up. 62 // up.
63 base::Closure callback_; 63 base::Closure callback_;
64 64
65 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest); 65 DISALLOW_COPY_AND_ASSIGN(SyncEngineForProfileSyncTest);
66 }; 66 };
67 67
68 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( 68 SyncEngineForProfileSyncTest::SyncEngineForProfileSyncTest(
69 const base::FilePath& temp_dir, 69 const base::FilePath& temp_dir,
70 syncer::SyncClient* sync_client, 70 syncer::SyncClient* sync_client,
71 invalidation::InvalidationService* invalidator, 71 invalidation::InvalidationService* invalidator,
72 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs, 72 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs,
73 const base::Closure& callback) 73 const base::Closure& callback)
74 : SyncBackendHostImpl( 74 : SyncBackendHostImpl(
75 "dummy_debug_name", 75 "dummy_debug_name",
76 sync_client, 76 sync_client,
77 invalidator, 77 invalidator,
78 sync_prefs, 78 sync_prefs,
79 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))), 79 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))),
80 callback_(callback) {} 80 callback_(callback) {}
81 81
82 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} 82 SyncEngineForProfileSyncTest::~SyncEngineForProfileSyncTest() {}
83 83
84 void SyncBackendHostForProfileSyncTest::InitCore( 84 void SyncEngineForProfileSyncTest::InitCore(
85 std::unique_ptr<syncer::DoInitializeOptions> options) { 85 std::unique_ptr<syncer::DoInitializeOptions> options) {
86 options->http_bridge_factory = base::MakeUnique<TestHttpBridgeFactory>(); 86 options->http_bridge_factory = base::MakeUnique<TestHttpBridgeFactory>();
87 options->sync_manager_factory = 87 options->sync_manager_factory =
88 base::MakeUnique<syncer::SyncManagerFactoryForProfileSyncTest>(callback_); 88 base::MakeUnique<syncer::SyncManagerFactoryForProfileSyncTest>(callback_);
89 options->credentials.email = "testuser@gmail.com"; 89 options->credentials.email = "testuser@gmail.com";
90 options->credentials.sync_token = "token"; 90 options->credentials.sync_token = "token";
91 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); 91 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
92 options->restored_key_for_bootstrapping.clear(); 92 options->restored_key_for_bootstrapping.clear();
93 93
94 // It'd be nice if we avoided creating the EngineComponentsFactory in the 94 // It'd be nice if we avoided creating the EngineComponentsFactory in the
95 // first place, but SyncBackendHost will have created one by now so we must 95 // first place, but SyncEngine will have created one by now so we must free
96 // free it. Grab the switches to pass on first. 96 // it. Grab the switches to pass on first.
97 syncer::EngineComponentsFactory::Switches factory_switches = 97 syncer::EngineComponentsFactory::Switches factory_switches =
98 options->engine_components_factory->GetSwitches(); 98 options->engine_components_factory->GetSwitches();
99 options->engine_components_factory = 99 options->engine_components_factory =
100 base::MakeUnique<syncer::TestEngineComponentsFactory>( 100 base::MakeUnique<syncer::TestEngineComponentsFactory>(
101 factory_switches, syncer::EngineComponentsFactory::STORAGE_IN_MEMORY, 101 factory_switches, syncer::EngineComponentsFactory::STORAGE_IN_MEMORY,
102 nullptr); 102 nullptr);
103 103
104 SyncBackendHostImpl::InitCore(std::move(options)); 104 SyncBackendHostImpl::InitCore(std::move(options));
105 } 105 }
106 106
107 void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer( 107 void SyncEngineForProfileSyncTest::RequestConfigureSyncer(
108 syncer::ConfigureReason reason, 108 syncer::ConfigureReason reason,
109 syncer::ModelTypeSet to_download, 109 syncer::ModelTypeSet to_download,
110 syncer::ModelTypeSet to_purge, 110 syncer::ModelTypeSet to_purge,
111 syncer::ModelTypeSet to_journal, 111 syncer::ModelTypeSet to_journal,
112 syncer::ModelTypeSet to_unapply, 112 syncer::ModelTypeSet to_unapply,
113 syncer::ModelTypeSet to_ignore, 113 syncer::ModelTypeSet to_ignore,
114 const syncer::ModelSafeRoutingInfo& routing_info, 114 const syncer::ModelSafeRoutingInfo& routing_info,
115 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 115 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
116 ready_task, 116 ready_task,
117 const base::Closure& retry_callback) { 117 const base::Closure& retry_callback) {
118 syncer::ModelTypeSet failed_configuration_types; 118 syncer::ModelTypeSet failed_configuration_types;
119 119
120 // The first parameter there should be the set of enabled types. That's not 120 // The first parameter there should be the set of enabled types. That's not
121 // something we have access to from this strange test harness. We'll just 121 // something we have access to from this strange test harness. We'll just
122 // send back the list of newly configured types instead and hope it doesn't 122 // send back the list of newly configured types instead and hope it doesn't
123 // break anything. 123 // break anything.
124 // Posted to avoid re-entrancy issues. 124 // Posted to avoid re-entrancy issues.
125 base::ThreadTaskRunnerHandle::Get()->PostTask( 125 base::ThreadTaskRunnerHandle::Get()->PostTask(
126 FROM_HERE, 126 FROM_HERE,
127 base::Bind(&SyncBackendHostForProfileSyncTest:: 127 base::Bind(
128 FinishConfigureDataTypesOnFrontendLoop, 128 &SyncEngineForProfileSyncTest::FinishConfigureDataTypesOnFrontendLoop,
129 base::Unretained(this), 129 base::Unretained(this),
130 syncer::Difference(to_download, failed_configuration_types), 130 syncer::Difference(to_download, failed_configuration_types),
131 syncer::Difference(to_download, failed_configuration_types), 131 syncer::Difference(to_download, failed_configuration_types),
132 failed_configuration_types, ready_task)); 132 failed_configuration_types, ready_task));
133 } 133 }
134 134
135 // Helper function for return-type-upcasting of the callback. 135 // Helper function for return-type-upcasting of the callback.
136 syncer::SyncService* GetSyncService( 136 syncer::SyncService* GetSyncService(
137 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) { 137 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) {
138 return get_sync_service_callback.Run(); 138 return get_sync_service_callback.Run();
139 } 139 }
140 140
141 } // namespace 141 } // namespace
142 142
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 const base::Closure& initialization_success_callback) { 184 const base::Closure& initialization_success_callback) {
185 DCHECK(sync_client); 185 DCHECK(sync_client);
186 ProfileSyncService::InitParams init_params = 186 ProfileSyncService::InitParams init_params =
187 profile_sync_service_bundle_.CreateBasicInitParams( 187 profile_sync_service_bundle_.CreateBasicInitParams(
188 ProfileSyncService::AUTO_START, std::move(sync_client)); 188 ProfileSyncService::AUTO_START, std::move(sync_client));
189 sync_service_ = 189 sync_service_ =
190 base::MakeUnique<TestProfileSyncService>(std::move(init_params)); 190 base::MakeUnique<TestProfileSyncService>(std::move(init_params));
191 191
192 syncer::SyncApiComponentFactoryMock* components = 192 syncer::SyncApiComponentFactoryMock* components =
193 profile_sync_service_bundle_.component_factory(); 193 profile_sync_service_bundle_.component_factory();
194 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _)) 194 EXPECT_CALL(*components, CreateSyncEngine(_, _, _, _))
195 .WillOnce(Return(new SyncBackendHostForProfileSyncTest( 195 .WillOnce(Return(new SyncEngineForProfileSyncTest(
196 temp_dir_.GetPath(), sync_service_->GetSyncClient(), 196 temp_dir_.GetPath(), sync_service_->GetSyncClient(),
197 profile_sync_service_bundle_.fake_invalidation_service(), 197 profile_sync_service_bundle_.fake_invalidation_service(),
198 sync_service_->sync_prefs()->AsWeakPtr(), 198 sync_service_->sync_prefs()->AsWeakPtr(),
199 initialization_success_callback))); 199 initialization_success_callback)));
200 200
201 sync_service_->SetFirstSetupComplete(); 201 sync_service_->SetFirstSetupComplete();
202 } 202 }
203 203
204 base::Callback<syncer::SyncService*(void)> 204 base::Callback<syncer::SyncService*(void)>
205 AbstractProfileSyncServiceTest::GetSyncServiceCallback() { 205 AbstractProfileSyncServiceTest::GetSyncServiceCallback() {
(...skipping 18 matching lines...) Expand all
224 224
225 bool CreateRootHelper::success() { 225 bool CreateRootHelper::success() {
226 return success_; 226 return success_;
227 } 227 }
228 228
229 void CreateRootHelper::CreateRootCallback() { 229 void CreateRootHelper::CreateRootCallback() {
230 success_ = test_->CreateRoot(model_type_); 230 success_ = test_->CreateRoot(model_type_);
231 } 231 }
232 232
233 } // namespace browser_sync 233 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_proxy_backend.h ('k') | components/browser_sync/profile_sync_components_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698