| 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.h" | 5 #include "sync/engine/sync_scheduler.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(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(const SyncProtocolError& error) { |
| 63 const syncer::SyncProtocolError& error) { | 62 return (error.action != UNKNOWN_ACTION); |
| 64 return (error.action != syncer::UNKNOWN_ACTION); | |
| 65 } | 63 } |
| 66 } // namespace | 64 } // namespace |
| 67 | 65 |
| 68 ConfigurationParams::ConfigurationParams() | 66 ConfigurationParams::ConfigurationParams() |
| 69 : source(GetUpdatesCallerInfo::UNKNOWN), | 67 : source(GetUpdatesCallerInfo::UNKNOWN), |
| 70 keystore_key_status(KEYSTORE_KEY_UNNECESSARY) {} | 68 keystore_key_status(KEYSTORE_KEY_UNNECESSARY) {} |
| 71 ConfigurationParams::ConfigurationParams( | 69 ConfigurationParams::ConfigurationParams( |
| 72 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | 70 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, |
| 73 const syncer::ModelTypeSet& types_to_download, | 71 const ModelTypeSet& types_to_download, |
| 74 const syncer::ModelSafeRoutingInfo& routing_info, | 72 const ModelSafeRoutingInfo& routing_info, |
| 75 KeystoreKeyStatus keystore_key_status, | 73 KeystoreKeyStatus keystore_key_status, |
| 76 const base::Closure& ready_task) | 74 const base::Closure& ready_task) |
| 77 : source(source), | 75 : source(source), |
| 78 types_to_download(types_to_download), | 76 types_to_download(types_to_download), |
| 79 routing_info(routing_info), | 77 routing_info(routing_info), |
| 80 keystore_key_status(keystore_key_status), | 78 keystore_key_status(keystore_key_status), |
| 81 ready_task(ready_task) { | 79 ready_task(ready_task) { |
| 82 DCHECK(!ready_task.is_null()); | 80 DCHECK(!ready_task.is_null()); |
| 83 } | 81 } |
| 84 ConfigurationParams::~ConfigurationParams() {} | 82 ConfigurationParams::~ConfigurationParams() {} |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 void BuildModelSafeParams( | 305 void BuildModelSafeParams( |
| 308 const ModelTypeSet& types_to_download, | 306 const ModelTypeSet& types_to_download, |
| 309 const ModelSafeRoutingInfo& current_routes, | 307 const ModelSafeRoutingInfo& current_routes, |
| 310 const std::vector<ModelSafeWorker*>& current_workers, | 308 const std::vector<ModelSafeWorker*>& current_workers, |
| 311 ModelSafeRoutingInfo* result_routes, | 309 ModelSafeRoutingInfo* result_routes, |
| 312 std::vector<ModelSafeWorker*>* result_workers) { | 310 std::vector<ModelSafeWorker*>* result_workers) { |
| 313 std::set<ModelSafeGroup> active_groups; | 311 std::set<ModelSafeGroup> active_groups; |
| 314 active_groups.insert(GROUP_PASSIVE); | 312 active_groups.insert(GROUP_PASSIVE); |
| 315 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); | 313 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); |
| 316 iter.Inc()) { | 314 iter.Inc()) { |
| 317 syncer::ModelType type = iter.Get(); | 315 ModelType type = iter.Get(); |
| 318 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); | 316 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); |
| 319 DCHECK(route != current_routes.end()); | 317 DCHECK(route != current_routes.end()); |
| 320 ModelSafeGroup group = route->second; | 318 ModelSafeGroup group = route->second; |
| 321 (*result_routes)[type] = group; | 319 (*result_routes)[type] = group; |
| 322 active_groups.insert(group); | 320 active_groups.insert(group); |
| 323 } | 321 } |
| 324 | 322 |
| 325 for(std::vector<ModelSafeWorker*>::const_iterator iter = | 323 for(std::vector<ModelSafeWorker*>::const_iterator iter = |
| 326 current_workers.begin(); iter != current_workers.end(); ++iter) { | 324 current_workers.begin(); iter != current_workers.end(); ++iter) { |
| 327 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) | 325 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 338 DCHECK(!params.ready_task.is_null()); | 336 DCHECK(!params.ready_task.is_null()); |
| 339 SDVLOG(2) << "Reconfiguring syncer."; | 337 SDVLOG(2) << "Reconfiguring syncer."; |
| 340 | 338 |
| 341 // Only one configuration is allowed at a time. Verify we're not waiting | 339 // Only one configuration is allowed at a time. Verify we're not waiting |
| 342 // for a pending configure job. | 340 // for a pending configure job. |
| 343 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); | 341 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); |
| 344 | 342 |
| 345 // TODO(sync): now that ModelChanging commands only use those workers within | 343 // TODO(sync): now that ModelChanging commands only use those workers within |
| 346 // the routing info, we don't really need |restricted_workers|. Remove it. | 344 // the routing info, we don't really need |restricted_workers|. Remove it. |
| 347 // crbug.com/133030 | 345 // crbug.com/133030 |
| 348 syncer::ModelSafeRoutingInfo restricted_routes; | 346 ModelSafeRoutingInfo restricted_routes; |
| 349 std::vector<ModelSafeWorker*> restricted_workers; | 347 std::vector<ModelSafeWorker*> restricted_workers; |
| 350 BuildModelSafeParams(params.types_to_download, | 348 BuildModelSafeParams(params.types_to_download, |
| 351 params.routing_info, | 349 params.routing_info, |
| 352 session_context_->workers(), | 350 session_context_->workers(), |
| 353 &restricted_routes, | 351 &restricted_routes, |
| 354 &restricted_workers); | 352 &restricted_workers); |
| 355 session_context_->set_routing_info(params.routing_info); | 353 session_context_->set_routing_info(params.routing_info); |
| 356 | 354 |
| 357 // We rely on this not failing, so don't need to worry about checking for | 355 // 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. | 356 // success. In addition, this will be removed as part of crbug.com/131433. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return job.is_canary_job ? CONTINUE : SAVE; | 438 return job.is_canary_job ? CONTINUE : SAVE; |
| 441 } | 439 } |
| 442 | 440 |
| 443 SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( | 441 SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( |
| 444 const SyncSessionJob& job) { | 442 const SyncSessionJob& job) { |
| 445 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 443 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 446 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) | 444 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) |
| 447 return CONTINUE; | 445 return CONTINUE; |
| 448 | 446 |
| 449 // See if our type is throttled. | 447 // See if our type is throttled. |
| 450 syncer::ModelTypeSet throttled_types = | 448 ModelTypeSet throttled_types = |
| 451 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 449 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 452 if (job.purpose == SyncSessionJob::NUDGE && | 450 if (job.purpose == SyncSessionJob::NUDGE && |
| 453 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 451 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| 454 syncer::ModelTypeSet requested_types; | 452 ModelTypeSet requested_types; |
| 455 for (ModelTypePayloadMap::const_iterator i = | 453 for (ModelTypePayloadMap::const_iterator i = |
| 456 job.session->source().types.begin(); | 454 job.session->source().types.begin(); |
| 457 i != job.session->source().types.end(); | 455 i != job.session->source().types.end(); |
| 458 ++i) { | 456 ++i) { |
| 459 requested_types.Put(i->first); | 457 requested_types.Put(i->first); |
| 460 } | 458 } |
| 461 | 459 |
| 462 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) | 460 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) |
| 463 return SAVE; | 461 return SAVE; |
| 464 } | 462 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 const TimeDelta& delay, | 577 const TimeDelta& delay, |
| 580 NudgeSource source, ModelTypeSet types, | 578 NudgeSource source, ModelTypeSet types, |
| 581 const tracked_objects::Location& nudge_location) { | 579 const tracked_objects::Location& nudge_location) { |
| 582 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 580 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 583 SDVLOG_LOC(nudge_location, 2) | 581 SDVLOG_LOC(nudge_location, 2) |
| 584 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 582 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 585 << "source " << GetNudgeSourceString(source) << ", " | 583 << "source " << GetNudgeSourceString(source) << ", " |
| 586 << "types " << ModelTypeSetToString(types); | 584 << "types " << ModelTypeSetToString(types); |
| 587 | 585 |
| 588 ModelTypePayloadMap types_with_payloads = | 586 ModelTypePayloadMap types_with_payloads = |
| 589 syncer::ModelTypePayloadMapFromEnumSet(types, std::string()); | 587 ModelTypePayloadMapFromEnumSet(types, std::string()); |
| 590 SyncScheduler::ScheduleNudgeImpl(delay, | 588 SyncScheduler::ScheduleNudgeImpl(delay, |
| 591 GetUpdatesFromNudgeSource(source), | 589 GetUpdatesFromNudgeSource(source), |
| 592 types_with_payloads, | 590 types_with_payloads, |
| 593 false, | 591 false, |
| 594 nudge_location); | 592 nudge_location); |
| 595 } | 593 } |
| 596 | 594 |
| 597 void SyncScheduler::ScheduleNudgeWithPayloadsAsync( | 595 void SyncScheduler::ScheduleNudgeWithPayloadsAsync( |
| 598 const TimeDelta& delay, | 596 const TimeDelta& delay, |
| 599 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, | 597 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, |
| 600 const tracked_objects::Location& nudge_location) { | 598 const tracked_objects::Location& nudge_location) { |
| 601 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 599 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 602 SDVLOG_LOC(nudge_location, 2) | 600 SDVLOG_LOC(nudge_location, 2) |
| 603 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 601 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 604 << "source " << GetNudgeSourceString(source) << ", " | 602 << "source " << GetNudgeSourceString(source) << ", " |
| 605 << "payloads " | 603 << "payloads " |
| 606 << syncer::ModelTypePayloadMapToString(types_with_payloads); | 604 << ModelTypePayloadMapToString(types_with_payloads); |
| 607 | 605 |
| 608 SyncScheduler::ScheduleNudgeImpl(delay, | 606 SyncScheduler::ScheduleNudgeImpl(delay, |
| 609 GetUpdatesFromNudgeSource(source), | 607 GetUpdatesFromNudgeSource(source), |
| 610 types_with_payloads, | 608 types_with_payloads, |
| 611 false, | 609 false, |
| 612 nudge_location); | 610 nudge_location); |
| 613 } | 611 } |
| 614 | 612 |
| 615 void SyncScheduler::ScheduleNudgeImpl( | 613 void SyncScheduler::ScheduleNudgeImpl( |
| 616 const TimeDelta& delay, | 614 const TimeDelta& delay, |
| 617 GetUpdatesCallerInfo::GetUpdatesSource source, | 615 GetUpdatesCallerInfo::GetUpdatesSource source, |
| 618 const ModelTypePayloadMap& types_with_payloads, | 616 const ModelTypePayloadMap& types_with_payloads, |
| 619 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 617 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
| 620 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 618 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 621 | 619 |
| 622 SDVLOG_LOC(nudge_location, 2) | 620 SDVLOG_LOC(nudge_location, 2) |
| 623 << "In ScheduleNudgeImpl with delay " | 621 << "In ScheduleNudgeImpl with delay " |
| 624 << delay.InMilliseconds() << " ms, " | 622 << delay.InMilliseconds() << " ms, " |
| 625 << "source " << GetUpdatesSourceString(source) << ", " | 623 << "source " << GetUpdatesSourceString(source) << ", " |
| 626 << "payloads " | 624 << "payloads " |
| 627 << syncer::ModelTypePayloadMapToString(types_with_payloads) | 625 << ModelTypePayloadMapToString(types_with_payloads) |
| 628 << (is_canary_job ? " (canary)" : ""); | 626 << (is_canary_job ? " (canary)" : ""); |
| 629 | 627 |
| 630 SyncSourceInfo info(source, types_with_payloads); | 628 SyncSourceInfo info(source, types_with_payloads); |
| 631 | 629 |
| 632 SyncSession* session(CreateSyncSession(info)); | 630 SyncSession* session(CreateSyncSession(info)); |
| 633 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 631 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
| 634 make_linked_ptr(session), is_canary_job, | 632 make_linked_ptr(session), is_canary_job, |
| 635 ConfigurationParams(), nudge_location); | 633 ConfigurationParams(), nudge_location); |
| 636 | 634 |
| 637 session = NULL; | 635 session = NULL; |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 | 1193 |
| 1196 #undef SDVLOG_LOC | 1194 #undef SDVLOG_LOC |
| 1197 | 1195 |
| 1198 #undef SDVLOG | 1196 #undef SDVLOG |
| 1199 | 1197 |
| 1200 #undef SLOG | 1198 #undef SLOG |
| 1201 | 1199 |
| 1202 #undef ENUM_CASE | 1200 #undef ENUM_CASE |
| 1203 | 1201 |
| 1204 } // namespace syncer | 1202 } // namespace syncer |
| OLD | NEW |