| 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 13 matching lines...) Expand all Loading... |
| 24 using base::TimeTicks; | 24 using base::TimeTicks; |
| 25 | 25 |
| 26 namespace syncer { | 26 namespace syncer { |
| 27 | 27 |
| 28 using sessions::SyncSession; | 28 using sessions::SyncSession; |
| 29 using sessions::SyncSessionSnapshot; | 29 using sessions::SyncSessionSnapshot; |
| 30 using sessions::SyncSourceInfo; | 30 using sessions::SyncSourceInfo; |
| 31 using sync_pb::GetUpdatesCallerInfo; | 31 using sync_pb::GetUpdatesCallerInfo; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 bool ShouldRequestEarlyExit( | 34 bool ShouldRequestEarlyExit(const SyncProtocolError& error) { |
| 35 const syncer::SyncProtocolError& error) { | |
| 36 switch (error.error_type) { | 35 switch (error.error_type) { |
| 37 case syncer::SYNC_SUCCESS: | 36 case SYNC_SUCCESS: |
| 38 case syncer::MIGRATION_DONE: | 37 case MIGRATION_DONE: |
| 39 case syncer::THROTTLED: | 38 case THROTTLED: |
| 40 case syncer::TRANSIENT_ERROR: | 39 case TRANSIENT_ERROR: |
| 41 return false; | 40 return false; |
| 42 case syncer::NOT_MY_BIRTHDAY: | 41 case NOT_MY_BIRTHDAY: |
| 43 case syncer::CLEAR_PENDING: | 42 case CLEAR_PENDING: |
| 44 // If we send terminate sync early then |sync_cycle_ended| notification | 43 // If we send terminate sync early then |sync_cycle_ended| notification |
| 45 // would not be sent. If there were no actions then |ACTIONABLE_ERROR| | 44 // would not be sent. If there were no actions then |ACTIONABLE_ERROR| |
| 46 // notification wouldnt be sent either. Then the UI layer would be left | 45 // notification wouldnt be sent either. Then the UI layer would be left |
| 47 // waiting forever. So assert we would send something. | 46 // waiting forever. So assert we would send something. |
| 48 DCHECK(error.action != syncer::UNKNOWN_ACTION); | 47 DCHECK_NE(error.action, UNKNOWN_ACTION); |
| 49 return true; | 48 return true; |
| 50 case syncer::INVALID_CREDENTIAL: | 49 case INVALID_CREDENTIAL: |
| 51 // The notification for this is handled by PostAndProcessHeaders|. | 50 // The notification for this is handled by PostAndProcessHeaders|. |
| 52 // Server does no have to send any action for this. | 51 // Server does no have to send any action for this. |
| 53 return true; | 52 return true; |
| 54 // Make the default a NOTREACHED. So if a new error is introduced we | 53 // Make the default a NOTREACHED. So if a new error is introduced we |
| 55 // think about its expected functionality. | 54 // think about its expected functionality. |
| 56 default: | 55 default: |
| 57 NOTREACHED(); | 56 NOTREACHED(); |
| 58 return false; | 57 return false; |
| 59 } | 58 } |
| 60 } | 59 } |
| 61 | 60 |
| 62 bool IsActionableError( | 61 bool IsActionableError( |
| 63 const syncer::SyncProtocolError& error) { | 62 const SyncProtocolError& error) { |
| 64 return (error.action != syncer::UNKNOWN_ACTION); | 63 return (error.action != UNKNOWN_ACTION); |
| 65 } | 64 } |
| 66 } // namespace | 65 } // namespace |
| 67 | 66 |
| 68 ConfigurationParams::ConfigurationParams() | 67 ConfigurationParams::ConfigurationParams() |
| 69 : source(GetUpdatesCallerInfo::UNKNOWN), | 68 : source(GetUpdatesCallerInfo::UNKNOWN), |
| 70 keystore_key_status(KEYSTORE_KEY_UNNECESSARY) {} | 69 keystore_key_status(KEYSTORE_KEY_UNNECESSARY) {} |
| 71 ConfigurationParams::ConfigurationParams( | 70 ConfigurationParams::ConfigurationParams( |
| 72 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | 71 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, |
| 73 const syncer::ModelTypeSet& types_to_download, | 72 const ModelTypeSet& types_to_download, |
| 74 const syncer::ModelSafeRoutingInfo& routing_info, | 73 const ModelSafeRoutingInfo& routing_info, |
| 75 KeystoreKeyStatus keystore_key_status, | 74 KeystoreKeyStatus keystore_key_status, |
| 76 const base::Closure& ready_task) | 75 const base::Closure& ready_task) |
| 77 : source(source), | 76 : source(source), |
| 78 types_to_download(types_to_download), | 77 types_to_download(types_to_download), |
| 79 routing_info(routing_info), | 78 routing_info(routing_info), |
| 80 keystore_key_status(keystore_key_status), | 79 keystore_key_status(keystore_key_status), |
| 81 ready_task(ready_task) { | 80 ready_task(ready_task) { |
| 82 DCHECK(!ready_task.is_null()); | 81 DCHECK(!ready_task.is_null()); |
| 83 } | 82 } |
| 84 ConfigurationParams::~ConfigurationParams() {} | 83 ConfigurationParams::~ConfigurationParams() {} |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 void BuildModelSafeParams( | 306 void BuildModelSafeParams( |
| 308 const ModelTypeSet& types_to_download, | 307 const ModelTypeSet& types_to_download, |
| 309 const ModelSafeRoutingInfo& current_routes, | 308 const ModelSafeRoutingInfo& current_routes, |
| 310 const std::vector<ModelSafeWorker*>& current_workers, | 309 const std::vector<ModelSafeWorker*>& current_workers, |
| 311 ModelSafeRoutingInfo* result_routes, | 310 ModelSafeRoutingInfo* result_routes, |
| 312 std::vector<ModelSafeWorker*>* result_workers) { | 311 std::vector<ModelSafeWorker*>* result_workers) { |
| 313 std::set<ModelSafeGroup> active_groups; | 312 std::set<ModelSafeGroup> active_groups; |
| 314 active_groups.insert(GROUP_PASSIVE); | 313 active_groups.insert(GROUP_PASSIVE); |
| 315 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); | 314 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); |
| 316 iter.Inc()) { | 315 iter.Inc()) { |
| 317 syncer::ModelType type = iter.Get(); | 316 ModelType type = iter.Get(); |
| 318 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); | 317 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); |
| 319 DCHECK(route != current_routes.end()); | 318 DCHECK(route != current_routes.end()); |
| 320 ModelSafeGroup group = route->second; | 319 ModelSafeGroup group = route->second; |
| 321 (*result_routes)[type] = group; | 320 (*result_routes)[type] = group; |
| 322 active_groups.insert(group); | 321 active_groups.insert(group); |
| 323 } | 322 } |
| 324 | 323 |
| 325 for(std::vector<ModelSafeWorker*>::const_iterator iter = | 324 for(std::vector<ModelSafeWorker*>::const_iterator iter = |
| 326 current_workers.begin(); iter != current_workers.end(); ++iter) { | 325 current_workers.begin(); iter != current_workers.end(); ++iter) { |
| 327 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) | 326 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 DCHECK(!params.ready_task.is_null()); | 338 DCHECK(!params.ready_task.is_null()); |
| 340 SDVLOG(2) << "Reconfiguring syncer."; | 339 SDVLOG(2) << "Reconfiguring syncer."; |
| 341 | 340 |
| 342 // Only one configuration is allowed at a time. Verify we're not waiting | 341 // Only one configuration is allowed at a time. Verify we're not waiting |
| 343 // for a pending configure job. | 342 // for a pending configure job. |
| 344 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); | 343 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); |
| 345 | 344 |
| 346 // TODO(sync): now that ModelChanging commands only use those workers within | 345 // TODO(sync): now that ModelChanging commands only use those workers within |
| 347 // the routing info, we don't really need |restricted_workers|. Remove it. | 346 // the routing info, we don't really need |restricted_workers|. Remove it. |
| 348 // crbug.com/133030 | 347 // crbug.com/133030 |
| 349 syncer::ModelSafeRoutingInfo restricted_routes; | 348 ModelSafeRoutingInfo restricted_routes; |
| 350 std::vector<ModelSafeWorker*> restricted_workers; | 349 std::vector<ModelSafeWorker*> restricted_workers; |
| 351 BuildModelSafeParams(params.types_to_download, | 350 BuildModelSafeParams(params.types_to_download, |
| 352 params.routing_info, | 351 params.routing_info, |
| 353 session_context_->workers(), | 352 session_context_->workers(), |
| 354 &restricted_routes, | 353 &restricted_routes, |
| 355 &restricted_workers); | 354 &restricted_workers); |
| 356 session_context_->set_routing_info(params.routing_info); | 355 session_context_->set_routing_info(params.routing_info); |
| 357 | 356 |
| 358 // We rely on this not failing, so don't need to worry about checking for | 357 // We rely on this not failing, so don't need to worry about checking for |
| 359 // success. In addition, this will be removed as part of crbug.com/131433. | 358 // success. In addition, this will be removed as part of crbug.com/131433. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 return job.is_canary_job ? CONTINUE : SAVE; | 441 return job.is_canary_job ? CONTINUE : SAVE; |
| 443 } | 442 } |
| 444 | 443 |
| 445 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( | 444 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( |
| 446 const SyncSessionJob& job) { | 445 const SyncSessionJob& job) { |
| 447 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 446 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 448 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) | 447 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) |
| 449 return CONTINUE; | 448 return CONTINUE; |
| 450 | 449 |
| 451 // See if our type is throttled. | 450 // See if our type is throttled. |
| 452 syncer::ModelTypeSet throttled_types = | 451 ModelTypeSet throttled_types = |
| 453 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 452 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 454 if (job.purpose == SyncSessionJob::NUDGE && | 453 if (job.purpose == SyncSessionJob::NUDGE && |
| 455 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 454 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| 456 syncer::ModelTypeSet requested_types; | 455 ModelTypeSet requested_types; |
| 457 for (ModelTypePayloadMap::const_iterator i = | 456 for (ModelTypePayloadMap::const_iterator i = |
| 458 job.session->source().types.begin(); | 457 job.session->source().types.begin(); |
| 459 i != job.session->source().types.end(); | 458 i != job.session->source().types.end(); |
| 460 ++i) { | 459 ++i) { |
| 461 requested_types.Put(i->first); | 460 requested_types.Put(i->first); |
| 462 } | 461 } |
| 463 | 462 |
| 464 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) | 463 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) |
| 465 return SAVE; | 464 return SAVE; |
| 466 } | 465 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 const TimeDelta& delay, | 580 const TimeDelta& delay, |
| 582 NudgeSource source, ModelTypeSet types, | 581 NudgeSource source, ModelTypeSet types, |
| 583 const tracked_objects::Location& nudge_location) { | 582 const tracked_objects::Location& nudge_location) { |
| 584 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 583 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 585 SDVLOG_LOC(nudge_location, 2) | 584 SDVLOG_LOC(nudge_location, 2) |
| 586 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 585 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 587 << "source " << GetNudgeSourceString(source) << ", " | 586 << "source " << GetNudgeSourceString(source) << ", " |
| 588 << "types " << ModelTypeSetToString(types); | 587 << "types " << ModelTypeSetToString(types); |
| 589 | 588 |
| 590 ModelTypePayloadMap types_with_payloads = | 589 ModelTypePayloadMap types_with_payloads = |
| 591 syncer::ModelTypePayloadMapFromEnumSet(types, std::string()); | 590 ModelTypePayloadMapFromEnumSet(types, std::string()); |
| 592 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 591 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 593 GetUpdatesFromNudgeSource(source), | 592 GetUpdatesFromNudgeSource(source), |
| 594 types_with_payloads, | 593 types_with_payloads, |
| 595 false, | 594 false, |
| 596 nudge_location); | 595 nudge_location); |
| 597 } | 596 } |
| 598 | 597 |
| 599 void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( | 598 void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( |
| 600 const TimeDelta& delay, | 599 const TimeDelta& delay, |
| 601 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, | 600 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, |
| 602 const tracked_objects::Location& nudge_location) { | 601 const tracked_objects::Location& nudge_location) { |
| 603 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 602 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 604 SDVLOG_LOC(nudge_location, 2) | 603 SDVLOG_LOC(nudge_location, 2) |
| 605 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 604 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 606 << "source " << GetNudgeSourceString(source) << ", " | 605 << "source " << GetNudgeSourceString(source) << ", " |
| 607 << "payloads " | 606 << "payloads " |
| 608 << syncer::ModelTypePayloadMapToString(types_with_payloads); | 607 << ModelTypePayloadMapToString(types_with_payloads); |
| 609 | 608 |
| 610 SyncSchedulerImpl::ScheduleNudgeImpl(delay, | 609 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 611 GetUpdatesFromNudgeSource(source), | 610 GetUpdatesFromNudgeSource(source), |
| 612 types_with_payloads, | 611 types_with_payloads, |
| 613 false, | 612 false, |
| 614 nudge_location); | 613 nudge_location); |
| 615 } | 614 } |
| 616 | 615 |
| 617 void SyncSchedulerImpl::ScheduleNudgeImpl( | 616 void SyncSchedulerImpl::ScheduleNudgeImpl( |
| 618 const TimeDelta& delay, | 617 const TimeDelta& delay, |
| 619 GetUpdatesCallerInfo::GetUpdatesSource source, | 618 GetUpdatesCallerInfo::GetUpdatesSource source, |
| 620 const ModelTypePayloadMap& types_with_payloads, | 619 const ModelTypePayloadMap& types_with_payloads, |
| 621 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 620 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
| 622 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 621 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 623 | 622 |
| 624 SDVLOG_LOC(nudge_location, 2) | 623 SDVLOG_LOC(nudge_location, 2) |
| 625 << "In ScheduleNudgeImpl with delay " | 624 << "In ScheduleNudgeImpl with delay " |
| 626 << delay.InMilliseconds() << " ms, " | 625 << delay.InMilliseconds() << " ms, " |
| 627 << "source " << GetUpdatesSourceString(source) << ", " | 626 << "source " << GetUpdatesSourceString(source) << ", " |
| 628 << "payloads " | 627 << "payloads " |
| 629 << syncer::ModelTypePayloadMapToString(types_with_payloads) | 628 << ModelTypePayloadMapToString(types_with_payloads) |
| 630 << (is_canary_job ? " (canary)" : ""); | 629 << (is_canary_job ? " (canary)" : ""); |
| 631 | 630 |
| 632 SyncSourceInfo info(source, types_with_payloads); | 631 SyncSourceInfo info(source, types_with_payloads); |
| 633 | 632 |
| 634 SyncSession* session(CreateSyncSession(info)); | 633 SyncSession* session(CreateSyncSession(info)); |
| 635 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 634 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
| 636 make_linked_ptr(session), is_canary_job, | 635 make_linked_ptr(session), is_canary_job, |
| 637 ConfigurationParams(), nudge_location); | 636 ConfigurationParams(), nudge_location); |
| 638 | 637 |
| 639 session = NULL; | 638 session = NULL; |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 | 1199 |
| 1201 #undef SDVLOG_LOC | 1200 #undef SDVLOG_LOC |
| 1202 | 1201 |
| 1203 #undef SDVLOG | 1202 #undef SDVLOG |
| 1204 | 1203 |
| 1205 #undef SLOG | 1204 #undef SLOG |
| 1206 | 1205 |
| 1207 #undef ENUM_CASE | 1206 #undef ENUM_CASE |
| 1208 | 1207 |
| 1209 } // namespace syncer | 1208 } // namespace syncer |
| OLD | NEW |