Chromium Code Reviews| 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 "sync/engine/sync_scheduler.h" | 5 #include "sync/engine/sync_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool IsActionableError( | 64 bool IsActionableError( |
| 65 const browser_sync::SyncProtocolError& error) { | 65 const browser_sync::SyncProtocolError& error) { |
| 66 return (error.action != browser_sync::UNKNOWN_ACTION); | 66 return (error.action != browser_sync::UNKNOWN_ACTION); |
| 67 } | 67 } |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 SyncScheduler::ConfigureParams::ConfigureParams() | |
| 71 : source(GetUpdatesCallerInfo::UNKNOWN), | |
| 72 need_cleanup(false), | |
| 73 need_encryption_key(false) {} | |
| 74 SyncScheduler::ConfigureParams::ConfigureParams( | |
| 75 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | |
| 76 const syncable::ModelTypeSet& types_to_config, | |
| 77 const browser_sync::ModelSafeRoutingInfo& routing_info, | |
| 78 bool need_cleanup, | |
| 79 bool need_encryption_key, | |
| 80 const base::Closure& ready_task) | |
| 81 : source(source), | |
| 82 types_to_config(types_to_config), | |
| 83 routing_info(routing_info), | |
| 84 need_cleanup(need_cleanup), | |
| 85 need_encryption_key(need_encryption_key), | |
| 86 ready_task(ready_task) {} | |
| 87 SyncScheduler::ConfigureParams::~ConfigureParams() {} | |
| 88 | |
| 70 SyncScheduler::DelayProvider::DelayProvider() {} | 89 SyncScheduler::DelayProvider::DelayProvider() {} |
| 71 SyncScheduler::DelayProvider::~DelayProvider() {} | 90 SyncScheduler::DelayProvider::~DelayProvider() {} |
| 72 | 91 |
| 73 SyncScheduler::WaitInterval::WaitInterval() | 92 SyncScheduler::WaitInterval::WaitInterval() |
| 74 : mode(UNKNOWN), | 93 : mode(UNKNOWN), |
| 75 had_nudge(false) { | 94 had_nudge(false) { |
| 76 } | 95 } |
| 77 | 96 |
| 78 SyncScheduler::WaitInterval::~WaitInterval() {} | 97 SyncScheduler::WaitInterval::~WaitInterval() {} |
| 79 | 98 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 | 258 |
| 240 void SyncScheduler::UpdateServerConnectionManagerStatus( | 259 void SyncScheduler::UpdateServerConnectionManagerStatus( |
| 241 HttpResponse::ServerConnectionCode code) { | 260 HttpResponse::ServerConnectionCode code) { |
| 242 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 261 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 243 SDVLOG(2) << "New server connection code: " | 262 SDVLOG(2) << "New server connection code: " |
| 244 << HttpResponse::GetServerConnectionCodeString(code); | 263 << HttpResponse::GetServerConnectionCodeString(code); |
| 245 | 264 |
| 246 connection_code_ = code; | 265 connection_code_ = code; |
| 247 } | 266 } |
| 248 | 267 |
| 249 void SyncScheduler::Start(Mode mode, const base::Closure& callback) { | 268 void SyncScheduler::Start(Mode mode) { |
| 250 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 269 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 251 std::string thread_name = MessageLoop::current()->thread_name(); | 270 std::string thread_name = MessageLoop::current()->thread_name(); |
| 252 if (thread_name.empty()) | 271 if (thread_name.empty()) |
| 253 thread_name = "<Main thread>"; | 272 thread_name = "<Main thread>"; |
| 254 SDVLOG(2) << "Start called from thread " | 273 SDVLOG(2) << "Start called from thread " |
| 255 << thread_name << " with mode " << GetModeString(mode); | 274 << thread_name << " with mode " << GetModeString(mode); |
| 256 if (!started_) { | 275 if (!started_) { |
| 257 started_ = true; | 276 started_ = true; |
| 258 PostTask(FROM_HERE, "SendInitialSnapshot", | 277 SendInitialSnapshot(); |
| 259 base::Bind(&SyncScheduler::SendInitialSnapshot, | |
| 260 weak_ptr_factory_.GetWeakPtr())); | |
| 261 } | 278 } |
| 262 PostTask(FROM_HERE, "StartImpl", | 279 StartImpl(mode); |
| 263 base::Bind(&SyncScheduler::StartImpl, | |
| 264 weak_ptr_factory_.GetWeakPtr(), mode, callback)); | |
| 265 } | 280 } |
| 266 | 281 |
| 267 void SyncScheduler::SendInitialSnapshot() { | 282 void SyncScheduler::SendInitialSnapshot() { |
| 268 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 283 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 269 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, | 284 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, |
| 270 SyncSourceInfo(), ModelSafeRoutingInfo(), | 285 SyncSourceInfo(), ModelSafeRoutingInfo(), |
| 271 std::vector<ModelSafeWorker*>())); | 286 std::vector<ModelSafeWorker*>())); |
| 272 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 287 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 273 event.snapshot = dummy->TakeSnapshot(); | 288 event.snapshot = dummy->TakeSnapshot(); |
| 274 session_context_->NotifyListeners(event); | 289 session_context_->NotifyListeners(event); |
| 275 } | 290 } |
| 276 | 291 |
| 277 void SyncScheduler::StartImpl(Mode mode, const base::Closure& callback) { | 292 void SyncScheduler::StartImpl(Mode mode) { |
| 278 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 293 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 279 SDVLOG(2) << "In StartImpl with mode " << GetModeString(mode); | 294 SDVLOG(2) << "In StartImpl with mode " << GetModeString(mode); |
| 280 | 295 |
| 281 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 296 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 282 DCHECK(!session_context_->account_name().empty()); | 297 DCHECK(!session_context_->account_name().empty()); |
| 283 DCHECK(syncer_.get()); | 298 DCHECK(syncer_.get()); |
| 284 Mode old_mode = mode_; | 299 Mode old_mode = mode_; |
| 285 mode_ = mode; | 300 mode_ = mode; |
| 286 AdjustPolling(NULL); // Will kick start poll timer if needed. | 301 AdjustPolling(NULL); // Will kick start poll timer if needed. |
| 287 if (!callback.is_null()) | |
| 288 callback.Run(); | |
| 289 | 302 |
| 290 if (old_mode != mode_) { | 303 if (old_mode != mode_) { |
| 291 // We just changed our mode. See if there are any pending jobs that we could | 304 // We just changed our mode. See if there are any pending jobs that we could |
| 292 // execute in the new mode. | 305 // execute in the new mode. |
| 293 DoPendingJobIfPossible(false); | 306 DoPendingJobIfPossible(false); |
| 294 } | 307 } |
| 295 } | 308 } |
| 296 | 309 |
| 310 namespace { | |
| 311 | |
| 312 // Helper to extract the routing info and workers corresponding to types in | |
| 313 // |types| from |current_routes| and |current_workers|. | |
| 314 void BuildModelSafeParams( | |
| 315 const ModelTypeSet& types_to_config, | |
| 316 const ModelSafeRoutingInfo& current_routes, | |
| 317 const std::vector<ModelSafeWorker*>& current_workers, | |
| 318 ModelSafeRoutingInfo* result_routes, | |
| 319 std::vector<ModelSafeWorker*>* result_workers) { | |
| 320 std::set<ModelSafeGroup> active_groups; | |
| 321 active_groups.insert(GROUP_PASSIVE); | |
| 322 for (ModelTypeSet::Iterator iter = types_to_config.First(); iter.Good(); | |
| 323 iter.Inc()) { | |
| 324 syncable::ModelType type = iter.Get(); | |
| 325 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); | |
| 326 DCHECK(route != current_routes.end()); | |
| 327 ModelSafeGroup group = route->second; | |
| 328 (*result_routes)[type] = group; | |
| 329 active_groups.insert(group); | |
| 330 } | |
| 331 | |
| 332 for(std::vector<ModelSafeWorker*>::const_iterator iter = | |
| 333 current_workers.begin(); iter != current_workers.end(); ++iter) { | |
| 334 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) | |
| 335 result_workers->push_back(*iter); | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 } // namespace. | |
| 340 | |
| 341 bool SyncScheduler::Configure(const ConfigureParams& params) { | |
| 342 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 343 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); | |
| 344 DCHECK_EQ(CONFIGURATION_MODE, mode_); | |
| 345 SDVLOG(2) << "Reconfiguring syncer."; | |
| 346 | |
| 347 // Only one configuration is allowed at a time. Verify we're not waiting | |
| 348 // for a pending configure job. | |
| 349 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); | |
| 350 | |
| 351 // We set the routing info for all enabled types in the session context, but | |
| 352 // the session for this configuration only knows about the routing info for | |
| 353 // those types_to_config (set via restricted_routes and restricted_workers). | |
| 354 browser_sync::ModelSafeRoutingInfo restricted_routes; | |
| 355 std::vector<ModelSafeWorker*> restricted_workers; | |
| 356 BuildModelSafeParams(params.types_to_config, | |
| 357 params.routing_info, | |
| 358 session_context_->workers(), | |
| 359 &restricted_routes, | |
| 360 &restricted_workers); | |
| 361 const browser_sync::ModelSafeRoutingInfo& previous_routing_info = | |
| 362 session_context_->routing_info(); | |
| 363 // TODO(zea): ensure that the routing info can't be set anywhere but here. | |
| 364 session_context_->set_routing_info(params.routing_info); | |
| 365 | |
| 366 if (params.need_cleanup) { | |
|
rlarocque
2012/06/04 23:01:38
CleanupDisabledTypesCommand has some strange logic
tim (not reviewing)
2012/06/05 04:02:09
We do have a function that takes a 'types to clean
Nicolas Zea
2012/06/07 19:25:42
Discussed offline. I've removed this logic and now
| |
| 367 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(), | |
| 368 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | |
| 369 false, | |
| 370 FROM_HERE); | |
| 371 DoSyncSessionJob(job); | |
| 372 } | |
| 373 | |
| 374 if (params.need_encryption_key) { | |
| 375 // TODO(zea): implement in such a way that we can handle failures and the | |
| 376 // subsequent retry's the scheduler might perform. | |
| 377 NOTIMPLEMENTED(); | |
| 378 } | |
| 379 | |
| 380 // If the set of enabled types hasn't changed there's no need to configure. | |
| 381 if (params.routing_info != previous_routing_info) { | |
| 382 DCHECK(!restricted_routes.empty()); | |
| 383 // TODO(tim): config-specific GetUpdatesCallerInfo value? | |
| 384 SyncSession* session = new SyncSession( | |
| 385 session_context_, | |
| 386 this, | |
| 387 SyncSourceInfo(params.source, | |
| 388 syncable::ModelTypePayloadMapFromRoutingInfo( | |
| 389 restricted_routes, | |
| 390 std::string())), | |
| 391 restricted_routes, | |
| 392 restricted_workers); | |
| 393 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | |
|
rlarocque
2012/06/04 23:01:38
The arguments for converting SyncSessionJobs into
| |
| 394 TimeTicks::Now(), | |
| 395 make_linked_ptr(session), | |
| 396 false, | |
| 397 FROM_HERE); | |
| 398 job.config_params = params; | |
| 399 DoSyncSessionJob(job); | |
| 400 | |
| 401 // If we failed, the job would have been saved as the pending configure | |
| 402 // job and a wait interval would have been set. | |
| 403 if (wait_interval_.get() && wait_interval_->pending_configure_job.get()) | |
| 404 return false; | |
| 405 } else { | |
| 406 params.ready_task.Run(); | |
| 407 } | |
| 408 | |
| 409 return true; | |
| 410 } | |
| 411 | |
| 297 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( | 412 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( |
| 298 const SyncSessionJob& job) { | 413 const SyncSessionJob& job) { |
| 299 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 414 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 300 DCHECK(wait_interval_.get()); | 415 DCHECK(wait_interval_.get()); |
| 301 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); | 416 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); |
| 302 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); | 417 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); |
| 303 | 418 |
| 304 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 419 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
| 305 << WaitInterval::GetModeString(wait_interval_->mode) | 420 << WaitInterval::GetModeString(wait_interval_->mode) |
| 306 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 421 << (wait_interval_->had_nudge ? " (had nudge)" : "") |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // TODO(sync): Should we also check that job.purpose != | 546 // TODO(sync): Should we also check that job.purpose != |
| 432 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) | 547 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) |
| 433 if (job.purpose == SyncSessionJob::NUDGE) { | 548 if (job.purpose == SyncSessionJob::NUDGE) { |
| 434 SDVLOG(2) << "Saving a nudge job"; | 549 SDVLOG(2) << "Saving a nudge job"; |
| 435 InitOrCoalescePendingJob(job); | 550 InitOrCoalescePendingJob(job); |
| 436 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ | 551 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ |
| 437 SDVLOG(2) << "Saving a configuration job"; | 552 SDVLOG(2) << "Saving a configuration job"; |
| 438 DCHECK(wait_interval_.get()); | 553 DCHECK(wait_interval_.get()); |
| 439 DCHECK(mode_ == CONFIGURATION_MODE); | 554 DCHECK(mode_ == CONFIGURATION_MODE); |
| 440 | 555 |
| 556 // Config params should always get set. | |
| 557 DCHECK(!job.config_params.ready_task.is_null()); | |
| 441 SyncSession* old = job.session.get(); | 558 SyncSession* old = job.session.get(); |
| 442 SyncSession* s(new SyncSession(session_context_, this, old->source(), | 559 SyncSession* s(new SyncSession(session_context_, this, old->source(), |
| 443 old->routing_info(), old->workers())); | 560 old->routing_info(), old->workers())); |
| 444 SyncSessionJob new_job(job.purpose, TimeTicks::Now(), | 561 SyncSessionJob new_job(job.purpose, TimeTicks::Now(), |
| 445 make_linked_ptr(s), false, job.from_here); | 562 make_linked_ptr(s), false, job.from_here); |
| 446 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); | 563 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); |
| 447 } // drop the rest. | 564 } // drop the rest. |
| 448 // TODO(sync): Is it okay to drop the rest? It's weird that | 565 // TODO(sync): Is it okay to drop the rest? It's weird that |
| 449 // SaveJob() only does what it says sometimes. (See | 566 // SaveJob() only does what it says sometimes. (See |
| 450 // http://crbug.com/90868.) | 567 // http://crbug.com/90868.) |
| 451 } | 568 } |
| 452 | 569 |
| 453 // Functor for std::find_if to search by ModelSafeGroup. | 570 // Functor for std::find_if to search by ModelSafeGroup. |
| 454 struct ModelSafeWorkerGroupIs { | 571 struct ModelSafeWorkerGroupIs { |
| 455 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} | 572 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} |
| 456 bool operator()(ModelSafeWorker* w) { | 573 bool operator()(ModelSafeWorker* w) { |
| 457 return group == w->GetModelSafeGroup(); | 574 return group == w->GetModelSafeGroup(); |
| 458 } | 575 } |
| 459 ModelSafeGroup group; | 576 ModelSafeGroup group; |
| 460 }; | 577 }; |
| 461 | 578 |
| 579 // TODO(sync): Remove the *Impl methods for the other Schedule* | |
| 580 // functions, too. | |
| 462 void SyncScheduler::ScheduleClearUserData() { | 581 void SyncScheduler::ScheduleClearUserData() { |
| 463 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 582 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 464 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", | 583 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", |
| 465 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, | 584 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, |
| 466 weak_ptr_factory_.GetWeakPtr())); | 585 weak_ptr_factory_.GetWeakPtr())); |
| 467 } | 586 } |
| 468 | 587 |
| 469 // TODO(sync): Remove the *Impl methods for the other Schedule* | |
| 470 // functions, too. | |
| 471 void SyncScheduler::ScheduleCleanupDisabledTypes() { | |
| 472 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 473 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(), | |
| 474 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | |
| 475 false, | |
| 476 FROM_HERE); | |
| 477 ScheduleSyncSessionJob(job); | |
| 478 } | |
| 479 | |
| 480 void SyncScheduler::ScheduleNudge( | 588 void SyncScheduler::ScheduleNudge( |
| 481 const TimeDelta& delay, | 589 const TimeDelta& delay, |
| 482 NudgeSource source, ModelTypeSet types, | 590 NudgeSource source, ModelTypeSet types, |
| 483 const tracked_objects::Location& nudge_location) { | 591 const tracked_objects::Location& nudge_location) { |
| 484 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 592 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 485 SDVLOG_LOC(nudge_location, 2) | 593 SDVLOG_LOC(nudge_location, 2) |
| 486 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 594 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 487 << "source " << GetNudgeSourceString(source) << ", " | 595 << "source " << GetNudgeSourceString(source) << ", " |
| 488 << "types " << ModelTypeSetToString(types); | 596 << "types " << ModelTypeSetToString(types); |
| 489 | 597 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 job.scheduled_start = std::min(job.scheduled_start, | 682 job.scheduled_start = std::min(job.scheduled_start, |
| 575 pending_nudge_->scheduled_start); | 683 pending_nudge_->scheduled_start); |
| 576 pending_nudge_.reset(); | 684 pending_nudge_.reset(); |
| 577 } | 685 } |
| 578 | 686 |
| 579 // TODO(zea): Consider adding separate throttling/backoff for datatype | 687 // TODO(zea): Consider adding separate throttling/backoff for datatype |
| 580 // refresh requests. | 688 // refresh requests. |
| 581 ScheduleSyncSessionJob(job); | 689 ScheduleSyncSessionJob(job); |
| 582 } | 690 } |
| 583 | 691 |
| 584 // Helper to extract the routing info and workers corresponding to types in | |
| 585 // |types| from |current_routes| and |current_workers|. | |
| 586 void GetModelSafeParamsForTypes(ModelTypeSet types, | |
| 587 const ModelSafeRoutingInfo& current_routes, | |
| 588 const std::vector<ModelSafeWorker*>& current_workers, | |
| 589 ModelSafeRoutingInfo* result_routes, | |
| 590 std::vector<ModelSafeWorker*>* result_workers) { | |
| 591 bool passive_group_added = false; | |
| 592 | |
| 593 typedef std::vector<ModelSafeWorker*>::const_iterator iter; | |
| 594 for (ModelTypeSet::Iterator it = types.First(); | |
| 595 it.Good(); it.Inc()) { | |
| 596 const syncable::ModelType t = it.Get(); | |
| 597 ModelSafeRoutingInfo::const_iterator route = current_routes.find(t); | |
| 598 DCHECK(route != current_routes.end()); | |
| 599 ModelSafeGroup group = route->second; | |
| 600 | |
| 601 (*result_routes)[t] = group; | |
| 602 iter w_tmp_it = std::find_if(current_workers.begin(), current_workers.end(), | |
| 603 ModelSafeWorkerGroupIs(group)); | |
| 604 if (w_tmp_it != current_workers.end()) { | |
| 605 iter result_workers_it = std::find_if( | |
| 606 result_workers->begin(), result_workers->end(), | |
| 607 ModelSafeWorkerGroupIs(group)); | |
| 608 if (result_workers_it == result_workers->end()) | |
| 609 result_workers->push_back(*w_tmp_it); | |
| 610 | |
| 611 if (group == GROUP_PASSIVE) | |
| 612 passive_group_added = true; | |
| 613 } else { | |
| 614 NOTREACHED(); | |
| 615 } | |
| 616 } | |
| 617 | |
| 618 // Always add group passive. | |
| 619 if (passive_group_added == false) { | |
| 620 iter it = std::find_if(current_workers.begin(), current_workers.end(), | |
| 621 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); | |
| 622 if (it != current_workers.end()) | |
| 623 result_workers->push_back(*it); | |
| 624 else | |
| 625 NOTREACHED(); | |
| 626 } | |
| 627 } | |
| 628 | |
| 629 void SyncScheduler::ScheduleConfig( | |
| 630 ModelTypeSet types, | |
| 631 GetUpdatesCallerInfo::GetUpdatesSource source) { | |
| 632 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 633 DCHECK(IsConfigRelatedUpdateSourceValue(source)); | |
| 634 SDVLOG(2) << "Scheduling a config"; | |
| 635 | |
| 636 ModelSafeRoutingInfo routes; | |
| 637 std::vector<ModelSafeWorker*> workers; | |
| 638 GetModelSafeParamsForTypes(types, | |
| 639 session_context_->routing_info(), | |
| 640 session_context_->workers(), | |
| 641 &routes, &workers); | |
| 642 | |
| 643 PostTask(FROM_HERE, "ScheduleConfigImpl", | |
| 644 base::Bind(&SyncScheduler::ScheduleConfigImpl, | |
| 645 weak_ptr_factory_.GetWeakPtr(), | |
| 646 routes, | |
| 647 workers, | |
| 648 source)); | |
| 649 } | |
| 650 | |
| 651 void SyncScheduler::ScheduleConfigImpl( | |
| 652 const ModelSafeRoutingInfo& routing_info, | |
| 653 const std::vector<ModelSafeWorker*>& workers, | |
| 654 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | |
| 655 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 656 | |
| 657 SDVLOG(2) << "In ScheduleConfigImpl"; | |
| 658 // TODO(tim): config-specific GetUpdatesCallerInfo value? | |
| 659 SyncSession* session = new SyncSession(session_context_, this, | |
| 660 SyncSourceInfo(source, | |
| 661 syncable::ModelTypePayloadMapFromRoutingInfo( | |
| 662 routing_info, std::string())), | |
| 663 routing_info, workers); | |
| 664 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(), | |
| 665 make_linked_ptr(session), | |
| 666 false, | |
| 667 FROM_HERE); | |
| 668 ScheduleSyncSessionJob(job); | |
| 669 } | |
| 670 | |
| 671 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { | 692 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { |
| 672 switch (mode) { | 693 switch (mode) { |
| 673 ENUM_CASE(CONFIGURATION_MODE); | 694 ENUM_CASE(CONFIGURATION_MODE); |
| 674 ENUM_CASE(NORMAL_MODE); | 695 ENUM_CASE(NORMAL_MODE); |
| 675 } | 696 } |
| 676 return ""; | 697 return ""; |
| 677 } | 698 } |
| 678 | 699 |
| 679 const char* SyncScheduler::GetDecisionString( | 700 const char* SyncScheduler::GetDecisionString( |
| 680 SyncScheduler::JobProcessDecision mode) { | 701 SyncScheduler::JobProcessDecision mode) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 | 903 |
| 883 if (old_job.session->Succeeded()) { | 904 if (old_job.session->Succeeded()) { |
| 884 // Success implies backoff relief. Note that if this was a | 905 // Success implies backoff relief. Note that if this was a |
| 885 // "one-off" job (i.e. purpose == | 906 // "one-off" job (i.e. purpose == |
| 886 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if | 907 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if |
| 887 // there was work to do before it ran this wont have changed, as | 908 // there was work to do before it ran this wont have changed, as |
| 888 // jobs like this don't run a full sync cycle. So we don't need | 909 // jobs like this don't run a full sync cycle. So we don't need |
| 889 // special code here. | 910 // special code here. |
| 890 wait_interval_.reset(); | 911 wait_interval_.reset(); |
| 891 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; | 912 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; |
| 913 | |
| 914 // If this was a configuration job with a ready task, invoke it now that | |
| 915 // we finished successfully. | |
| 916 if (!old_job.config_params.ready_task.is_null()) | |
| 917 old_job.config_params.ready_task.Run(); | |
| 892 return; | 918 return; |
| 893 } | 919 } |
| 894 | 920 |
| 895 if (old_job.purpose == SyncSessionJob::POLL) { | 921 if (old_job.purpose == SyncSessionJob::POLL) { |
| 896 return; // We don't retry POLL jobs. | 922 return; // We don't retry POLL jobs. |
| 897 } | 923 } |
| 898 | 924 |
| 899 // TODO(rlarocque): There's no reason why we should blindly backoff and retry | 925 // TODO(rlarocque): There's no reason why we should blindly backoff and retry |
| 900 // if we don't succeed. Some types of errors are not likely to disappear on | 926 // if we don't succeed. Some types of errors are not likely to disappear on |
| 901 // their own. With the return values now available in the old_job.session, we | 927 // their own. With the return values now available in the old_job.session, we |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 967 | 993 |
| 968 SDVLOG(2) << "In handle continuation error with " | 994 SDVLOG(2) << "In handle continuation error with " |
| 969 << SyncSessionJob::GetPurposeString(old_job.purpose) | 995 << SyncSessionJob::GetPurposeString(old_job.purpose) |
| 970 << " job. The time delta(ms) is " | 996 << " job. The time delta(ms) is " |
| 971 << length.InMilliseconds(); | 997 << length.InMilliseconds(); |
| 972 | 998 |
| 973 // This will reset the had_nudge variable as well. | 999 // This will reset the had_nudge variable as well. |
| 974 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, | 1000 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, |
| 975 length)); | 1001 length)); |
| 976 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 1002 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
| 1003 // Config params should always get set. | |
| 1004 DCHECK(!old_job.config_params.ready_task.is_null()); | |
| 977 SyncSession* old = old_job.session.get(); | 1005 SyncSession* old = old_job.session.get(); |
| 978 SyncSession* s(new SyncSession(session_context_, this, | 1006 SyncSession* s(new SyncSession(session_context_, this, |
| 979 old->source(), old->routing_info(), old->workers())); | 1007 old->source(), old->routing_info(), old->workers())); |
| 980 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, | 1008 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, |
| 981 make_linked_ptr(s), false, FROM_HERE); | 1009 make_linked_ptr(s), false, FROM_HERE); |
| 982 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); | 1010 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); |
| 983 } else { | 1011 } else { |
| 984 // We are not in configuration mode. So wait_interval's pending job | 1012 // We are not in configuration mode. So wait_interval's pending job |
| 985 // should be null. | 1013 // should be null. |
| 986 DCHECK(wait_interval_->pending_configure_job.get() == NULL); | 1014 DCHECK(wait_interval_->pending_configure_job.get() == NULL); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 | 1223 |
| 1196 #undef SDVLOG_LOC | 1224 #undef SDVLOG_LOC |
| 1197 | 1225 |
| 1198 #undef SDVLOG | 1226 #undef SDVLOG |
| 1199 | 1227 |
| 1200 #undef SLOG | 1228 #undef SLOG |
| 1201 | 1229 |
| 1202 #undef ENUM_CASE | 1230 #undef ENUM_CASE |
| 1203 | 1231 |
| 1204 } // browser_sync | 1232 } // browser_sync |
| OLD | NEW |