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/engine_impl/model_type_registry.h" | 5 #include "components/sync/engine_impl/model_type_registry.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/deferred_sequenced_task_runner.h" | 10 #include "base/deferred_sequenced_task_runner.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 ModelTypeRegistry* registry(); | 33 ModelTypeRegistry* registry(); |
34 | 34 |
35 static sync_pb::DataTypeState MakeInitialDataTypeState(ModelType type) { | 35 static sync_pb::DataTypeState MakeInitialDataTypeState(ModelType type) { |
36 sync_pb::DataTypeState state; | 36 sync_pb::DataTypeState state; |
37 state.mutable_progress_marker()->set_data_type_id( | 37 state.mutable_progress_marker()->set_data_type_id( |
38 GetSpecificsFieldNumberFromModelType(type)); | 38 GetSpecificsFieldNumberFromModelType(type)); |
39 return state; | 39 return state; |
40 } | 40 } |
41 | 41 |
42 static std::unique_ptr<ActivationContext> MakeActivationContext( | 42 static std::unique_ptr<syncer_v2::ActivationContext> MakeActivationContext( |
43 const sync_pb::DataTypeState& data_type_state, | 43 const sync_pb::DataTypeState& data_type_state, |
44 std::unique_ptr<ModelTypeProcessor> type_processor) { | 44 std::unique_ptr<syncer_v2::ModelTypeProcessor> type_processor) { |
45 std::unique_ptr<ActivationContext> context = | 45 std::unique_ptr<syncer_v2::ActivationContext> context = |
46 base::WrapUnique(new ActivationContext); | 46 base::WrapUnique(new syncer_v2::ActivationContext); |
47 context->data_type_state = data_type_state; | 47 context->data_type_state = data_type_state; |
48 context->type_processor = std::move(type_processor); | 48 context->type_processor = std::move(type_processor); |
49 return context; | 49 return context; |
50 } | 50 } |
51 | 51 |
52 void MarkInitialSyncEndedForDirectoryType(ModelType type) { | 52 void MarkInitialSyncEndedForDirectoryType(ModelType type) { |
53 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::SYNCER, | 53 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::SYNCER, |
54 directory()); | 54 directory()); |
55 syncable::ModelNeutralMutableEntry entry( | 55 syncable::ModelNeutralMutableEntry entry( |
56 &trans, syncable::CREATE_NEW_TYPE_ROOT, type); | 56 &trans, syncable::CREATE_NEW_TYPE_ROOT, type); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 ModelSafeRoutingInfo routing_info2; | 175 ModelSafeRoutingInfo routing_info2; |
176 registry()->SetEnabledDirectoryTypes(routing_info2); | 176 registry()->SetEnabledDirectoryTypes(routing_info2); |
177 | 177 |
178 registry()->SetEnabledDirectoryTypes(routing_info1); | 178 registry()->SetEnabledDirectoryTypes(routing_info1); |
179 } | 179 } |
180 | 180 |
181 TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { | 181 TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { |
182 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); | 182 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); |
183 | 183 |
184 registry()->ConnectType( | 184 registry()->ConnectType( |
185 THEMES, | 185 syncer::THEMES, |
186 MakeActivationContext(MakeInitialDataTypeState(THEMES), | 186 MakeActivationContext( |
187 base::MakeUnique<FakeModelTypeProcessor>())); | 187 MakeInitialDataTypeState(THEMES), |
188 EXPECT_EQ(ModelTypeSet(THEMES), registry()->GetEnabledTypes()); | 188 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); |
| 189 EXPECT_EQ(ModelTypeSet(syncer::THEMES), registry()->GetEnabledTypes()); |
189 | 190 |
190 registry()->ConnectType( | 191 registry()->ConnectType( |
191 SESSIONS, | 192 syncer::SESSIONS, |
192 MakeActivationContext(MakeInitialDataTypeState(SESSIONS), | 193 MakeActivationContext( |
193 base::MakeUnique<FakeModelTypeProcessor>())); | 194 MakeInitialDataTypeState(SESSIONS), |
194 EXPECT_EQ(ModelTypeSet(THEMES, SESSIONS), registry()->GetEnabledTypes()); | 195 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); |
| 196 EXPECT_EQ(ModelTypeSet(syncer::THEMES, syncer::SESSIONS), |
| 197 registry()->GetEnabledTypes()); |
195 | 198 |
196 registry()->DisconnectType(THEMES); | 199 registry()->DisconnectType(syncer::THEMES); |
197 EXPECT_EQ(ModelTypeSet(SESSIONS), registry()->GetEnabledTypes()); | 200 EXPECT_EQ(ModelTypeSet(syncer::SESSIONS), registry()->GetEnabledTypes()); |
198 | 201 |
199 // Allow ModelTypeRegistry destruction to delete the | 202 // Allow ModelTypeRegistry destruction to delete the |
200 // Sessions' ModelTypeSyncWorker. | 203 // Sessions' ModelTypeSyncWorker. |
201 } | 204 } |
202 | 205 |
203 TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { | 206 TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { |
204 ModelSafeRoutingInfo routing_info1; | 207 ModelSafeRoutingInfo routing_info1; |
205 routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE)); | 208 routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE)); |
206 routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_UI)); | 209 routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_UI)); |
207 routing_info1.insert(std::make_pair(AUTOFILL, GROUP_DB)); | 210 routing_info1.insert(std::make_pair(AUTOFILL, GROUP_DB)); |
208 routing_info1.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); | 211 routing_info1.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); |
209 routing_info1.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); | 212 routing_info1.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); |
210 | 213 |
211 ModelTypeSet directory_types(NIGORI, BOOKMARKS, AUTOFILL); | 214 ModelTypeSet directory_types(NIGORI, BOOKMARKS, AUTOFILL); |
212 | 215 |
213 ModelTypeSet current_types; | 216 ModelTypeSet current_types; |
214 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); | 217 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); |
215 | 218 |
216 // Add the themes non-blocking type. | 219 // Add the themes non-blocking type. |
217 registry()->ConnectType( | 220 registry()->ConnectType( |
218 THEMES, | 221 syncer::THEMES, |
219 MakeActivationContext(MakeInitialDataTypeState(THEMES), | 222 MakeActivationContext( |
220 base::MakeUnique<FakeModelTypeProcessor>())); | 223 MakeInitialDataTypeState(THEMES), |
221 current_types.Put(THEMES); | 224 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); |
| 225 current_types.Put(syncer::THEMES); |
222 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); | 226 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); |
223 | 227 |
224 // Add some directory types. | 228 // Add some directory types. |
225 registry()->SetEnabledDirectoryTypes(routing_info1); | 229 registry()->SetEnabledDirectoryTypes(routing_info1); |
226 current_types.PutAll(directory_types); | 230 current_types.PutAll(directory_types); |
227 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); | 231 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); |
228 | 232 |
229 // Add sessions non-blocking type. | 233 // Add sessions non-blocking type. |
230 registry()->ConnectType( | 234 registry()->ConnectType( |
231 SESSIONS, | 235 syncer::SESSIONS, |
232 MakeActivationContext(MakeInitialDataTypeState(SESSIONS), | 236 MakeActivationContext( |
233 base::MakeUnique<FakeModelTypeProcessor>())); | 237 MakeInitialDataTypeState(SESSIONS), |
234 current_types.Put(SESSIONS); | 238 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); |
| 239 current_types.Put(syncer::SESSIONS); |
235 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); | 240 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); |
236 | 241 |
237 // Remove themes non-blocking type. | 242 // Remove themes non-blocking type. |
238 registry()->DisconnectType(THEMES); | 243 registry()->DisconnectType(syncer::THEMES); |
239 current_types.Remove(THEMES); | 244 current_types.Remove(syncer::THEMES); |
240 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); | 245 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); |
241 | 246 |
242 // Clear all directory types. | 247 // Clear all directory types. |
243 ModelSafeRoutingInfo routing_info2; | 248 ModelSafeRoutingInfo routing_info2; |
244 registry()->SetEnabledDirectoryTypes(routing_info2); | 249 registry()->SetEnabledDirectoryTypes(routing_info2); |
245 current_types.RemoveAll(directory_types); | 250 current_types.RemoveAll(directory_types); |
246 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); | 251 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); |
247 } | 252 } |
248 | 253 |
249 // Tests correct result returned from GetInitialSyncEndedTypes. | 254 // Tests correct result returned from GetInitialSyncEndedTypes. |
250 TEST_F(ModelTypeRegistryTest, GetInitialSyncEndedTypes) { | 255 TEST_F(ModelTypeRegistryTest, GetInitialSyncEndedTypes) { |
251 ModelSafeRoutingInfo routing_info; | 256 ModelSafeRoutingInfo routing_info; |
252 // Add two directory and two non-blocking types. | 257 // Add two directory and two non-blocking types. |
253 routing_info.insert(std::make_pair(AUTOFILL, GROUP_PASSIVE)); | 258 routing_info.insert(std::make_pair(AUTOFILL, GROUP_PASSIVE)); |
254 routing_info.insert(std::make_pair(BOOKMARKS, GROUP_PASSIVE)); | 259 routing_info.insert(std::make_pair(BOOKMARKS, GROUP_PASSIVE)); |
255 routing_info.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); | 260 routing_info.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); |
256 routing_info.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); | 261 routing_info.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); |
257 registry()->SetEnabledDirectoryTypes(routing_info); | 262 registry()->SetEnabledDirectoryTypes(routing_info); |
258 | 263 |
259 // Only Autofill and Themes types finished initial sync. | 264 // Only Autofill and Themes types finished initial sync. |
260 MarkInitialSyncEndedForDirectoryType(AUTOFILL); | 265 MarkInitialSyncEndedForDirectoryType(AUTOFILL); |
261 | 266 |
262 sync_pb::DataTypeState data_type_state = MakeInitialDataTypeState(THEMES); | 267 sync_pb::DataTypeState data_type_state = MakeInitialDataTypeState(THEMES); |
263 data_type_state.set_initial_sync_done(true); | 268 data_type_state.set_initial_sync_done(true); |
264 registry()->ConnectType( | 269 registry()->ConnectType( |
265 THEMES, | 270 syncer::THEMES, |
266 MakeActivationContext(data_type_state, | 271 MakeActivationContext( |
267 base::WrapUnique(new FakeModelTypeProcessor()))); | 272 data_type_state, |
| 273 base::WrapUnique(new syncer_v2::FakeModelTypeProcessor()))); |
268 | 274 |
269 EXPECT_EQ(ModelTypeSet(AUTOFILL, THEMES), | 275 EXPECT_EQ(ModelTypeSet(AUTOFILL, THEMES), |
270 registry()->GetInitialSyncEndedTypes()); | 276 registry()->GetInitialSyncEndedTypes()); |
271 } | 277 } |
272 | 278 |
273 } // namespace syncer | 279 } // namespace syncer |
OLD | NEW |