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

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

Issue 10541079: [Sync] Remove CleanupDisabledTypes command and move purge logic into SyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test Created 8 years, 5 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
« no previous file with comments | « sync/engine/sync_scheduler_impl.h ('k') | sync/engine/sync_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl.h" 5 #include "sync/engine/sync_scheduler_impl.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 from_here(from_here) { 125 from_here(from_here) {
126 } 126 }
127 127
128 const char* SyncSchedulerImpl::SyncSessionJob::GetPurposeString( 128 const char* SyncSchedulerImpl::SyncSessionJob::GetPurposeString(
129 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { 129 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) {
130 switch (purpose) { 130 switch (purpose) {
131 ENUM_CASE(UNKNOWN); 131 ENUM_CASE(UNKNOWN);
132 ENUM_CASE(POLL); 132 ENUM_CASE(POLL);
133 ENUM_CASE(NUDGE); 133 ENUM_CASE(NUDGE);
134 ENUM_CASE(CONFIGURATION); 134 ENUM_CASE(CONFIGURATION);
135 ENUM_CASE(CLEANUP_DISABLED_TYPES);
136 } 135 }
137 NOTREACHED(); 136 NOTREACHED();
138 return ""; 137 return "";
139 } 138 }
140 139
141 TimeDelta SyncSchedulerImpl::DelayProvider::GetDelay( 140 TimeDelta SyncSchedulerImpl::DelayProvider::GetDelay(
142 const base::TimeDelta& last_delay) { 141 const base::TimeDelta& last_delay) {
143 return SyncSchedulerImpl::GetRecommendedDelay(last_delay); 142 return SyncSchedulerImpl::GetRecommendedDelay(last_delay);
144 } 143 }
145 144
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // crbug.com/133030 346 // crbug.com/133030
348 ModelSafeRoutingInfo restricted_routes; 347 ModelSafeRoutingInfo restricted_routes;
349 std::vector<ModelSafeWorker*> restricted_workers; 348 std::vector<ModelSafeWorker*> restricted_workers;
350 BuildModelSafeParams(params.types_to_download, 349 BuildModelSafeParams(params.types_to_download,
351 params.routing_info, 350 params.routing_info,
352 session_context_->workers(), 351 session_context_->workers(),
353 &restricted_routes, 352 &restricted_routes,
354 &restricted_workers); 353 &restricted_workers);
355 session_context_->set_routing_info(params.routing_info); 354 session_context_->set_routing_info(params.routing_info);
356 355
357 // We rely on this not failing, so don't need to worry about checking for
358 // success. In addition, this will be removed as part of crbug.com/131433.
359 SyncSessionJob cleanup_job(
360 SyncSessionJob::CLEANUP_DISABLED_TYPES,
361 TimeTicks::Now(),
362 make_linked_ptr(CreateSyncSession(SyncSourceInfo())),
363 false,
364 ConfigurationParams(),
365 FROM_HERE);
366 DoSyncSessionJob(cleanup_job);
367
368 if (params.keystore_key_status == ConfigurationParams::KEYSTORE_KEY_NEEDED) { 356 if (params.keystore_key_status == ConfigurationParams::KEYSTORE_KEY_NEEDED) {
369 // TODO(zea): implement in such a way that we can handle failures and the 357 // TODO(zea): implement in such a way that we can handle failures and the
370 // subsequent retrys the scheduler might perform. See crbug.com/129665. 358 // subsequent retrys the scheduler might perform. See crbug.com/129665.
371 NOTIMPLEMENTED(); 359 NOTIMPLEMENTED();
372 } 360 }
373 361
374 // Only reconfigure if we have types to download. 362 // Only reconfigure if we have types to download.
375 if (!params.types_to_download.Empty()) { 363 if (!params.types_to_download.Empty()) {
376 DCHECK(!restricted_routes.empty()); 364 DCHECK(!restricted_routes.empty());
377 linked_ptr<SyncSession> session(new SyncSession( 365 linked_ptr<SyncSession> session(new SyncSession(
(...skipping 26 matching lines...) Expand all
404 } 392 }
405 393
406 return true; 394 return true;
407 } 395 }
408 396
409 SyncSchedulerImpl::JobProcessDecision 397 SyncSchedulerImpl::JobProcessDecision
410 SyncSchedulerImpl::DecideWhileInWaitInterval( 398 SyncSchedulerImpl::DecideWhileInWaitInterval(
411 const SyncSessionJob& job) { 399 const SyncSessionJob& job) {
412 DCHECK_EQ(MessageLoop::current(), sync_loop_); 400 DCHECK_EQ(MessageLoop::current(), sync_loop_);
413 DCHECK(wait_interval_.get()); 401 DCHECK(wait_interval_.get());
414 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES);
415 402
416 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " 403 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode "
417 << WaitInterval::GetModeString(wait_interval_->mode) 404 << WaitInterval::GetModeString(wait_interval_->mode)
418 << (wait_interval_->had_nudge ? " (had nudge)" : "") 405 << (wait_interval_->had_nudge ? " (had nudge)" : "")
419 << (job.is_canary_job ? " (canary)" : ""); 406 << (job.is_canary_job ? " (canary)" : "");
420 407
421 if (job.purpose == SyncSessionJob::POLL) 408 if (job.purpose == SyncSessionJob::POLL)
422 return DROP; 409 return DROP;
423 410
424 DCHECK(job.purpose == SyncSessionJob::NUDGE || 411 DCHECK(job.purpose == SyncSessionJob::NUDGE ||
(...skipping 12 matching lines...) Expand all
437 return wait_interval_->had_nudge ? DROP : CONTINUE; 424 return wait_interval_->had_nudge ? DROP : CONTINUE;
438 else // We are here because timer ran out. So retry. 425 else // We are here because timer ran out. So retry.
439 return CONTINUE; 426 return CONTINUE;
440 } 427 }
441 return job.is_canary_job ? CONTINUE : SAVE; 428 return job.is_canary_job ? CONTINUE : SAVE;
442 } 429 }
443 430
444 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( 431 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob(
445 const SyncSessionJob& job) { 432 const SyncSessionJob& job) {
446 DCHECK_EQ(MessageLoop::current(), sync_loop_); 433 DCHECK_EQ(MessageLoop::current(), sync_loop_);
447 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES)
448 return CONTINUE;
449 434
450 // See if our type is throttled. 435 // See if our type is throttled.
451 ModelTypeSet throttled_types = 436 ModelTypeSet throttled_types =
452 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); 437 session_context_->throttled_data_type_tracker()->GetThrottledTypes();
453 if (job.purpose == SyncSessionJob::NUDGE && 438 if (job.purpose == SyncSessionJob::NUDGE &&
454 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { 439 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) {
455 ModelTypeSet requested_types; 440 ModelTypeSet requested_types;
456 for (ModelTypePayloadMap::const_iterator i = 441 for (ModelTypePayloadMap::const_iterator i =
457 job.session->source().types.begin(); 442 job.session->source().types.begin();
458 i != job.session->source().types.end(); 443 i != job.session->source().types.end();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 517
533 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose == 518 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose ==
534 SyncSessionJob::CONFIGURATION); 519 SyncSessionJob::CONFIGURATION);
535 520
536 SaveJob(job); 521 SaveJob(job);
537 return false; 522 return false;
538 } 523 }
539 524
540 void SyncSchedulerImpl::SaveJob(const SyncSessionJob& job) { 525 void SyncSchedulerImpl::SaveJob(const SyncSessionJob& job) {
541 DCHECK_EQ(MessageLoop::current(), sync_loop_); 526 DCHECK_EQ(MessageLoop::current(), sync_loop_);
542 // TODO(sync): Should we also check that job.purpose !=
543 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.)
544 if (job.purpose == SyncSessionJob::NUDGE) { 527 if (job.purpose == SyncSessionJob::NUDGE) {
545 SDVLOG(2) << "Saving a nudge job"; 528 SDVLOG(2) << "Saving a nudge job";
546 InitOrCoalescePendingJob(job); 529 InitOrCoalescePendingJob(job);
547 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ 530 } else if (job.purpose == SyncSessionJob::CONFIGURATION){
548 SDVLOG(2) << "Saving a configuration job"; 531 SDVLOG(2) << "Saving a configuration job";
549 DCHECK(wait_interval_.get()); 532 DCHECK(wait_interval_.get());
550 DCHECK(mode_ == CONFIGURATION_MODE); 533 DCHECK(mode_ == CONFIGURATION_MODE);
551 534
552 // Config params should always get set. 535 // Config params should always get set.
553 DCHECK(!job.config_params.ready_task.is_null()); 536 DCHECK(!job.config_params.ready_task.is_null());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 switch (purpose) { 673 switch (purpose) {
691 case SyncSessionJob::CONFIGURATION: 674 case SyncSessionJob::CONFIGURATION:
692 *start = DOWNLOAD_UPDATES; 675 *start = DOWNLOAD_UPDATES;
693 *end = APPLY_UPDATES; 676 *end = APPLY_UPDATES;
694 return; 677 return;
695 case SyncSessionJob::NUDGE: 678 case SyncSessionJob::NUDGE:
696 case SyncSessionJob::POLL: 679 case SyncSessionJob::POLL:
697 *start = SYNCER_BEGIN; 680 *start = SYNCER_BEGIN;
698 *end = SYNCER_END; 681 *end = SYNCER_END;
699 return; 682 return;
700 case SyncSessionJob::CLEANUP_DISABLED_TYPES:
701 *start = CLEANUP_DISABLED_TYPES;
702 *end = CLEANUP_DISABLED_TYPES;
703 return;
704 default: 683 default:
705 NOTREACHED(); 684 NOTREACHED();
706 *start = SYNCER_END; 685 *start = SYNCER_END;
707 *end = SYNCER_END; 686 *end = SYNCER_END;
708 return; 687 return;
709 } 688 }
710 } 689 }
711 690
712 void SyncSchedulerImpl::PostTask( 691 void SyncSchedulerImpl::PostTask(
713 const tracked_objects::Location& from_here, 692 const tracked_objects::Location& from_here,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 syncer_->SyncShare(job.session.get(), begin, end); 777 syncer_->SyncShare(job.session.get(), begin, end);
799 has_more_to_sync = job.session->HasMoreToSync(); 778 has_more_to_sync = job.session->HasMoreToSync();
800 if (has_more_to_sync) 779 if (has_more_to_sync)
801 job.session->PrepareForAnotherSyncCycle(); 780 job.session->PrepareForAnotherSyncCycle();
802 } 781 }
803 SDVLOG(2) << "Done SyncShare looping."; 782 SDVLOG(2) << "Done SyncShare looping.";
804 783
805 FinishSyncSessionJob(job); 784 FinishSyncSessionJob(job);
806 } 785 }
807 786
808 void SyncSchedulerImpl::UpdateCarryoverSessionState(
809 const SyncSessionJob& old_job) {
810 DCHECK_EQ(MessageLoop::current(), sync_loop_);
811 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
812 // Whatever types were part of a configuration task will have had updates
813 // downloaded. For that reason, we make sure they get recorded in the
814 // event that they get disabled at a later time.
815 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info());
816 if (!r.empty()) {
817 ModelSafeRoutingInfo temp_r;
818 ModelSafeRoutingInfo old_info(old_job.session->routing_info());
819 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(),
820 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin()));
821 session_context_->set_previous_session_routing_info(temp_r);
822 }
823 } else {
824 session_context_->set_previous_session_routing_info(
825 old_job.session->routing_info());
826 }
827 }
828
829 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { 787 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) {
830 DCHECK_EQ(MessageLoop::current(), sync_loop_); 788 DCHECK_EQ(MessageLoop::current(), sync_loop_);
831 // Update timing information for how often datatypes are triggering nudges. 789 // Update timing information for how often datatypes are triggering nudges.
832 base::TimeTicks now = TimeTicks::Now(); 790 base::TimeTicks now = TimeTicks::Now();
833 if (!last_sync_session_end_time_.is_null()) { 791 if (!last_sync_session_end_time_.is_null()) {
834 ModelTypePayloadMap::const_iterator iter; 792 ModelTypePayloadMap::const_iterator iter;
835 for (iter = job.session->source().types.begin(); 793 for (iter = job.session->source().types.begin();
836 iter != job.session->source().types.end(); 794 iter != job.session->source().types.end();
837 ++iter) { 795 ++iter) {
838 #define PER_DATA_TYPE_MACRO(type_str) \ 796 #define PER_DATA_TYPE_MACRO(type_str) \
839 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ 797 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \
840 now - last_sync_session_end_time_); 798 now - last_sync_session_end_time_);
841 SYNC_DATA_TYPE_HISTOGRAM(iter->first); 799 SYNC_DATA_TYPE_HISTOGRAM(iter->first);
842 #undef PER_DATA_TYPE_MACRO 800 #undef PER_DATA_TYPE_MACRO
843 } 801 }
844 } 802 }
845 last_sync_session_end_time_ = now; 803 last_sync_session_end_time_ = now;
846 804
847 // Now update the status of the connection from SCM. We need this to decide 805 // Now update the status of the connection from SCM. We need this to decide
848 // whether we need to save/run future jobs. The notifications from SCM are not 806 // whether we need to save/run future jobs. The notifications from SCM are not
849 // reliable. 807 // reliable.
850 // 808 //
851 // TODO(rlarocque): crbug.com/110954 809 // TODO(rlarocque): crbug.com/110954
852 // We should get rid of the notifications and it is probably not needed to 810 // We should get rid of the notifications and it is probably not needed to
853 // maintain this status variable in 2 places. We should query it directly from 811 // maintain this status variable in 2 places. We should query it directly from
854 // SCM when needed. 812 // SCM when needed.
855 ServerConnectionManager* scm = session_context_->connection_manager(); 813 ServerConnectionManager* scm = session_context_->connection_manager();
856 UpdateServerConnectionManagerStatus(scm->server_status()); 814 UpdateServerConnectionManagerStatus(scm->server_status());
857 815
858 UpdateCarryoverSessionState(job);
859 if (IsSyncingCurrentlySilenced()) { 816 if (IsSyncingCurrentlySilenced()) {
860 SDVLOG(2) << "We are currently throttled; not scheduling the next sync."; 817 SDVLOG(2) << "We are currently throttled; not scheduling the next sync.";
861 // TODO(sync): Investigate whether we need to check job.purpose 818 // TODO(sync): Investigate whether we need to check job.purpose
862 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.) 819 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.)
863 SaveJob(job); 820 SaveJob(job);
864 return; // Nothing to do. 821 return; // Nothing to do.
865 } else if (job.session->Succeeded() && 822 } else if (job.session->Succeeded() &&
866 !job.config_params.ready_task.is_null()) { 823 !job.config_params.ready_task.is_null()) {
867 // If this was a configuration job with a ready task, invoke it now that 824 // If this was a configuration job with a ready task, invoke it now that
868 // we finished successfully. 825 // we finished successfully.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 1156
1200 #undef SDVLOG_LOC 1157 #undef SDVLOG_LOC
1201 1158
1202 #undef SDVLOG 1159 #undef SDVLOG
1203 1160
1204 #undef SLOG 1161 #undef SLOG
1205 1162
1206 #undef ENUM_CASE 1163 #undef ENUM_CASE
1207 1164
1208 } // namespace syncer 1165 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_impl.h ('k') | sync/engine/sync_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698