| OLD | NEW |
| 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 Loading... |
| 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, |
| 103 const base::Closure& ready_task, | 104 const base::Closure& ready_task, |
| 104 const base::Closure& retry_task) | 105 const base::Closure& retry_task) |
| 105 : source(source), | 106 : source(source), |
| 106 types_to_download(types_to_download), | 107 types_to_download(types_to_download), |
| 108 routing_info(routing_info), |
| 107 ready_task(ready_task), | 109 ready_task(ready_task), |
| 108 retry_task(retry_task) { | 110 retry_task(retry_task) { |
| 109 DCHECK(!ready_task.is_null()); | 111 DCHECK(!ready_task.is_null()); |
| 110 } | 112 } |
| 111 ConfigurationParams::ConfigurationParams(const ConfigurationParams& other) = | 113 ConfigurationParams::ConfigurationParams(const ConfigurationParams& other) = |
| 112 default; | 114 default; |
| 113 ConfigurationParams::~ConfigurationParams() {} | 115 ConfigurationParams::~ConfigurationParams() {} |
| 114 | 116 |
| 115 ClearParams::ClearParams(const base::Closure& report_success_task) | 117 ClearParams::ClearParams(const base::Closure& report_success_task) |
| 116 : report_success_task(report_success_task) { | 118 : report_success_task(report_success_task) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 263 |
| 262 void SyncSchedulerImpl::SendInitialSnapshot() { | 264 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 263 DCHECK(CalledOnValidThread()); | 265 DCHECK(CalledOnValidThread()); |
| 264 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); | 266 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); |
| 265 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); | 267 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); |
| 266 event.snapshot = dummy->TakeSnapshot(); | 268 event.snapshot = dummy->TakeSnapshot(); |
| 267 for (auto& observer : *cycle_context_->listeners()) | 269 for (auto& observer : *cycle_context_->listeners()) |
| 268 observer.OnSyncCycleEvent(event); | 270 observer.OnSyncCycleEvent(event); |
| 269 } | 271 } |
| 270 | 272 |
| 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 |
| 271 void SyncSchedulerImpl::ScheduleConfiguration( | 292 void SyncSchedulerImpl::ScheduleConfiguration( |
| 272 const ConfigurationParams& params) { | 293 const ConfigurationParams& params) { |
| 273 DCHECK(CalledOnValidThread()); | 294 DCHECK(CalledOnValidThread()); |
| 274 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); | 295 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); |
| 275 DCHECK_EQ(CONFIGURATION_MODE, mode_); | 296 DCHECK_EQ(CONFIGURATION_MODE, mode_); |
| 276 DCHECK(!params.ready_task.is_null()); | 297 DCHECK(!params.ready_task.is_null()); |
| 277 CHECK(started_) << "Scheduler must be running to configure."; | 298 CHECK(started_) << "Scheduler must be running to configure."; |
| 278 SDVLOG(2) << "Reconfiguring syncer."; | 299 SDVLOG(2) << "Reconfiguring syncer."; |
| 279 | 300 |
| 280 // Only one configuration is allowed at a time. Verify we're not waiting | 301 // Only one configuration is allowed at a time. Verify we're not waiting |
| 281 // for a pending configure job. | 302 // for a pending configure job. |
| 282 DCHECK(!pending_configure_params_); | 303 DCHECK(!pending_configure_params_); |
| 283 | 304 |
| 305 ModelSafeRoutingInfo restricted_routes; |
| 306 BuildModelSafeParams(params.types_to_download, params.routing_info, |
| 307 &restricted_routes); |
| 308 cycle_context_->SetRoutingInfo(restricted_routes); |
| 309 |
| 284 // Only reconfigure if we have types to download. | 310 // Only reconfigure if we have types to download. |
| 285 if (!params.types_to_download.Empty()) { | 311 if (!params.types_to_download.Empty()) { |
| 286 pending_configure_params_ = base::MakeUnique<ConfigurationParams>(params); | 312 pending_configure_params_ = base::MakeUnique<ConfigurationParams>(params); |
| 287 TrySyncCycleJob(); | 313 TrySyncCycleJob(); |
| 288 } else { | 314 } else { |
| 289 SDVLOG(2) << "No change in routing info, calling ready task directly."; | 315 SDVLOG(2) << "No change in routing info, calling ready task directly."; |
| 290 params.ready_task.Run(); | 316 params.ready_task.Run(); |
| 291 } | 317 } |
| 292 } | 318 } |
| 293 | 319 |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 976 |
| 951 #undef SDVLOG_LOC | 977 #undef SDVLOG_LOC |
| 952 | 978 |
| 953 #undef SDVLOG | 979 #undef SDVLOG |
| 954 | 980 |
| 955 #undef SLOG | 981 #undef SLOG |
| 956 | 982 |
| 957 #undef ENUM_CASE | 983 #undef ENUM_CASE |
| 958 | 984 |
| 959 } // namespace syncer | 985 } // namespace syncer |
| OLD | NEW |