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

Side by Side Diff: sync/engine/sync_scheduler.cc

Issue 10542044: [Sync] Remove unnecessary posting of methods in sync scheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and fix dcheck Created 8 years, 6 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 | Annotate | Revision Log
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 "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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 void SyncScheduler::Start(Mode mode, const base::Closure& callback) { 249 void SyncScheduler::Start(Mode mode, const base::Closure& callback) {
250 DCHECK_EQ(MessageLoop::current(), sync_loop_); 250 DCHECK_EQ(MessageLoop::current(), sync_loop_);
251 std::string thread_name = MessageLoop::current()->thread_name(); 251 std::string thread_name = MessageLoop::current()->thread_name();
252 if (thread_name.empty()) 252 if (thread_name.empty())
253 thread_name = "<Main thread>"; 253 thread_name = "<Main thread>";
254 SDVLOG(2) << "Start called from thread " 254 SDVLOG(2) << "Start called from thread "
255 << thread_name << " with mode " << GetModeString(mode); 255 << thread_name << " with mode " << GetModeString(mode);
256 if (!started_) { 256 if (!started_) {
257 started_ = true; 257 started_ = true;
258 PostTask(FROM_HERE, "SendInitialSnapshot", 258 SendInitialSnapshot();
259 base::Bind(&SyncScheduler::SendInitialSnapshot,
260 weak_ptr_factory_.GetWeakPtr()));
261 } 259 }
262 PostTask(FROM_HERE, "StartImpl",
263 base::Bind(&SyncScheduler::StartImpl,
264 weak_ptr_factory_.GetWeakPtr(), mode, callback));
265 }
266 260
267 void SyncScheduler::SendInitialSnapshot() {
268 DCHECK_EQ(MessageLoop::current(), sync_loop_);
269 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this,
270 SyncSourceInfo(), ModelSafeRoutingInfo(),
271 std::vector<ModelSafeWorker*>()));
272 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED);
273 event.snapshot = dummy->TakeSnapshot();
274 session_context_->NotifyListeners(event);
275 }
276
277 void SyncScheduler::StartImpl(Mode mode, const base::Closure& callback) {
278 DCHECK_EQ(MessageLoop::current(), sync_loop_);
279 SDVLOG(2) << "In StartImpl with mode " << GetModeString(mode);
280
281 DCHECK_EQ(MessageLoop::current(), sync_loop_);
282 DCHECK(!session_context_->account_name().empty()); 261 DCHECK(!session_context_->account_name().empty());
283 DCHECK(syncer_.get()); 262 DCHECK(syncer_.get());
284 Mode old_mode = mode_; 263 Mode old_mode = mode_;
285 mode_ = mode; 264 mode_ = mode;
286 AdjustPolling(NULL); // Will kick start poll timer if needed. 265 AdjustPolling(NULL); // Will kick start poll timer if needed.
287 if (!callback.is_null()) 266 if (!callback.is_null())
288 callback.Run(); 267 callback.Run();
289 268
290 if (old_mode != mode_) { 269 if (old_mode != mode_) {
291 // We just changed our mode. See if there are any pending jobs that we could 270 // We just changed our mode. See if there are any pending jobs that we could
292 // execute in the new mode. 271 // execute in the new mode.
293 DoPendingJobIfPossible(false); 272 DoPendingJobIfPossible(false);
294 } 273 }
295 } 274 }
296 275
276 void SyncScheduler::SendInitialSnapshot() {
277 DCHECK_EQ(MessageLoop::current(), sync_loop_);
278 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this,
279 SyncSourceInfo(), ModelSafeRoutingInfo(),
280 std::vector<ModelSafeWorker*>()));
281 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED);
282 event.snapshot = dummy->TakeSnapshot();
283 session_context_->NotifyListeners(event);
284 }
285
297 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( 286 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval(
298 const SyncSessionJob& job) { 287 const SyncSessionJob& job) {
299 DCHECK_EQ(MessageLoop::current(), sync_loop_); 288 DCHECK_EQ(MessageLoop::current(), sync_loop_);
300 DCHECK(wait_interval_.get()); 289 DCHECK(wait_interval_.get());
301 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); 290 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA);
302 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); 291 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES);
303 292
304 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " 293 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode "
305 << WaitInterval::GetModeString(wait_interval_->mode) 294 << WaitInterval::GetModeString(wait_interval_->mode)
306 << (wait_interval_->had_nudge ? " (had nudge)" : "") 295 << (wait_interval_->had_nudge ? " (had nudge)" : "")
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 441
453 // Functor for std::find_if to search by ModelSafeGroup. 442 // Functor for std::find_if to search by ModelSafeGroup.
454 struct ModelSafeWorkerGroupIs { 443 struct ModelSafeWorkerGroupIs {
455 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} 444 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {}
456 bool operator()(ModelSafeWorker* w) { 445 bool operator()(ModelSafeWorker* w) {
457 return group == w->GetModelSafeGroup(); 446 return group == w->GetModelSafeGroup();
458 } 447 }
459 ModelSafeGroup group; 448 ModelSafeGroup group;
460 }; 449 };
461 450
462 void SyncScheduler::ScheduleClearUserData() { 451 void SyncScheduler::ClearUserData() {
463 DCHECK_EQ(MessageLoop::current(), sync_loop_); 452 DCHECK_EQ(MessageLoop::current(), sync_loop_);
464 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", 453 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(),
465 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, 454 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
466 weak_ptr_factory_.GetWeakPtr())); 455 false,
456 FROM_HERE);
457
458 DoSyncSessionJob(job);
467 } 459 }
468 460
469 // TODO(sync): Remove the *Impl methods for the other Schedule* 461 void SyncScheduler::CleanupDisabledTypes() {
470 // functions, too.
471 void SyncScheduler::ScheduleCleanupDisabledTypes() {
472 DCHECK_EQ(MessageLoop::current(), sync_loop_); 462 DCHECK_EQ(MessageLoop::current(), sync_loop_);
473 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(), 463 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(),
474 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), 464 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
475 false, 465 false,
476 FROM_HERE); 466 FROM_HERE);
477 ScheduleSyncSessionJob(job); 467 DoSyncSessionJob(job);
478 } 468 }
479 469
480 void SyncScheduler::ScheduleNudge( 470 void SyncScheduler::ScheduleNudge(
481 const TimeDelta& delay, 471 const TimeDelta& delay,
482 NudgeSource source, ModelTypeSet types, 472 NudgeSource source, ModelTypeSet types,
483 const tracked_objects::Location& nudge_location) { 473 const tracked_objects::Location& nudge_location) {
484 DCHECK_EQ(MessageLoop::current(), sync_loop_); 474 DCHECK_EQ(MessageLoop::current(), sync_loop_);
485 SDVLOG_LOC(nudge_location, 2) 475 SDVLOG_LOC(nudge_location, 2)
486 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 476 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
487 << "source " << GetNudgeSourceString(source) << ", " 477 << "source " << GetNudgeSourceString(source) << ", "
488 << "types " << ModelTypeSetToString(types); 478 << "types " << ModelTypeSetToString(types);
489 479
490 ModelTypePayloadMap types_with_payloads = 480 ModelTypePayloadMap types_with_payloads =
491 syncable::ModelTypePayloadMapFromEnumSet(types, std::string()); 481 syncable::ModelTypePayloadMapFromEnumSet(types, std::string());
492 PostTask(nudge_location, "ScheduleNudgeImpl", 482 SyncScheduler::ScheduleNudgeImpl(delay,
493 base::Bind(&SyncScheduler::ScheduleNudgeImpl, 483 GetUpdatesFromNudgeSource(source),
494 weak_ptr_factory_.GetWeakPtr(), 484 types_with_payloads,
495 delay, 485 false,
496 GetUpdatesFromNudgeSource(source), 486 nudge_location);
497 types_with_payloads,
498 false,
499 nudge_location));
500 } 487 }
501 488
502 void SyncScheduler::ScheduleNudgeWithPayloads( 489 void SyncScheduler::ScheduleNudgeWithPayloads(
503 const TimeDelta& delay, 490 const TimeDelta& delay,
504 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 491 NudgeSource source, const ModelTypePayloadMap& types_with_payloads,
505 const tracked_objects::Location& nudge_location) { 492 const tracked_objects::Location& nudge_location) {
506 DCHECK_EQ(MessageLoop::current(), sync_loop_); 493 DCHECK_EQ(MessageLoop::current(), sync_loop_);
507 SDVLOG_LOC(nudge_location, 2) 494 SDVLOG_LOC(nudge_location, 2)
508 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 495 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
509 << "source " << GetNudgeSourceString(source) << ", " 496 << "source " << GetNudgeSourceString(source) << ", "
510 << "payloads " 497 << "payloads "
511 << syncable::ModelTypePayloadMapToString(types_with_payloads); 498 << syncable::ModelTypePayloadMapToString(types_with_payloads);
512 499
513 PostTask(nudge_location, "ScheduleNudgeImpl", 500 SyncScheduler::ScheduleNudgeImpl(delay,
514 base::Bind(&SyncScheduler::ScheduleNudgeImpl, 501 GetUpdatesFromNudgeSource(source),
515 weak_ptr_factory_.GetWeakPtr(), 502 types_with_payloads,
516 delay, 503 false,
517 GetUpdatesFromNudgeSource(source), 504 nudge_location);
518 types_with_payloads,
519 false,
520 nudge_location));
521 }
522
523 void SyncScheduler::ScheduleClearUserDataImpl() {
524 DCHECK_EQ(MessageLoop::current(), sync_loop_);
525 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(),
526 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
527 false,
528 FROM_HERE);
529
530 ScheduleSyncSessionJob(job);
531 } 505 }
532 506
533 void SyncScheduler::ScheduleNudgeImpl( 507 void SyncScheduler::ScheduleNudgeImpl(
534 const TimeDelta& delay, 508 const TimeDelta& delay,
535 GetUpdatesCallerInfo::GetUpdatesSource source, 509 GetUpdatesCallerInfo::GetUpdatesSource source,
536 const ModelTypePayloadMap& types_with_payloads, 510 const ModelTypePayloadMap& types_with_payloads,
537 bool is_canary_job, const tracked_objects::Location& nudge_location) { 511 bool is_canary_job, const tracked_objects::Location& nudge_location) {
538 DCHECK_EQ(MessageLoop::current(), sync_loop_); 512 DCHECK_EQ(MessageLoop::current(), sync_loop_);
539 513
540 SDVLOG_LOC(nudge_location, 2) 514 SDVLOG_LOC(nudge_location, 2)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 if (passive_group_added == false) { 593 if (passive_group_added == false) {
620 iter it = std::find_if(current_workers.begin(), current_workers.end(), 594 iter it = std::find_if(current_workers.begin(), current_workers.end(),
621 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); 595 ModelSafeWorkerGroupIs(GROUP_PASSIVE));
622 if (it != current_workers.end()) 596 if (it != current_workers.end())
623 result_workers->push_back(*it); 597 result_workers->push_back(*it);
624 else 598 else
625 NOTREACHED(); 599 NOTREACHED();
626 } 600 }
627 } 601 }
628 602
629 void SyncScheduler::ScheduleConfig( 603 void SyncScheduler::Configure(
630 ModelTypeSet types, 604 ModelTypeSet types,
631 GetUpdatesCallerInfo::GetUpdatesSource source) { 605 GetUpdatesCallerInfo::GetUpdatesSource source) {
632 DCHECK_EQ(MessageLoop::current(), sync_loop_); 606 DCHECK_EQ(MessageLoop::current(), sync_loop_);
633 DCHECK(IsConfigRelatedUpdateSourceValue(source)); 607 DCHECK(IsConfigRelatedUpdateSourceValue(source));
634 SDVLOG(2) << "Scheduling a config"; 608 SDVLOG(2) << "Performing a config";
635 609
636 ModelSafeRoutingInfo routes; 610 ModelSafeRoutingInfo routes;
637 std::vector<ModelSafeWorker*> workers; 611 std::vector<ModelSafeWorker*> workers;
638 GetModelSafeParamsForTypes(types, 612 GetModelSafeParamsForTypes(types,
639 session_context_->routing_info(), 613 session_context_->routing_info(),
640 session_context_->workers(), 614 session_context_->workers(),
641 &routes, &workers); 615 &routes, &workers);
642 616
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? 617 // TODO(tim): config-specific GetUpdatesCallerInfo value?
tim (not reviewing) 2012/06/11 20:06:13 I think this can be removed.
Nicolas Zea 2012/06/11 20:55:09 Done.
659 SyncSession* session = new SyncSession(session_context_, this, 618 SyncSession* session = new SyncSession(session_context_, this,
660 SyncSourceInfo(source, 619 SyncSourceInfo(source,
661 syncable::ModelTypePayloadMapFromRoutingInfo( 620 syncable::ModelTypePayloadMapFromRoutingInfo(
662 routing_info, std::string())), 621 routes, std::string())),
663 routing_info, workers); 622 routes, workers);
664 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(), 623 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(),
665 make_linked_ptr(session), 624 make_linked_ptr(session),
666 false, 625 false,
667 FROM_HERE); 626 FROM_HERE);
668 ScheduleSyncSessionJob(job); 627 DoSyncSessionJob(job);
669 } 628 }
670 629
671 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { 630 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) {
672 switch (mode) { 631 switch (mode) {
673 ENUM_CASE(CONFIGURATION_MODE); 632 ENUM_CASE(CONFIGURATION_MODE);
674 ENUM_CASE(NORMAL_MODE); 633 ENUM_CASE(NORMAL_MODE);
675 } 634 }
676 return ""; 635 return "";
677 } 636 }
678 637
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 void SyncScheduler::ScheduleSyncSessionJob(const SyncSessionJob& job) { 704 void SyncScheduler::ScheduleSyncSessionJob(const SyncSessionJob& job) {
746 DCHECK_EQ(MessageLoop::current(), sync_loop_); 705 DCHECK_EQ(MessageLoop::current(), sync_loop_);
747 TimeDelta delay = job.scheduled_start - TimeTicks::Now(); 706 TimeDelta delay = job.scheduled_start - TimeTicks::Now();
748 if (delay < TimeDelta::FromMilliseconds(0)) 707 if (delay < TimeDelta::FromMilliseconds(0))
749 delay = TimeDelta::FromMilliseconds(0); 708 delay = TimeDelta::FromMilliseconds(0);
750 SDVLOG_LOC(job.from_here, 2) 709 SDVLOG_LOC(job.from_here, 2)
751 << "In ScheduleSyncSessionJob with " 710 << "In ScheduleSyncSessionJob with "
752 << SyncSessionJob::GetPurposeString(job.purpose) 711 << SyncSessionJob::GetPurposeString(job.purpose)
753 << " job and " << delay.InMilliseconds() << " ms delay"; 712 << " job and " << delay.InMilliseconds() << " ms delay";
754 713
714 DCHECK(job.purpose == SyncSessionJob::NUDGE ||
715 job.purpose == SyncSessionJob::POLL);
755 if (job.purpose == SyncSessionJob::NUDGE) { 716 if (job.purpose == SyncSessionJob::NUDGE) {
756 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge"; 717 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge";
757 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == 718 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() ==
758 job.session); 719 job.session);
759 pending_nudge_.reset(new SyncSessionJob(job)); 720 pending_nudge_.reset(new SyncSessionJob(job));
760 } 721 }
722
761 PostDelayedTask(job.from_here, "DoSyncSessionJob", 723 PostDelayedTask(job.from_here, "DoSyncSessionJob",
762 base::Bind(&SyncScheduler::DoSyncSessionJob, 724 base::Bind(&SyncScheduler::DoSyncSessionJob,
763 weak_ptr_factory_.GetWeakPtr(), 725 weak_ptr_factory_.GetWeakPtr(),
764 job), 726 job),
765 delay); 727 delay);
766 } 728 }
767 729
768 void SyncScheduler::DoSyncSessionJob(const SyncSessionJob& job) { 730 void SyncScheduler::DoSyncSessionJob(const SyncSessionJob& job) {
769 DCHECK_EQ(MessageLoop::current(), sync_loop_); 731 DCHECK_EQ(MessageLoop::current(), sync_loop_);
770 if (!ShouldRunJob(job)) { 732 if (!ShouldRunJob(job)) {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 1153
1192 #undef SDVLOG_LOC 1154 #undef SDVLOG_LOC
1193 1155
1194 #undef SDVLOG 1156 #undef SDVLOG
1195 1157
1196 #undef SLOG 1158 #undef SLOG
1197 1159
1198 #undef ENUM_CASE 1160 #undef ENUM_CASE
1199 1161
1200 } // browser_sync 1162 } // browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698