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

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

Issue 8787006: Delay autofill commits to reduce client to server traffic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/sync_scheduler.h" 5 #include "chrome/browser/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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 DCHECK_EQ(MessageLoop::current(), sync_loop_); 445 DCHECK_EQ(MessageLoop::current(), sync_loop_);
446 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", 446 PostTask(FROM_HERE, "ScheduleClearUserDataImpl",
447 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, 447 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl,
448 weak_ptr_factory_.GetWeakPtr())); 448 weak_ptr_factory_.GetWeakPtr()));
449 } 449 }
450 450
451 // TODO(sync): Remove the *Impl methods for the other Schedule* 451 // TODO(sync): Remove the *Impl methods for the other Schedule*
452 // functions, too. 452 // functions, too.
453 void SyncScheduler::ScheduleCleanupDisabledTypes() { 453 void SyncScheduler::ScheduleCleanupDisabledTypes() {
454 DCHECK_EQ(MessageLoop::current(), sync_loop_); 454 DCHECK_EQ(MessageLoop::current(), sync_loop_);
455 ScheduleSyncSessionJob( 455 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(),
456 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, 456 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
457 CreateSyncSession(SyncSourceInfo()), FROM_HERE); 457 false,
458 FROM_HERE);
459 ScheduleSyncSessionJob(job);
458 } 460 }
459 461
460 void SyncScheduler::ScheduleNudge( 462 void SyncScheduler::ScheduleNudge(
461 const TimeDelta& delay, 463 const TimeDelta& delay,
462 NudgeSource source, const ModelTypeBitSet& types, 464 NudgeSource source, const ModelTypeBitSet& types,
463 const tracked_objects::Location& nudge_location) { 465 const tracked_objects::Location& nudge_location) {
464 DCHECK_EQ(MessageLoop::current(), sync_loop_); 466 DCHECK_EQ(MessageLoop::current(), sync_loop_);
465 SDVLOG_LOC(nudge_location, 2) 467 SDVLOG_LOC(nudge_location, 2)
466 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 468 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
467 << "source " << GetNudgeSourceString(source) << ", " 469 << "source " << GetNudgeSourceString(source) << ", "
(...skipping 27 matching lines...) Expand all
495 weak_ptr_factory_.GetWeakPtr(), 497 weak_ptr_factory_.GetWeakPtr(),
496 delay, 498 delay,
497 GetUpdatesFromNudgeSource(source), 499 GetUpdatesFromNudgeSource(source),
498 types_with_payloads, 500 types_with_payloads,
499 false, 501 false,
500 nudge_location)); 502 nudge_location));
501 } 503 }
502 504
503 void SyncScheduler::ScheduleClearUserDataImpl() { 505 void SyncScheduler::ScheduleClearUserDataImpl() {
504 DCHECK_EQ(MessageLoop::current(), sync_loop_); 506 DCHECK_EQ(MessageLoop::current(), sync_loop_);
505 ScheduleSyncSessionJob( 507 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(),
506 TimeDelta::FromSeconds(0), SyncSessionJob::CLEAR_USER_DATA, 508 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
507 CreateSyncSession(SyncSourceInfo()), FROM_HERE); 509 false,
510 FROM_HERE);
511
512 ScheduleSyncSessionJob(job);
508 } 513 }
509 514
510 void SyncScheduler::ScheduleNudgeImpl( 515 void SyncScheduler::ScheduleNudgeImpl(
511 const TimeDelta& delay, 516 const TimeDelta& delay,
512 GetUpdatesCallerInfo::GetUpdatesSource source, 517 GetUpdatesCallerInfo::GetUpdatesSource source,
513 const ModelTypePayloadMap& types_with_payloads, 518 const ModelTypePayloadMap& types_with_payloads,
514 bool is_canary_job, const tracked_objects::Location& nudge_location) { 519 bool is_canary_job, const tracked_objects::Location& nudge_location) {
515 DCHECK_EQ(MessageLoop::current(), sync_loop_); 520 DCHECK_EQ(MessageLoop::current(), sync_loop_);
516 521
517 SDVLOG_LOC(nudge_location, 2) 522 SDVLOG_LOC(nudge_location, 2)
(...skipping 17 matching lines...) Expand all
535 540
536 if (pending_nudge_.get()) { 541 if (pending_nudge_.get()) {
537 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { 542 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) {
538 SDVLOG(2) << "Dropping the nudge because we are in backoff"; 543 SDVLOG(2) << "Dropping the nudge because we are in backoff";
539 return; 544 return;
540 } 545 }
541 546
542 SDVLOG(2) << "Coalescing pending nudge"; 547 SDVLOG(2) << "Coalescing pending nudge";
543 pending_nudge_->session->Coalesce(*(job.session.get())); 548 pending_nudge_->session->Coalesce(*(job.session.get()));
544 549
545 if (!IsBackingOff()) { 550 SDVLOG(2) << "Rescheduling pending nudge";
546 SDVLOG(2) << "Dropping a nudge because" 551 SyncSession* s = pending_nudge_->session.get();
547 << " we are not in backoff and the job was coalesced"; 552 job.session.reset(new SyncSession(s->context(), s->delegate(),
548 return; 553 s->source(), s->routing_info(), s->workers()));
549 } else { 554
550 SDVLOG(2) << "Rescheduling pending nudge"; 555 // Choose the start time as the earliest of the 2.
551 SyncSession* s = pending_nudge_->session.get(); 556 job.scheduled_start = std::min(job.scheduled_start,
552 job.session.reset(new SyncSession(s->context(), s->delegate(), 557 pending_nudge_->scheduled_start);
553 s->source(), s->routing_info(), s->workers())); 558 pending_nudge_.reset();
554 pending_nudge_.reset();
555 }
556 } 559 }
557 560
558 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. 561 ScheduleSyncSessionJob(job);
559 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
560 nudge_location);
561 } 562 }
562 563
563 // Helper to extract the routing info and workers corresponding to types in 564 // Helper to extract the routing info and workers corresponding to types in
564 // |types| from |registrar|. 565 // |types| from |registrar|.
565 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types, 566 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
566 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, 567 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
567 std::vector<ModelSafeWorker*>* workers) { 568 std::vector<ModelSafeWorker*>* workers) {
568 ModelSafeRoutingInfo r_tmp; 569 ModelSafeRoutingInfo r_tmp;
569 std::vector<ModelSafeWorker*> w_tmp; 570 std::vector<ModelSafeWorker*> w_tmp;
570 registrar->GetModelSafeRoutingInfo(&r_tmp); 571 registrar->GetModelSafeRoutingInfo(&r_tmp);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { 631 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
631 DCHECK_EQ(MessageLoop::current(), sync_loop_); 632 DCHECK_EQ(MessageLoop::current(), sync_loop_);
632 633
633 SDVLOG(2) << "In ScheduleConfigImpl"; 634 SDVLOG(2) << "In ScheduleConfigImpl";
634 // TODO(tim): config-specific GetUpdatesCallerInfo value? 635 // TODO(tim): config-specific GetUpdatesCallerInfo value?
635 SyncSession* session = new SyncSession(session_context_.get(), this, 636 SyncSession* session = new SyncSession(session_context_.get(), this,
636 SyncSourceInfo(source, 637 SyncSourceInfo(source,
637 syncable::ModelTypePayloadMapFromRoutingInfo( 638 syncable::ModelTypePayloadMapFromRoutingInfo(
638 routing_info, std::string())), 639 routing_info, std::string())),
639 routing_info, workers); 640 routing_info, workers);
640 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), 641 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(),
641 SyncSessionJob::CONFIGURATION, session, FROM_HERE); 642 make_linked_ptr(session),
643 false,
644 FROM_HERE);
645 ScheduleSyncSessionJob(job);
642 } 646 }
643 647
644 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { 648 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) {
645 switch (mode) { 649 switch (mode) {
646 ENUM_CASE(CONFIGURATION_MODE); 650 ENUM_CASE(CONFIGURATION_MODE);
647 ENUM_CASE(NORMAL_MODE); 651 ENUM_CASE(NORMAL_MODE);
648 } 652 }
649 return ""; 653 return "";
650 } 654 }
651 655
(...skipping 25 matching lines...) Expand all
677 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with " 681 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with "
678 << delay_ms << " ms delay"; 682 << delay_ms << " ms delay";
679 DCHECK_EQ(MessageLoop::current(), sync_loop_); 683 DCHECK_EQ(MessageLoop::current(), sync_loop_);
680 if (!started_) { 684 if (!started_) {
681 SDVLOG(1) << "Not posting task as scheduler is stopped."; 685 SDVLOG(1) << "Not posting task as scheduler is stopped.";
682 return; 686 return;
683 } 687 }
684 sync_loop_->PostDelayedTask(from_here, task, delay_ms); 688 sync_loop_->PostDelayedTask(from_here, task, delay_ms);
685 } 689 }
686 690
687 void SyncScheduler::ScheduleSyncSessionJob( 691 void SyncScheduler::ScheduleSyncSessionJob(const SyncSessionJob& job) {
688 const base::TimeDelta& delay,
689 SyncSessionJob::SyncSessionJobPurpose purpose,
690 sessions::SyncSession* session,
691 const tracked_objects::Location& from_here) {
692 DCHECK_EQ(MessageLoop::current(), sync_loop_); 692 DCHECK_EQ(MessageLoop::current(), sync_loop_);
693 SDVLOG_LOC(from_here, 2) 693 TimeDelta delay = job.scheduled_start - TimeTicks::Now();
694 if (delay < TimeDelta::FromMilliseconds(0))
695 delay = TimeDelta::FromMilliseconds(0);
696 SDVLOG_LOC(job.from_here, 2)
694 << "In ScheduleSyncSessionJob with " 697 << "In ScheduleSyncSessionJob with "
695 << SyncSessionJob::GetPurposeString(purpose) 698 << SyncSessionJob::GetPurposeString(job.purpose)
696 << " job and " << delay.InMilliseconds() << " ms delay"; 699 << " job and " << delay.InMilliseconds() << " ms delay";
697 700
698 SyncSessionJob job(purpose, TimeTicks::Now() + delay, 701 if (job.purpose == SyncSessionJob::NUDGE) {
699 make_linked_ptr(session), false, from_here); 702 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge";
700 if (purpose == SyncSessionJob::NUDGE) { 703 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() ==
701 SDVLOG_LOC(from_here, 2) << "Resetting pending_nudge"; 704 job.session);
702 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session);
703 pending_nudge_.reset(new SyncSessionJob(job)); 705 pending_nudge_.reset(new SyncSessionJob(job));
704 } 706 }
705 PostDelayedTask(from_here, "DoSyncSessionJob", 707 PostDelayedTask(job.from_here, "DoSyncSessionJob",
706 base::Bind(&SyncScheduler::DoSyncSessionJob, 708 base::Bind(&SyncScheduler::DoSyncSessionJob,
707 weak_ptr_factory_.GetWeakPtr(), 709 weak_ptr_factory_.GetWeakPtr(),
708 job), 710 job),
709 delay.InMilliseconds()); 711 delay.InMilliseconds());
710 } 712 }
711 713
712 void SyncScheduler::SetSyncerStepsForPurpose( 714 void SyncScheduler::SetSyncerStepsForPurpose(
713 SyncSessionJob::SyncSessionJobPurpose purpose, 715 SyncSessionJob::SyncSessionJobPurpose purpose,
714 SyncerStep* start, SyncerStep* end) { 716 SyncerStep* start, SyncerStep* end) {
715 DCHECK_EQ(MessageLoop::current(), sync_loop_); 717 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 return session; 1077 return session;
1076 } 1078 }
1077 1079
1078 void SyncScheduler::PollTimerCallback() { 1080 void SyncScheduler::PollTimerCallback() {
1079 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1081 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1080 ModelSafeRoutingInfo r; 1082 ModelSafeRoutingInfo r;
1081 ModelTypePayloadMap types_with_payloads = 1083 ModelTypePayloadMap types_with_payloads =
1082 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); 1084 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string());
1083 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); 1085 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads);
1084 SyncSession* s = CreateSyncSession(info); 1086 SyncSession* s = CreateSyncSession(info);
1085 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), SyncSessionJob::POLL, s, 1087
1086 FROM_HERE); 1088 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(),
1089 make_linked_ptr(s),
1090 false,
1091 FROM_HERE);
1092
1093 ScheduleSyncSessionJob(job);
tim (not reviewing) 2011/12/09 23:07:22 I created this function (ScheduleSyncSessionJob) t
lipalani1 2011/12/15 01:35:16 The functional reason is in ScheduleNudgeImpl. We
1087 } 1094 }
1088 1095
1089 void SyncScheduler::Unthrottle() { 1096 void SyncScheduler::Unthrottle() {
1090 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1097 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1091 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); 1098 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode);
1092 SDVLOG(2) << "Unthrottled."; 1099 SDVLOG(2) << "Unthrottled.";
1093 DoCanaryJob(); 1100 DoCanaryJob();
1094 wait_interval_.reset(); 1101 wait_interval_.reset();
1095 } 1102 }
1096 1103
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1194
1188 #undef SDVLOG_LOC 1195 #undef SDVLOG_LOC
1189 1196
1190 #undef SDVLOG 1197 #undef SDVLOG
1191 1198
1192 #undef SLOG 1199 #undef SLOG
1193 1200
1194 #undef ENUM_CASE 1201 #undef ENUM_CASE
1195 1202
1196 } // browser_sync 1203 } // browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698