| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/sync_scheduler.h" | 5 #include "chrome/browser/sync/engine/sync_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 case NUDGE_SOURCE_CONTINUATION: | 97 case NUDGE_SOURCE_CONTINUATION: |
| 98 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | 98 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; |
| 99 case NUDGE_SOURCE_UNKNOWN: | 99 case NUDGE_SOURCE_UNKNOWN: |
| 100 return GetUpdatesCallerInfo::UNKNOWN; | 100 return GetUpdatesCallerInfo::UNKNOWN; |
| 101 default: | 101 default: |
| 102 NOTREACHED(); | 102 NOTREACHED(); |
| 103 return GetUpdatesCallerInfo::UNKNOWN; | 103 return GetUpdatesCallerInfo::UNKNOWN; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( | |
| 108 sync_api::ConfigureReason reason) { | |
| 109 switch (reason) { | |
| 110 case sync_api::CONFIGURE_REASON_RECONFIGURATION: | |
| 111 return GetUpdatesCallerInfo::RECONFIGURATION; | |
| 112 case sync_api::CONFIGURE_REASON_MIGRATION: | |
| 113 return GetUpdatesCallerInfo::MIGRATION; | |
| 114 case sync_api::CONFIGURE_REASON_NEW_CLIENT: | |
| 115 return GetUpdatesCallerInfo::NEW_CLIENT; | |
| 116 case sync_api::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: | |
| 117 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; | |
| 118 default: | |
| 119 NOTREACHED(); | |
| 120 } | |
| 121 | |
| 122 return GetUpdatesCallerInfo::UNKNOWN; | |
| 123 } | |
| 124 | |
| 125 SyncScheduler::WaitInterval::WaitInterval(Mode mode, TimeDelta length) | 107 SyncScheduler::WaitInterval::WaitInterval(Mode mode, TimeDelta length) |
| 126 : mode(mode), had_nudge(false), length(length) { } | 108 : mode(mode), had_nudge(false), length(length) { } |
| 127 | 109 |
| 128 // Helper macros to log with the syncer thread name; useful when there | 110 // Helper macros to log with the syncer thread name; useful when there |
| 129 // are multiple syncer threads involved. | 111 // are multiple syncer threads involved. |
| 130 | 112 |
| 131 #define SLOG(severity) LOG(severity) << name_ << ": " | 113 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 132 | 114 |
| 133 #define SVLOG(verbose_level) VLOG(verbose_level) << name_ << ": " | 115 #define SVLOG(verbose_level) VLOG(verbose_level) << name_ << ": " |
| 134 | 116 |
| 135 #define SVLOG_LOC(from_here, verbose_level) \ | 117 #define SVLOG_LOC(from_here, verbose_level) \ |
| 136 VLOG_LOC(from_here, verbose_level) << name_ << ": " | 118 VLOG_LOC(from_here, verbose_level) << name_ << ": " |
| 137 | 119 |
| 138 namespace { | 120 namespace { |
| 139 | 121 |
| 140 const int kDefaultSessionsCommitDelaySeconds = 10; | 122 const int kDefaultSessionsCommitDelaySeconds = 10; |
| 141 | 123 |
| 124 bool IsConfigRelatedUpdateSourceValue( |
| 125 GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 126 switch (source) { |
| 127 case GetUpdatesCallerInfo::RECONFIGURATION: |
| 128 case GetUpdatesCallerInfo::MIGRATION: |
| 129 case GetUpdatesCallerInfo::NEW_CLIENT: |
| 130 case GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE: |
| 131 return true; |
| 132 default: |
| 133 return false; |
| 134 } |
| 135 } |
| 136 |
| 142 } // namespace | 137 } // namespace |
| 143 | 138 |
| 144 SyncScheduler::SyncScheduler(const std::string& name, | 139 SyncScheduler::SyncScheduler(const std::string& name, |
| 145 sessions::SyncSessionContext* context, | 140 sessions::SyncSessionContext* context, |
| 146 Syncer* syncer) | 141 Syncer* syncer) |
| 147 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 142 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 148 name_(name), | 143 name_(name), |
| 149 sync_loop_(MessageLoop::current()), | 144 sync_loop_(MessageLoop::current()), |
| 150 started_(false), | 145 started_(false), |
| 151 syncer_short_poll_interval_seconds_( | 146 syncer_short_poll_interval_seconds_( |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 if (passive_group_added == false) { | 559 if (passive_group_added == false) { |
| 565 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), | 560 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), |
| 566 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); | 561 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); |
| 567 if (it != w_tmp.end()) | 562 if (it != w_tmp.end()) |
| 568 workers->push_back(*it); | 563 workers->push_back(*it); |
| 569 else | 564 else |
| 570 NOTREACHED(); | 565 NOTREACHED(); |
| 571 } | 566 } |
| 572 } | 567 } |
| 573 | 568 |
| 574 void SyncScheduler::ScheduleConfig(const ModelTypeBitSet& types, | 569 void SyncScheduler::ScheduleConfig( |
| 575 sync_api::ConfigureReason reason) { | 570 const ModelTypeBitSet& types, |
| 571 GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 576 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 572 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 573 DCHECK(IsConfigRelatedUpdateSourceValue(source)); |
| 577 SVLOG(2) << "Scheduling a config"; | 574 SVLOG(2) << "Scheduling a config"; |
| 578 ModelSafeRoutingInfo routes; | 575 ModelSafeRoutingInfo routes; |
| 579 std::vector<ModelSafeWorker*> workers; | 576 std::vector<ModelSafeWorker*> workers; |
| 580 GetModelSafeParamsForTypes(types, session_context_->registrar(), | 577 GetModelSafeParamsForTypes(types, session_context_->registrar(), |
| 581 &routes, &workers); | 578 &routes, &workers); |
| 582 | 579 |
| 583 PostTask(FROM_HERE, "ScheduleConfigImpl", | 580 PostTask(FROM_HERE, "ScheduleConfigImpl", |
| 584 method_factory_.NewRunnableMethod( | 581 method_factory_.NewRunnableMethod( |
| 585 &SyncScheduler::ScheduleConfigImpl, routes, workers, | 582 &SyncScheduler::ScheduleConfigImpl, routes, workers, source)); |
| 586 GetSourceFromReason(reason))); | |
| 587 } | 583 } |
| 588 | 584 |
| 589 void SyncScheduler::ScheduleConfigImpl( | 585 void SyncScheduler::ScheduleConfigImpl( |
| 590 const ModelSafeRoutingInfo& routing_info, | 586 const ModelSafeRoutingInfo& routing_info, |
| 591 const std::vector<ModelSafeWorker*>& workers, | 587 const std::vector<ModelSafeWorker*>& workers, |
| 592 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 588 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 593 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 589 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 594 | 590 |
| 595 SVLOG(2) << "In ScheduleConfigImpl"; | 591 SVLOG(2) << "In ScheduleConfigImpl"; |
| 596 // TODO(tim): config-specific GetUpdatesCallerInfo value? | 592 // TODO(tim): config-specific GetUpdatesCallerInfo value? |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 | 1101 |
| 1106 #undef SVLOG_LOC | 1102 #undef SVLOG_LOC |
| 1107 | 1103 |
| 1108 #undef SVLOG | 1104 #undef SVLOG |
| 1109 | 1105 |
| 1110 #undef SLOG | 1106 #undef SLOG |
| 1111 | 1107 |
| 1112 #undef ENUM_CASE | 1108 #undef ENUM_CASE |
| 1113 | 1109 |
| 1114 } // browser_sync | 1110 } // browser_sync |
| OLD | NEW |