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

Side by Side Diff: components/sync/engine_impl/sync_scheduler_impl.cc

Issue 2641523004: [Sync] Make directory types registration explicit in ModelTypeRegistry (Closed)
Patch Set: Address comments Created 3 years, 11 months 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/sync/engine_impl/sync_scheduler_impl.h" 5 #include "components/sync/engine_impl/sync_scheduler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return #x; \ 93 return #x; \
94 break; 94 break;
95 95
96 } // namespace 96 } // namespace
97 97
98 ConfigurationParams::ConfigurationParams() 98 ConfigurationParams::ConfigurationParams()
99 : source(GetUpdatesCallerInfo::UNKNOWN) {} 99 : source(GetUpdatesCallerInfo::UNKNOWN) {}
100 ConfigurationParams::ConfigurationParams( 100 ConfigurationParams::ConfigurationParams(
101 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, 101 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source,
102 ModelTypeSet types_to_download, 102 ModelTypeSet types_to_download,
103 const ModelSafeRoutingInfo& routing_info,
104 const base::Closure& ready_task, 103 const base::Closure& ready_task,
105 const base::Closure& retry_task) 104 const base::Closure& retry_task)
106 : source(source), 105 : source(source),
107 types_to_download(types_to_download), 106 types_to_download(types_to_download),
108 routing_info(routing_info),
109 ready_task(ready_task), 107 ready_task(ready_task),
110 retry_task(retry_task) { 108 retry_task(retry_task) {
111 DCHECK(!ready_task.is_null()); 109 DCHECK(!ready_task.is_null());
112 } 110 }
113 ConfigurationParams::ConfigurationParams(const ConfigurationParams& other) = 111 ConfigurationParams::ConfigurationParams(const ConfigurationParams& other) =
114 default; 112 default;
115 ConfigurationParams::~ConfigurationParams() {} 113 ConfigurationParams::~ConfigurationParams() {}
116 114
117 ClearParams::ClearParams(const base::Closure& report_success_task) 115 ClearParams::ClearParams(const base::Closure& report_success_task)
118 : report_success_task(report_success_task) { 116 : report_success_task(report_success_task) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 261
264 void SyncSchedulerImpl::SendInitialSnapshot() { 262 void SyncSchedulerImpl::SendInitialSnapshot() {
265 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
266 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); 264 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this));
267 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); 265 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED);
268 event.snapshot = dummy->TakeSnapshot(); 266 event.snapshot = dummy->TakeSnapshot();
269 for (auto& observer : *cycle_context_->listeners()) 267 for (auto& observer : *cycle_context_->listeners())
270 observer.OnSyncCycleEvent(event); 268 observer.OnSyncCycleEvent(event);
271 } 269 }
272 270
273 namespace {
274
275 // Helper to extract the routing info corresponding to types in
276 // |types_to_download| from |current_routes|.
277 void BuildModelSafeParams(ModelTypeSet types_to_download,
278 const ModelSafeRoutingInfo& current_routes,
279 ModelSafeRoutingInfo* result_routes) {
280 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good();
281 iter.Inc()) {
282 ModelType type = iter.Get();
283 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type);
284 DCHECK(route != current_routes.end());
285 ModelSafeGroup group = route->second;
286 (*result_routes)[type] = group;
287 }
288 }
289
290 } // namespace.
291
292 void SyncSchedulerImpl::ScheduleConfiguration( 271 void SyncSchedulerImpl::ScheduleConfiguration(
293 const ConfigurationParams& params) { 272 const ConfigurationParams& params) {
294 DCHECK(CalledOnValidThread()); 273 DCHECK(CalledOnValidThread());
295 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); 274 DCHECK(IsConfigRelatedUpdateSourceValue(params.source));
296 DCHECK_EQ(CONFIGURATION_MODE, mode_); 275 DCHECK_EQ(CONFIGURATION_MODE, mode_);
297 DCHECK(!params.ready_task.is_null()); 276 DCHECK(!params.ready_task.is_null());
298 CHECK(started_) << "Scheduler must be running to configure."; 277 CHECK(started_) << "Scheduler must be running to configure.";
299 SDVLOG(2) << "Reconfiguring syncer."; 278 SDVLOG(2) << "Reconfiguring syncer.";
300 279
301 // Only one configuration is allowed at a time. Verify we're not waiting 280 // Only one configuration is allowed at a time. Verify we're not waiting
302 // for a pending configure job. 281 // for a pending configure job.
303 DCHECK(!pending_configure_params_); 282 DCHECK(!pending_configure_params_);
304 283
305 ModelSafeRoutingInfo restricted_routes;
306 BuildModelSafeParams(params.types_to_download, params.routing_info,
307 &restricted_routes);
308 cycle_context_->SetRoutingInfo(restricted_routes);
309
310 // Only reconfigure if we have types to download. 284 // Only reconfigure if we have types to download.
311 if (!params.types_to_download.Empty()) { 285 if (!params.types_to_download.Empty()) {
312 pending_configure_params_ = base::MakeUnique<ConfigurationParams>(params); 286 pending_configure_params_ = base::MakeUnique<ConfigurationParams>(params);
313 TrySyncCycleJob(); 287 TrySyncCycleJob();
314 } else { 288 } else {
315 SDVLOG(2) << "No change in routing info, calling ready task directly."; 289 SDVLOG(2) << "No change in routing info, calling ready task directly.";
316 params.ready_task.Run(); 290 params.ready_task.Run();
317 } 291 }
318 } 292 }
319 293
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 950
977 #undef SDVLOG_LOC 951 #undef SDVLOG_LOC
978 952
979 #undef SDVLOG 953 #undef SDVLOG
980 954
981 #undef SLOG 955 #undef SLOG
982 956
983 #undef ENUM_CASE 957 #undef ENUM_CASE
984 958
985 } // namespace syncer 959 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/sync_scheduler.h ('k') | components/sync/engine_impl/sync_scheduler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698