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

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

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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_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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 &restricted_workers); 350 &restricted_workers);
351 session_context_->set_routing_info(params.routing_info); 351 session_context_->set_routing_info(params.routing_info);
352 352
353 // Only reconfigure if we have types to download. 353 // Only reconfigure if we have types to download.
354 if (!params.types_to_download.Empty()) { 354 if (!params.types_to_download.Empty()) {
355 DCHECK(!restricted_routes.empty()); 355 DCHECK(!restricted_routes.empty());
356 linked_ptr<SyncSession> session(new SyncSession( 356 linked_ptr<SyncSession> session(new SyncSession(
357 session_context_, 357 session_context_,
358 this, 358 this,
359 SyncSourceInfo(params.source, 359 SyncSourceInfo(params.source,
360 ModelSafeRoutingInfoToPayloadMap( 360 ModelSafeRoutingInfoToStateMap(
361 restricted_routes, 361 restricted_routes,
362 std::string())), 362 std::string())),
363 restricted_routes, 363 restricted_routes,
364 restricted_workers)); 364 restricted_workers));
365 SyncSessionJob job(SyncSessionJob::CONFIGURATION, 365 SyncSessionJob job(SyncSessionJob::CONFIGURATION,
366 TimeTicks::Now(), 366 TimeTicks::Now(),
367 session, 367 session,
368 false, 368 false,
369 params, 369 params,
370 FROM_HERE); 370 FROM_HERE);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( 422 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob(
423 const SyncSessionJob& job) { 423 const SyncSessionJob& job) {
424 DCHECK_EQ(MessageLoop::current(), sync_loop_); 424 DCHECK_EQ(MessageLoop::current(), sync_loop_);
425 425
426 // See if our type is throttled. 426 // See if our type is throttled.
427 ModelTypeSet throttled_types = 427 ModelTypeSet throttled_types =
428 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); 428 session_context_->throttled_data_type_tracker()->GetThrottledTypes();
429 if (job.purpose == SyncSessionJob::NUDGE && 429 if (job.purpose == SyncSessionJob::NUDGE &&
430 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { 430 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) {
431 ModelTypeSet requested_types; 431 ModelTypeSet requested_types;
432 for (ModelTypePayloadMap::const_iterator i = 432 for (ModelTypeStateMap::const_iterator i =
433 job.session->source().types.begin(); 433 job.session->source().types.begin();
434 i != job.session->source().types.end(); 434 i != job.session->source().types.end();
435 ++i) { 435 ++i) {
436 requested_types.Put(i->first); 436 requested_types.Put(i->first);
437 } 437 }
438 438
439 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) 439 if (!requested_types.Empty() && throttled_types.HasAll(requested_types))
440 return SAVE; 440 return SAVE;
441 } 441 }
442 442
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 void SyncSchedulerImpl::ScheduleNudgeAsync( 553 void SyncSchedulerImpl::ScheduleNudgeAsync(
554 const TimeDelta& delay, 554 const TimeDelta& delay,
555 NudgeSource source, ModelTypeSet types, 555 NudgeSource source, ModelTypeSet types,
556 const tracked_objects::Location& nudge_location) { 556 const tracked_objects::Location& nudge_location) {
557 DCHECK_EQ(MessageLoop::current(), sync_loop_); 557 DCHECK_EQ(MessageLoop::current(), sync_loop_);
558 SDVLOG_LOC(nudge_location, 2) 558 SDVLOG_LOC(nudge_location, 2)
559 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 559 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
560 << "source " << GetNudgeSourceString(source) << ", " 560 << "source " << GetNudgeSourceString(source) << ", "
561 << "types " << ModelTypeSetToString(types); 561 << "types " << ModelTypeSetToString(types);
562 562
563 ModelTypePayloadMap types_with_payloads = 563 ModelTypeStateMap type_state_map =
564 ModelTypePayloadMapFromEnumSet(types, std::string()); 564 ModelTypeStateMapFromEnumSet(types, std::string());
565 SyncSchedulerImpl::ScheduleNudgeImpl(delay, 565 SyncSchedulerImpl::ScheduleNudgeImpl(delay,
566 GetUpdatesFromNudgeSource(source), 566 GetUpdatesFromNudgeSource(source),
567 types_with_payloads, 567 type_state_map,
568 false, 568 false,
569 nudge_location); 569 nudge_location);
570 } 570 }
571 571
572 void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( 572 void SyncSchedulerImpl::ScheduleNudgeWithStatesAsync(
573 const TimeDelta& delay, 573 const TimeDelta& delay,
574 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 574 NudgeSource source, const ModelTypeStateMap& type_state_map,
575 const tracked_objects::Location& nudge_location) { 575 const tracked_objects::Location& nudge_location) {
576 DCHECK_EQ(MessageLoop::current(), sync_loop_); 576 DCHECK_EQ(MessageLoop::current(), sync_loop_);
577 SDVLOG_LOC(nudge_location, 2) 577 SDVLOG_LOC(nudge_location, 2)
578 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 578 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
579 << "source " << GetNudgeSourceString(source) << ", " 579 << "source " << GetNudgeSourceString(source) << ", "
580 << "payloads " 580 << "payloads "
581 << ModelTypePayloadMapToString(types_with_payloads); 581 << ModelTypeStateMapToString(type_state_map);
582 582
583 SyncSchedulerImpl::ScheduleNudgeImpl(delay, 583 SyncSchedulerImpl::ScheduleNudgeImpl(delay,
584 GetUpdatesFromNudgeSource(source), 584 GetUpdatesFromNudgeSource(source),
585 types_with_payloads, 585 type_state_map,
586 false, 586 false,
587 nudge_location); 587 nudge_location);
588 } 588 }
589 589
590 void SyncSchedulerImpl::ScheduleNudgeImpl( 590 void SyncSchedulerImpl::ScheduleNudgeImpl(
591 const TimeDelta& delay, 591 const TimeDelta& delay,
592 GetUpdatesCallerInfo::GetUpdatesSource source, 592 GetUpdatesCallerInfo::GetUpdatesSource source,
593 const ModelTypePayloadMap& types_with_payloads, 593 const ModelTypeStateMap& type_state_map,
594 bool is_canary_job, const tracked_objects::Location& nudge_location) { 594 bool is_canary_job, const tracked_objects::Location& nudge_location) {
595 DCHECK_EQ(MessageLoop::current(), sync_loop_); 595 DCHECK_EQ(MessageLoop::current(), sync_loop_);
596 596
597 SDVLOG_LOC(nudge_location, 2) 597 SDVLOG_LOC(nudge_location, 2)
598 << "In ScheduleNudgeImpl with delay " 598 << "In ScheduleNudgeImpl with delay "
599 << delay.InMilliseconds() << " ms, " 599 << delay.InMilliseconds() << " ms, "
600 << "source " << GetUpdatesSourceString(source) << ", " 600 << "source " << GetUpdatesSourceString(source) << ", "
601 << "payloads " 601 << "payloads "
602 << ModelTypePayloadMapToString(types_with_payloads) 602 << ModelTypeStateMapToString(type_state_map)
603 << (is_canary_job ? " (canary)" : ""); 603 << (is_canary_job ? " (canary)" : "");
604 604
605 SyncSourceInfo info(source, types_with_payloads); 605 SyncSourceInfo info(source, type_state_map);
606 606
607 SyncSession* session(CreateSyncSession(info)); 607 SyncSession* session(CreateSyncSession(info));
608 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, 608 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay,
609 make_linked_ptr(session), is_canary_job, 609 make_linked_ptr(session), is_canary_job,
610 ConfigurationParams(), nudge_location); 610 ConfigurationParams(), nudge_location);
611 611
612 session = NULL; 612 session = NULL;
613 if (!ShouldRunJob(job)) 613 if (!ShouldRunJob(job))
614 return; 614 return;
615 615
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 SDVLOG(2) << "Done SyncShare looping."; 773 SDVLOG(2) << "Done SyncShare looping.";
774 774
775 FinishSyncSessionJob(job); 775 FinishSyncSessionJob(job);
776 } 776 }
777 777
778 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { 778 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) {
779 DCHECK_EQ(MessageLoop::current(), sync_loop_); 779 DCHECK_EQ(MessageLoop::current(), sync_loop_);
780 // Update timing information for how often datatypes are triggering nudges. 780 // Update timing information for how often datatypes are triggering nudges.
781 base::TimeTicks now = TimeTicks::Now(); 781 base::TimeTicks now = TimeTicks::Now();
782 if (!last_sync_session_end_time_.is_null()) { 782 if (!last_sync_session_end_time_.is_null()) {
783 ModelTypePayloadMap::const_iterator iter; 783 ModelTypeStateMap::const_iterator iter;
784 for (iter = job.session->source().types.begin(); 784 for (iter = job.session->source().types.begin();
785 iter != job.session->source().types.end(); 785 iter != job.session->source().types.end();
786 ++iter) { 786 ++iter) {
787 #define PER_DATA_TYPE_MACRO(type_str) \ 787 #define PER_DATA_TYPE_MACRO(type_str) \
788 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ 788 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \
789 now - last_sync_session_end_time_); 789 now - last_sync_session_end_time_);
790 SYNC_DATA_TYPE_HISTOGRAM(iter->first); 790 SYNC_DATA_TYPE_HISTOGRAM(iter->first);
791 #undef PER_DATA_TYPE_MACRO 791 #undef PER_DATA_TYPE_MACRO
792 } 792 }
793 } 793 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 SyncSourceInfo info(source); 1034 SyncSourceInfo info(source);
1035 SyncSession* session(new SyncSession(session_context_, this, info, 1035 SyncSession* session(new SyncSession(session_context_, this, info,
1036 session_context_->routing_info(), session_context_->workers())); 1036 session_context_->routing_info(), session_context_->workers()));
1037 1037
1038 return session; 1038 return session;
1039 } 1039 }
1040 1040
1041 void SyncSchedulerImpl::PollTimerCallback() { 1041 void SyncSchedulerImpl::PollTimerCallback() {
1042 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1042 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1043 ModelSafeRoutingInfo r; 1043 ModelSafeRoutingInfo r;
1044 ModelTypePayloadMap types_with_payloads = 1044 ModelTypeStateMap type_state_map =
1045 ModelSafeRoutingInfoToPayloadMap(r, std::string()); 1045 ModelSafeRoutingInfoToStateMap(r, std::string());
1046 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); 1046 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, type_state_map);
1047 SyncSession* s = CreateSyncSession(info); 1047 SyncSession* s = CreateSyncSession(info);
1048 1048
1049 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), 1049 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(),
1050 make_linked_ptr(s), 1050 make_linked_ptr(s),
1051 false, 1051 false,
1052 ConfigurationParams(), 1052 ConfigurationParams(),
1053 FROM_HERE); 1053 FROM_HERE);
1054 1054
1055 ScheduleSyncSessionJob(job); 1055 ScheduleSyncSessionJob(job);
1056 } 1056 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 1147
1148 #undef SDVLOG_LOC 1148 #undef SDVLOG_LOC
1149 1149
1150 #undef SDVLOG 1150 #undef SDVLOG
1151 1151
1152 #undef SLOG 1152 #undef SLOG
1153 1153
1154 #undef ENUM_CASE 1154 #undef ENUM_CASE
1155 1155
1156 } // namespace syncer 1156 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698