| 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_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/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 &restricted_routes); | 336 &restricted_routes); |
| 337 session_context_->set_routing_info(params.routing_info); | 337 session_context_->set_routing_info(params.routing_info); |
| 338 | 338 |
| 339 // Only reconfigure if we have types to download. | 339 // Only reconfigure if we have types to download. |
| 340 if (!params.types_to_download.Empty()) { | 340 if (!params.types_to_download.Empty()) { |
| 341 DCHECK(!restricted_routes.empty()); | 341 DCHECK(!restricted_routes.empty()); |
| 342 linked_ptr<SyncSession> session(new SyncSession( | 342 linked_ptr<SyncSession> session(new SyncSession( |
| 343 session_context_, | 343 session_context_, |
| 344 this, | 344 this, |
| 345 SyncSourceInfo(params.source, | 345 SyncSourceInfo(params.source, |
| 346 ModelSafeRoutingInfoToStateMap( | 346 ModelSafeRoutingInfoToInvalidationMap( |
| 347 restricted_routes, | 347 restricted_routes, |
| 348 std::string())), | 348 std::string())), |
| 349 restricted_routes, | 349 restricted_routes, |
| 350 session_context_->workers())); | 350 session_context_->workers())); |
| 351 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | 351 SyncSessionJob job(SyncSessionJob::CONFIGURATION, |
| 352 TimeTicks::Now(), | 352 TimeTicks::Now(), |
| 353 session, | 353 session, |
| 354 false, | 354 false, |
| 355 params, | 355 params, |
| 356 FROM_HERE); | 356 FROM_HERE); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( | 408 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( |
| 409 const SyncSessionJob& job) { | 409 const SyncSessionJob& job) { |
| 410 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 410 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 411 | 411 |
| 412 // See if our type is throttled. | 412 // See if our type is throttled. |
| 413 ModelTypeSet throttled_types = | 413 ModelTypeSet throttled_types = |
| 414 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 414 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 415 if (job.purpose == SyncSessionJob::NUDGE && | 415 if (job.purpose == SyncSessionJob::NUDGE && |
| 416 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 416 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| 417 ModelTypeSet requested_types; | 417 ModelTypeSet requested_types; |
| 418 for (ModelTypeStateMap::const_iterator i = | 418 for (ModelTypeInvalidationMap::const_iterator i = |
| 419 job.session->source().types.begin(); | 419 job.session->source().types.begin(); |
| 420 i != job.session->source().types.end(); | 420 i != job.session->source().types.end(); |
| 421 ++i) { | 421 ++i) { |
| 422 requested_types.Put(i->first); | 422 requested_types.Put(i->first); |
| 423 } | 423 } |
| 424 | 424 |
| 425 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) | 425 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) |
| 426 return SAVE; | 426 return SAVE; |
| 427 } | 427 } |
| 428 | 428 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 void SyncSchedulerImpl::ScheduleNudgeAsync( | 572 void SyncSchedulerImpl::ScheduleNudgeAsync( |
| 573 const TimeDelta& delay, | 573 const TimeDelta& delay, |
| 574 NudgeSource source, ModelTypeSet types, | 574 NudgeSource source, ModelTypeSet types, |
| 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 << "types " << ModelTypeSetToString(types); | 580 << "types " << ModelTypeSetToString(types); |
| 581 | 581 |
| 582 ModelTypeStateMap type_state_map = | 582 ModelTypeInvalidationMap invalidation_map = |
| 583 ModelTypeSetToStateMap(types, std::string()); | 583 ModelTypeSetToInvalidationMap(types, std::string()); |
| 584 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 584 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 585 GetUpdatesFromNudgeSource(source), | 585 GetUpdatesFromNudgeSource(source), |
| 586 type_state_map, | 586 invalidation_map, |
| 587 false, | 587 false, |
| 588 nudge_location); | 588 nudge_location); |
| 589 } | 589 } |
| 590 | 590 |
| 591 void SyncSchedulerImpl::ScheduleNudgeWithStatesAsync( | 591 void SyncSchedulerImpl::ScheduleNudgeWithStatesAsync( |
| 592 const TimeDelta& delay, | 592 const TimeDelta& delay, |
| 593 NudgeSource source, const ModelTypeStateMap& type_state_map, | 593 NudgeSource source, const ModelTypeInvalidationMap& invalidation_map, |
| 594 const tracked_objects::Location& nudge_location) { | 594 const tracked_objects::Location& nudge_location) { |
| 595 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 595 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 596 SDVLOG_LOC(nudge_location, 2) | 596 SDVLOG_LOC(nudge_location, 2) |
| 597 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 597 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 598 << "source " << GetNudgeSourceString(source) << ", " | 598 << "source " << GetNudgeSourceString(source) << ", " |
| 599 << "payloads " | 599 << "payloads " |
| 600 << ModelTypeStateMapToString(type_state_map); | 600 << ModelTypeInvalidationMapToString(invalidation_map); |
| 601 | 601 |
| 602 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 602 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 603 GetUpdatesFromNudgeSource(source), | 603 GetUpdatesFromNudgeSource(source), |
| 604 type_state_map, | 604 invalidation_map, |
| 605 false, | 605 false, |
| 606 nudge_location); | 606 nudge_location); |
| 607 } | 607 } |
| 608 | 608 |
| 609 void SyncSchedulerImpl::ScheduleNudgeImpl( | 609 void SyncSchedulerImpl::ScheduleNudgeImpl( |
| 610 const TimeDelta& delay, | 610 const TimeDelta& delay, |
| 611 GetUpdatesCallerInfo::GetUpdatesSource source, | 611 GetUpdatesCallerInfo::GetUpdatesSource source, |
| 612 const ModelTypeStateMap& type_state_map, | 612 const ModelTypeInvalidationMap& invalidation_map, |
| 613 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 613 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
| 614 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 614 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 615 DCHECK(!type_state_map.empty()) << "Nudge scheduled for no types!"; | 615 DCHECK(!invalidation_map.empty()) << "Nudge scheduled for no types!"; |
| 616 | 616 |
| 617 SDVLOG_LOC(nudge_location, 2) | 617 SDVLOG_LOC(nudge_location, 2) |
| 618 << "In ScheduleNudgeImpl with delay " | 618 << "In ScheduleNudgeImpl with delay " |
| 619 << delay.InMilliseconds() << " ms, " | 619 << delay.InMilliseconds() << " ms, " |
| 620 << "source " << GetUpdatesSourceString(source) << ", " | 620 << "source " << GetUpdatesSourceString(source) << ", " |
| 621 << "payloads " | 621 << "payloads " |
| 622 << ModelTypeStateMapToString(type_state_map) | 622 << ModelTypeInvalidationMapToString(invalidation_map) |
| 623 << (is_canary_job ? " (canary)" : ""); | 623 << (is_canary_job ? " (canary)" : ""); |
| 624 | 624 |
| 625 SyncSourceInfo info(source, type_state_map); | 625 SyncSourceInfo info(source, invalidation_map); |
| 626 UpdateNudgeTimeRecords(info); | 626 UpdateNudgeTimeRecords(info); |
| 627 | 627 |
| 628 SyncSession* session(CreateSyncSession(info)); | 628 SyncSession* session(CreateSyncSession(info)); |
| 629 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 629 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
| 630 make_linked_ptr(session), is_canary_job, | 630 make_linked_ptr(session), is_canary_job, |
| 631 ConfigurationParams(), nudge_location); | 631 ConfigurationParams(), nudge_location); |
| 632 | 632 |
| 633 session = NULL; | 633 session = NULL; |
| 634 if (!ShouldRunJob(job)) | 634 if (!ShouldRunJob(job)) |
| 635 return; | 635 return; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 void SyncSchedulerImpl::UpdateNudgeTimeRecords(const SyncSourceInfo& info) { | 806 void SyncSchedulerImpl::UpdateNudgeTimeRecords(const SyncSourceInfo& info) { |
| 807 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 807 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 808 | 808 |
| 809 // We are interested in recording time between local nudges for datatypes. | 809 // We are interested in recording time between local nudges for datatypes. |
| 810 // TODO(tim): Consider tracking LOCAL_NOTIFICATION as well. | 810 // TODO(tim): Consider tracking LOCAL_NOTIFICATION as well. |
| 811 if (info.updates_source != GetUpdatesCallerInfo::LOCAL) | 811 if (info.updates_source != GetUpdatesCallerInfo::LOCAL) |
| 812 return; | 812 return; |
| 813 | 813 |
| 814 base::TimeTicks now = TimeTicks::Now(); | 814 base::TimeTicks now = TimeTicks::Now(); |
| 815 // Update timing information for how often datatypes are triggering nudges. | 815 // Update timing information for how often datatypes are triggering nudges. |
| 816 for (ModelTypeStateMap::const_iterator iter = info.types.begin(); | 816 for (ModelTypeInvalidationMap::const_iterator iter = info.types.begin(); |
| 817 iter != info.types.end(); | 817 iter != info.types.end(); |
| 818 ++iter) { | 818 ++iter) { |
| 819 base::TimeTicks previous = last_local_nudges_by_model_type_[iter->first]; | 819 base::TimeTicks previous = last_local_nudges_by_model_type_[iter->first]; |
| 820 last_local_nudges_by_model_type_[iter->first] = now; | 820 last_local_nudges_by_model_type_[iter->first] = now; |
| 821 if (previous.is_null()) | 821 if (previous.is_null()) |
| 822 continue; | 822 continue; |
| 823 | 823 |
| 824 #define PER_DATA_TYPE_MACRO(type_str) \ | 824 #define PER_DATA_TYPE_MACRO(type_str) \ |
| 825 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, now - previous); | 825 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, now - previous); |
| 826 SYNC_DATA_TYPE_HISTOGRAM(iter->first); | 826 SYNC_DATA_TYPE_HISTOGRAM(iter->first); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 SyncSourceInfo info(source); | 1046 SyncSourceInfo info(source); |
| 1047 SyncSession* session(new SyncSession(session_context_, this, info, | 1047 SyncSession* session(new SyncSession(session_context_, this, info, |
| 1048 session_context_->routing_info(), session_context_->workers())); | 1048 session_context_->routing_info(), session_context_->workers())); |
| 1049 | 1049 |
| 1050 return session; | 1050 return session; |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 void SyncSchedulerImpl::PollTimerCallback() { | 1053 void SyncSchedulerImpl::PollTimerCallback() { |
| 1054 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1054 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1055 ModelSafeRoutingInfo r; | 1055 ModelSafeRoutingInfo r; |
| 1056 ModelTypeStateMap type_state_map = | 1056 ModelTypeInvalidationMap invalidation_map = |
| 1057 ModelSafeRoutingInfoToStateMap(r, std::string()); | 1057 ModelSafeRoutingInfoToInvalidationMap(r, std::string()); |
| 1058 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, type_state_map); | 1058 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, invalidation_map); |
| 1059 SyncSession* s = CreateSyncSession(info); | 1059 SyncSession* s = CreateSyncSession(info); |
| 1060 | 1060 |
| 1061 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), | 1061 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
| 1062 make_linked_ptr(s), | 1062 make_linked_ptr(s), |
| 1063 false, | 1063 false, |
| 1064 ConfigurationParams(), | 1064 ConfigurationParams(), |
| 1065 FROM_HERE); | 1065 FROM_HERE); |
| 1066 | 1066 |
| 1067 ScheduleSyncSessionJob(job); | 1067 ScheduleSyncSessionJob(job); |
| 1068 } | 1068 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 | 1159 |
| 1160 #undef SDVLOG_LOC | 1160 #undef SDVLOG_LOC |
| 1161 | 1161 |
| 1162 #undef SDVLOG | 1162 #undef SDVLOG |
| 1163 | 1163 |
| 1164 #undef SLOG | 1164 #undef SLOG |
| 1165 | 1165 |
| 1166 #undef ENUM_CASE | 1166 #undef ENUM_CASE |
| 1167 | 1167 |
| 1168 } // namespace syncer | 1168 } // namespace syncer |
| OLD | NEW |