| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 &restricted_workers); | 344 &restricted_workers); |
| 345 session_context_->set_routing_info(params.routing_info); | 345 session_context_->set_routing_info(params.routing_info); |
| 346 | 346 |
| 347 // Only reconfigure if we have types to download. | 347 // Only reconfigure if we have types to download. |
| 348 if (!params.types_to_download.Empty()) { | 348 if (!params.types_to_download.Empty()) { |
| 349 DCHECK(!restricted_routes.empty()); | 349 DCHECK(!restricted_routes.empty()); |
| 350 linked_ptr<SyncSession> session(new SyncSession( | 350 linked_ptr<SyncSession> session(new SyncSession( |
| 351 session_context_, | 351 session_context_, |
| 352 this, | 352 this, |
| 353 SyncSourceInfo(params.source, | 353 SyncSourceInfo(params.source, |
| 354 ModelSafeRoutingInfoToPayloadMap( | 354 ModelSafeRoutingInfoToStateMap( |
| 355 restricted_routes, | 355 restricted_routes, |
| 356 std::string())), | 356 std::string())), |
| 357 restricted_routes, | 357 restricted_routes, |
| 358 restricted_workers)); | 358 restricted_workers)); |
| 359 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | 359 SyncSessionJob job(SyncSessionJob::CONFIGURATION, |
| 360 TimeTicks::Now(), | 360 TimeTicks::Now(), |
| 361 session, | 361 session, |
| 362 false, | 362 false, |
| 363 params, | 363 params, |
| 364 FROM_HERE); | 364 FROM_HERE); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( | 416 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( |
| 417 const SyncSessionJob& job) { | 417 const SyncSessionJob& job) { |
| 418 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 418 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 419 | 419 |
| 420 // See if our type is throttled. | 420 // See if our type is throttled. |
| 421 ModelTypeSet throttled_types = | 421 ModelTypeSet throttled_types = |
| 422 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 422 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 423 if (job.purpose == SyncSessionJob::NUDGE && | 423 if (job.purpose == SyncSessionJob::NUDGE && |
| 424 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 424 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| 425 ModelTypeSet requested_types; | 425 ModelTypeSet requested_types; |
| 426 for (ModelTypePayloadMap::const_iterator i = | 426 for (ModelTypeStateMap::const_iterator i = |
| 427 job.session->source().types.begin(); | 427 job.session->source().types.begin(); |
| 428 i != job.session->source().types.end(); | 428 i != job.session->source().types.end(); |
| 429 ++i) { | 429 ++i) { |
| 430 requested_types.Put(i->first); | 430 requested_types.Put(i->first); |
| 431 } | 431 } |
| 432 | 432 |
| 433 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) | 433 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) |
| 434 return SAVE; | 434 return SAVE; |
| 435 } | 435 } |
| 436 | 436 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 void SyncSchedulerImpl::ScheduleNudgeAsync( | 547 void SyncSchedulerImpl::ScheduleNudgeAsync( |
| 548 const TimeDelta& delay, | 548 const TimeDelta& delay, |
| 549 NudgeSource source, ModelTypeSet types, | 549 NudgeSource source, ModelTypeSet types, |
| 550 const tracked_objects::Location& nudge_location) { | 550 const tracked_objects::Location& nudge_location) { |
| 551 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 551 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 552 SDVLOG_LOC(nudge_location, 2) | 552 SDVLOG_LOC(nudge_location, 2) |
| 553 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 553 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 554 << "source " << GetNudgeSourceString(source) << ", " | 554 << "source " << GetNudgeSourceString(source) << ", " |
| 555 << "types " << ModelTypeSetToString(types); | 555 << "types " << ModelTypeSetToString(types); |
| 556 | 556 |
| 557 ModelTypePayloadMap types_with_payloads = | 557 ModelTypeStateMap type_state_map = |
| 558 ModelTypePayloadMapFromEnumSet(types, std::string()); | 558 ModelTypeStateMapFromEnumSet(types, std::string()); |
| 559 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 559 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 560 GetUpdatesFromNudgeSource(source), | 560 GetUpdatesFromNudgeSource(source), |
| 561 types_with_payloads, | 561 type_state_map, |
| 562 false, | 562 false, |
| 563 nudge_location); | 563 nudge_location); |
| 564 } | 564 } |
| 565 | 565 |
| 566 void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( | 566 void SyncSchedulerImpl::ScheduleNudgeWithStatesAsync( |
| 567 const TimeDelta& delay, | 567 const TimeDelta& delay, |
| 568 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, | 568 NudgeSource source, const ModelTypeStateMap& type_state_map, |
| 569 const tracked_objects::Location& nudge_location) { | 569 const tracked_objects::Location& nudge_location) { |
| 570 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 570 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 571 SDVLOG_LOC(nudge_location, 2) | 571 SDVLOG_LOC(nudge_location, 2) |
| 572 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 572 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 573 << "source " << GetNudgeSourceString(source) << ", " | 573 << "source " << GetNudgeSourceString(source) << ", " |
| 574 << "payloads " | 574 << "payloads " |
| 575 << ModelTypePayloadMapToString(types_with_payloads); | 575 << ModelTypeStateMapToString(type_state_map); |
| 576 | 576 |
| 577 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 577 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 578 GetUpdatesFromNudgeSource(source), | 578 GetUpdatesFromNudgeSource(source), |
| 579 types_with_payloads, | 579 type_state_map, |
| 580 false, | 580 false, |
| 581 nudge_location); | 581 nudge_location); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void SyncSchedulerImpl::ScheduleNudgeImpl( | 584 void SyncSchedulerImpl::ScheduleNudgeImpl( |
| 585 const TimeDelta& delay, | 585 const TimeDelta& delay, |
| 586 GetUpdatesCallerInfo::GetUpdatesSource source, | 586 GetUpdatesCallerInfo::GetUpdatesSource source, |
| 587 const ModelTypePayloadMap& types_with_payloads, | 587 const ModelTypeStateMap& type_state_map, |
| 588 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 588 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
| 589 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 589 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 590 | 590 |
| 591 SDVLOG_LOC(nudge_location, 2) | 591 SDVLOG_LOC(nudge_location, 2) |
| 592 << "In ScheduleNudgeImpl with delay " | 592 << "In ScheduleNudgeImpl with delay " |
| 593 << delay.InMilliseconds() << " ms, " | 593 << delay.InMilliseconds() << " ms, " |
| 594 << "source " << GetUpdatesSourceString(source) << ", " | 594 << "source " << GetUpdatesSourceString(source) << ", " |
| 595 << "payloads " | 595 << "payloads " |
| 596 << ModelTypePayloadMapToString(types_with_payloads) | 596 << ModelTypeStateMapToString(type_state_map) |
| 597 << (is_canary_job ? " (canary)" : ""); | 597 << (is_canary_job ? " (canary)" : ""); |
| 598 | 598 |
| 599 SyncSourceInfo info(source, types_with_payloads); | 599 SyncSourceInfo info(source, type_state_map); |
| 600 | 600 |
| 601 SyncSession* session(CreateSyncSession(info)); | 601 SyncSession* session(CreateSyncSession(info)); |
| 602 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 602 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
| 603 make_linked_ptr(session), is_canary_job, | 603 make_linked_ptr(session), is_canary_job, |
| 604 ConfigurationParams(), nudge_location); | 604 ConfigurationParams(), nudge_location); |
| 605 | 605 |
| 606 session = NULL; | 606 session = NULL; |
| 607 if (!ShouldRunJob(job)) | 607 if (!ShouldRunJob(job)) |
| 608 return; | 608 return; |
| 609 | 609 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 SDVLOG(2) << "Done SyncShare looping."; | 767 SDVLOG(2) << "Done SyncShare looping."; |
| 768 | 768 |
| 769 FinishSyncSessionJob(job); | 769 FinishSyncSessionJob(job); |
| 770 } | 770 } |
| 771 | 771 |
| 772 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { | 772 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { |
| 773 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 773 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 774 // Update timing information for how often datatypes are triggering nudges. | 774 // Update timing information for how often datatypes are triggering nudges. |
| 775 base::TimeTicks now = TimeTicks::Now(); | 775 base::TimeTicks now = TimeTicks::Now(); |
| 776 if (!last_sync_session_end_time_.is_null()) { | 776 if (!last_sync_session_end_time_.is_null()) { |
| 777 ModelTypePayloadMap::const_iterator iter; | 777 ModelTypeStateMap::const_iterator iter; |
| 778 for (iter = job.session->source().types.begin(); | 778 for (iter = job.session->source().types.begin(); |
| 779 iter != job.session->source().types.end(); | 779 iter != job.session->source().types.end(); |
| 780 ++iter) { | 780 ++iter) { |
| 781 #define PER_DATA_TYPE_MACRO(type_str) \ | 781 #define PER_DATA_TYPE_MACRO(type_str) \ |
| 782 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ | 782 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ |
| 783 now - last_sync_session_end_time_); | 783 now - last_sync_session_end_time_); |
| 784 SYNC_DATA_TYPE_HISTOGRAM(iter->first); | 784 SYNC_DATA_TYPE_HISTOGRAM(iter->first); |
| 785 #undef PER_DATA_TYPE_MACRO | 785 #undef PER_DATA_TYPE_MACRO |
| 786 } | 786 } |
| 787 } | 787 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 SyncSourceInfo info(source); | 1006 SyncSourceInfo info(source); |
| 1007 SyncSession* session(new SyncSession(session_context_, this, info, | 1007 SyncSession* session(new SyncSession(session_context_, this, info, |
| 1008 session_context_->routing_info(), session_context_->workers())); | 1008 session_context_->routing_info(), session_context_->workers())); |
| 1009 | 1009 |
| 1010 return session; | 1010 return session; |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 void SyncSchedulerImpl::PollTimerCallback() { | 1013 void SyncSchedulerImpl::PollTimerCallback() { |
| 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1015 ModelSafeRoutingInfo r; | 1015 ModelSafeRoutingInfo r; |
| 1016 ModelTypePayloadMap types_with_payloads = | 1016 ModelTypeStateMap type_state_map = |
| 1017 ModelSafeRoutingInfoToPayloadMap(r, std::string()); | 1017 ModelSafeRoutingInfoToStateMap(r, std::string()); |
| 1018 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); | 1018 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, type_state_map); |
| 1019 SyncSession* s = CreateSyncSession(info); | 1019 SyncSession* s = CreateSyncSession(info); |
| 1020 | 1020 |
| 1021 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), | 1021 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
| 1022 make_linked_ptr(s), | 1022 make_linked_ptr(s), |
| 1023 false, | 1023 false, |
| 1024 ConfigurationParams(), | 1024 ConfigurationParams(), |
| 1025 FROM_HERE); | 1025 FROM_HERE); |
| 1026 | 1026 |
| 1027 ScheduleSyncSessionJob(job); | 1027 ScheduleSyncSessionJob(job); |
| 1028 } | 1028 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 | 1119 |
| 1120 #undef SDVLOG_LOC | 1120 #undef SDVLOG_LOC |
| 1121 | 1121 |
| 1122 #undef SDVLOG | 1122 #undef SDVLOG |
| 1123 | 1123 |
| 1124 #undef SLOG | 1124 #undef SLOG |
| 1125 | 1125 |
| 1126 #undef ENUM_CASE | 1126 #undef ENUM_CASE |
| 1127 | 1127 |
| 1128 } // namespace syncer | 1128 } // namespace syncer |
| OLD | NEW |