| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sync/driver/data_type_manager_impl.h" | 5 #include "components/sync/driver/data_type_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "components/sync/core/data_type_debug_info_listener.h" | 19 #include "components/sync/core/data_type_debug_info_listener.h" |
| 20 #include "components/sync/driver/data_type_encryption_handler.h" | 20 #include "components/sync/driver/data_type_encryption_handler.h" |
| 21 #include "components/sync/driver/data_type_manager_observer.h" | 21 #include "components/sync/driver/data_type_manager_observer.h" |
| 22 #include "components/sync/driver/data_type_status_table.h" | 22 #include "components/sync/driver/data_type_status_table.h" |
| 23 | 23 |
| 24 namespace syncer { | 24 using syncer::ModelTypeSet; |
| 25 |
| 26 namespace sync_driver { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 DataTypeStatusTable::TypeErrorMap GenerateCryptoErrorsForTypes( | 30 DataTypeStatusTable::TypeErrorMap GenerateCryptoErrorsForTypes( |
| 29 ModelTypeSet encrypted_types) { | 31 ModelTypeSet encrypted_types) { |
| 30 DataTypeStatusTable::TypeErrorMap crypto_errors; | 32 DataTypeStatusTable::TypeErrorMap crypto_errors; |
| 31 for (ModelTypeSet::Iterator iter = encrypted_types.First(); iter.Good(); | 33 for (ModelTypeSet::Iterator iter = encrypted_types.First(); iter.Good(); |
| 32 iter.Inc()) { | 34 iter.Inc()) { |
| 33 crypto_errors[iter.Get()] = | 35 crypto_errors[iter.Get()] = syncer::SyncError( |
| 34 SyncError(FROM_HERE, SyncError::CRYPTO_ERROR, "", iter.Get()); | 36 FROM_HERE, syncer::SyncError::CRYPTO_ERROR, "", iter.Get()); |
| 35 } | 37 } |
| 36 return crypto_errors; | 38 return crypto_errors; |
| 37 } | 39 } |
| 38 | 40 |
| 39 } // namespace | 41 } // namespace |
| 40 | 42 |
| 41 DataTypeManagerImpl::AssociationTypesInfo::AssociationTypesInfo() {} | 43 DataTypeManagerImpl::AssociationTypesInfo::AssociationTypesInfo() {} |
| 42 DataTypeManagerImpl::AssociationTypesInfo::AssociationTypesInfo( | 44 DataTypeManagerImpl::AssociationTypesInfo::AssociationTypesInfo( |
| 43 const AssociationTypesInfo& other) = default; | 45 const AssociationTypesInfo& other) = default; |
| 44 DataTypeManagerImpl::AssociationTypesInfo::~AssociationTypesInfo() {} | 46 DataTypeManagerImpl::AssociationTypesInfo::~AssociationTypesInfo() {} |
| 45 | 47 |
| 46 DataTypeManagerImpl::DataTypeManagerImpl( | 48 DataTypeManagerImpl::DataTypeManagerImpl( |
| 47 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, | 49 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 50 debug_info_listener, |
| 48 const DataTypeController::TypeMap* controllers, | 51 const DataTypeController::TypeMap* controllers, |
| 49 const DataTypeEncryptionHandler* encryption_handler, | 52 const DataTypeEncryptionHandler* encryption_handler, |
| 50 BackendDataTypeConfigurer* configurer, | 53 BackendDataTypeConfigurer* configurer, |
| 51 DataTypeManagerObserver* observer) | 54 DataTypeManagerObserver* observer) |
| 52 : configurer_(configurer), | 55 : configurer_(configurer), |
| 53 controllers_(controllers), | 56 controllers_(controllers), |
| 54 state_(DataTypeManager::STOPPED), | 57 state_(DataTypeManager::STOPPED), |
| 55 needs_reconfigure_(false), | 58 needs_reconfigure_(false), |
| 56 last_configure_reason_(CONFIGURE_REASON_UNKNOWN), | 59 last_configure_reason_(syncer::CONFIGURE_REASON_UNKNOWN), |
| 57 debug_info_listener_(debug_info_listener), | 60 debug_info_listener_(debug_info_listener), |
| 58 model_association_manager_(controllers, this), | 61 model_association_manager_(controllers, this), |
| 59 observer_(observer), | 62 observer_(observer), |
| 60 encryption_handler_(encryption_handler), | 63 encryption_handler_(encryption_handler), |
| 61 catch_up_in_progress_(false), | 64 catch_up_in_progress_(false), |
| 62 download_started_(false), | 65 download_started_(false), |
| 63 weak_ptr_factory_(this) { | 66 weak_ptr_factory_(this) { |
| 64 DCHECK(configurer_); | 67 DCHECK(configurer_); |
| 65 DCHECK(observer_); | 68 DCHECK(observer_); |
| 66 } | 69 } |
| 67 | 70 |
| 68 DataTypeManagerImpl::~DataTypeManagerImpl() {} | 71 DataTypeManagerImpl::~DataTypeManagerImpl() {} |
| 69 | 72 |
| 70 void DataTypeManagerImpl::Configure(ModelTypeSet desired_types, | 73 void DataTypeManagerImpl::Configure(ModelTypeSet desired_types, |
| 71 ConfigureReason reason) { | 74 syncer::ConfigureReason reason) { |
| 72 // Once requested, we will remain in "catch up" mode until we notify the | 75 // Once requested, we will remain in "catch up" mode until we notify the |
| 73 // caller (see NotifyDone). We do this to ensure that once started, subsequent | 76 // caller (see NotifyDone). We do this to ensure that once started, subsequent |
| 74 // calls to Configure won't take us out of "catch up" mode. | 77 // calls to Configure won't take us out of "catch up" mode. |
| 75 if (reason == CONFIGURE_REASON_CATCH_UP) | 78 if (reason == syncer::CONFIGURE_REASON_CATCH_UP) |
| 76 catch_up_in_progress_ = true; | 79 catch_up_in_progress_ = true; |
| 77 | 80 |
| 78 desired_types.PutAll(CoreTypes()); | 81 desired_types.PutAll(syncer::CoreTypes()); |
| 79 | 82 |
| 80 // Only allow control types and types that have controllers. | 83 // Only allow control types and types that have controllers. |
| 81 ModelTypeSet filtered_desired_types; | 84 ModelTypeSet filtered_desired_types; |
| 82 for (ModelTypeSet::Iterator type = desired_types.First(); type.Good(); | 85 for (ModelTypeSet::Iterator type = desired_types.First(); type.Good(); |
| 83 type.Inc()) { | 86 type.Inc()) { |
| 84 DataTypeController::TypeMap::const_iterator iter = | 87 DataTypeController::TypeMap::const_iterator iter = |
| 85 controllers_->find(type.Get()); | 88 controllers_->find(type.Get()); |
| 86 if (IsControlType(type.Get()) || iter != controllers_->end()) { | 89 if (syncer::IsControlType(type.Get()) || iter != controllers_->end()) { |
| 87 if (iter != controllers_->end()) { | 90 if (iter != controllers_->end()) { |
| 88 if (!iter->second->ReadyForStart() && | 91 if (!iter->second->ReadyForStart() && |
| 89 !data_type_status_table_.GetUnreadyErrorTypes().Has(type.Get())) { | 92 !data_type_status_table_.GetUnreadyErrorTypes().Has(type.Get())) { |
| 90 // Add the type to the unready types set to prevent purging it. It's | 93 // Add the type to the unready types set to prevent purging it. It's |
| 91 // up to the datatype controller to, if necessary, explicitly | 94 // up to the datatype controller to, if necessary, explicitly |
| 92 // mark the type as broken to trigger a purge. | 95 // mark the type as broken to trigger a purge. |
| 93 SyncError error(FROM_HERE, SyncError::UNREADY_ERROR, | 96 syncer::SyncError error(FROM_HERE, syncer::SyncError::UNREADY_ERROR, |
| 94 "Datatype not ready at config time.", type.Get()); | 97 "Datatype not ready at config time.", |
| 95 std::map<ModelType, SyncError> errors; | 98 type.Get()); |
| 99 std::map<syncer::ModelType, syncer::SyncError> errors; |
| 96 errors[type.Get()] = error; | 100 errors[type.Get()] = error; |
| 97 data_type_status_table_.UpdateFailedDataTypes(errors); | 101 data_type_status_table_.UpdateFailedDataTypes(errors); |
| 98 } else if (iter->second->ReadyForStart()) { | 102 } else if (iter->second->ReadyForStart()) { |
| 99 data_type_status_table_.ResetUnreadyErrorFor(type.Get()); | 103 data_type_status_table_.ResetUnreadyErrorFor(type.Get()); |
| 100 } | 104 } |
| 101 } | 105 } |
| 102 filtered_desired_types.Put(type.Get()); | 106 filtered_desired_types.Put(type.Get()); |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 ConfigureImpl(filtered_desired_types, reason); | 109 ConfigureImpl(filtered_desired_types, reason); |
| 106 } | 110 } |
| 107 | 111 |
| 108 void DataTypeManagerImpl::ReenableType(ModelType type) { | 112 void DataTypeManagerImpl::ReenableType(syncer::ModelType type) { |
| 109 // TODO(zea): move the "should we reconfigure" logic into the datatype handler | 113 // TODO(zea): move the "should we reconfigure" logic into the datatype handler |
| 110 // itself. | 114 // itself. |
| 111 // Only reconfigure if the type actually had a data type or unready error. | 115 // Only reconfigure if the type actually had a data type or unready error. |
| 112 if (!data_type_status_table_.ResetDataTypeErrorFor(type) && | 116 if (!data_type_status_table_.ResetDataTypeErrorFor(type) && |
| 113 !data_type_status_table_.ResetUnreadyErrorFor(type)) { | 117 !data_type_status_table_.ResetUnreadyErrorFor(type)) { |
| 114 return; | 118 return; |
| 115 } | 119 } |
| 116 | 120 |
| 117 // Only reconfigure if the type is actually desired. | 121 // Only reconfigure if the type is actually desired. |
| 118 if (!last_requested_types_.Has(type)) | 122 if (!last_requested_types_.Has(type)) |
| 119 return; | 123 return; |
| 120 | 124 |
| 121 DVLOG(1) << "Reenabling " << ModelTypeToString(type); | 125 DVLOG(1) << "Reenabling " << syncer::ModelTypeToString(type); |
| 122 needs_reconfigure_ = true; | 126 needs_reconfigure_ = true; |
| 123 last_configure_reason_ = CONFIGURE_REASON_PROGRAMMATIC; | 127 last_configure_reason_ = syncer::CONFIGURE_REASON_PROGRAMMATIC; |
| 124 ProcessReconfigure(); | 128 ProcessReconfigure(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 void DataTypeManagerImpl::ResetDataTypeErrors() { | 131 void DataTypeManagerImpl::ResetDataTypeErrors() { |
| 128 data_type_status_table_.Reset(); | 132 data_type_status_table_.Reset(); |
| 129 } | 133 } |
| 130 | 134 |
| 131 void DataTypeManagerImpl::PurgeForMigration(ModelTypeSet undesired_types, | 135 void DataTypeManagerImpl::PurgeForMigration(ModelTypeSet undesired_types, |
| 132 ConfigureReason reason) { | 136 syncer::ConfigureReason reason) { |
| 133 ModelTypeSet remainder = Difference(last_requested_types_, undesired_types); | 137 ModelTypeSet remainder = Difference(last_requested_types_, undesired_types); |
| 134 ConfigureImpl(remainder, reason); | 138 ConfigureImpl(remainder, reason); |
| 135 } | 139 } |
| 136 | 140 |
| 137 void DataTypeManagerImpl::ConfigureImpl(ModelTypeSet desired_types, | 141 void DataTypeManagerImpl::ConfigureImpl(ModelTypeSet desired_types, |
| 138 ConfigureReason reason) { | 142 syncer::ConfigureReason reason) { |
| 139 DCHECK_NE(reason, CONFIGURE_REASON_UNKNOWN); | 143 DCHECK_NE(reason, syncer::CONFIGURE_REASON_UNKNOWN); |
| 140 DVLOG(1) << "Configuring for " << ModelTypeSetToString(desired_types) | 144 DVLOG(1) << "Configuring for " << ModelTypeSetToString(desired_types) |
| 141 << " with reason " << reason; | 145 << " with reason " << reason; |
| 142 if (state_ == STOPPING) { | 146 if (state_ == STOPPING) { |
| 143 // You can not set a configuration while stopping. | 147 // You can not set a configuration while stopping. |
| 144 LOG(ERROR) << "Configuration set while stopping."; | 148 LOG(ERROR) << "Configuration set while stopping."; |
| 145 return; | 149 return; |
| 146 } | 150 } |
| 147 | 151 |
| 148 // TODO(zea): consider not performing a full configuration once there's a | 152 // TODO(zea): consider not performing a full configuration once there's a |
| 149 // reliable way to determine if the requested set of enabled types matches the | 153 // reliable way to determine if the requested set of enabled types matches the |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // Types with unready errors do not count as unready if they've been disabled. | 197 // Types with unready errors do not count as unready if they've been disabled. |
| 194 unready_types.RetainAll(last_requested_types_); | 198 unready_types.RetainAll(last_requested_types_); |
| 195 | 199 |
| 196 ModelTypeSet enabled_types = GetEnabledTypes(); | 200 ModelTypeSet enabled_types = GetEnabledTypes(); |
| 197 | 201 |
| 198 // If we're catching up, add all enabled (non-error) types to the clean set to | 202 // If we're catching up, add all enabled (non-error) types to the clean set to |
| 199 // ensure we download and apply them to the model types. | 203 // ensure we download and apply them to the model types. |
| 200 if (catch_up_in_progress_) | 204 if (catch_up_in_progress_) |
| 201 clean_types.PutAll(enabled_types); | 205 clean_types.PutAll(enabled_types); |
| 202 | 206 |
| 203 ModelTypeSet disabled_types = | 207 ModelTypeSet disabled_types = syncer::Difference( |
| 204 Difference(Union(UserTypes(), ControlTypes()), enabled_types); | 208 syncer::Union(syncer::UserTypes(), syncer::ControlTypes()), |
| 209 enabled_types); |
| 205 ModelTypeSet to_configure = | 210 ModelTypeSet to_configure = |
| 206 Intersection(enabled_types, types_being_configured); | 211 syncer::Intersection(enabled_types, types_being_configured); |
| 207 DVLOG(1) << "Enabling: " << ModelTypeSetToString(enabled_types); | 212 DVLOG(1) << "Enabling: " << ModelTypeSetToString(enabled_types); |
| 208 DVLOG(1) << "Configuring: " << ModelTypeSetToString(to_configure); | 213 DVLOG(1) << "Configuring: " << ModelTypeSetToString(to_configure); |
| 209 DVLOG(1) << "Disabling: " << ModelTypeSetToString(disabled_types); | 214 DVLOG(1) << "Disabling: " << ModelTypeSetToString(disabled_types); |
| 210 | 215 |
| 211 BackendDataTypeConfigurer::DataTypeConfigStateMap config_state_map; | 216 BackendDataTypeConfigurer::DataTypeConfigStateMap config_state_map; |
| 212 BackendDataTypeConfigurer::SetDataTypesState( | 217 BackendDataTypeConfigurer::SetDataTypesState( |
| 213 BackendDataTypeConfigurer::CONFIGURE_INACTIVE, enabled_types, | 218 BackendDataTypeConfigurer::CONFIGURE_INACTIVE, enabled_types, |
| 214 &config_state_map); | 219 &config_state_map); |
| 215 BackendDataTypeConfigurer::SetDataTypesState( | 220 BackendDataTypeConfigurer::SetDataTypesState( |
| 216 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, to_configure, | 221 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, to_configure, |
| 217 &config_state_map); | 222 &config_state_map); |
| 218 BackendDataTypeConfigurer::SetDataTypesState( | 223 BackendDataTypeConfigurer::SetDataTypesState( |
| 219 BackendDataTypeConfigurer::CONFIGURE_CLEAN, clean_types, | 224 BackendDataTypeConfigurer::CONFIGURE_CLEAN, clean_types, |
| 220 &config_state_map); | 225 &config_state_map); |
| 221 BackendDataTypeConfigurer::SetDataTypesState( | 226 BackendDataTypeConfigurer::SetDataTypesState( |
| 222 BackendDataTypeConfigurer::DISABLED, disabled_types, &config_state_map); | 227 BackendDataTypeConfigurer::DISABLED, disabled_types, &config_state_map); |
| 223 BackendDataTypeConfigurer::SetDataTypesState(BackendDataTypeConfigurer::FATAL, | 228 BackendDataTypeConfigurer::SetDataTypesState(BackendDataTypeConfigurer::FATAL, |
| 224 fatal_types, &config_state_map); | 229 fatal_types, &config_state_map); |
| 225 BackendDataTypeConfigurer::SetDataTypesState( | 230 BackendDataTypeConfigurer::SetDataTypesState( |
| 226 BackendDataTypeConfigurer::CRYPTO, crypto_types, &config_state_map); | 231 BackendDataTypeConfigurer::CRYPTO, crypto_types, &config_state_map); |
| 227 BackendDataTypeConfigurer::SetDataTypesState( | 232 BackendDataTypeConfigurer::SetDataTypesState( |
| 228 BackendDataTypeConfigurer::UNREADY, unready_types, &config_state_map); | 233 BackendDataTypeConfigurer::UNREADY, unready_types, &config_state_map); |
| 229 return config_state_map; | 234 return config_state_map; |
| 230 } | 235 } |
| 231 | 236 |
| 232 void DataTypeManagerImpl::Restart(ConfigureReason reason) { | 237 void DataTypeManagerImpl::Restart(syncer::ConfigureReason reason) { |
| 233 DVLOG(1) << "Restarting..."; | 238 DVLOG(1) << "Restarting..."; |
| 234 | 239 |
| 235 // Only record the type histograms for user-triggered configurations or | 240 // Only record the type histograms for user-triggered configurations or |
| 236 // restarts. | 241 // restarts. |
| 237 if (reason == CONFIGURE_REASON_RECONFIGURATION || | 242 if (reason == syncer::CONFIGURE_REASON_RECONFIGURATION || |
| 238 reason == CONFIGURE_REASON_NEW_CLIENT || | 243 reason == syncer::CONFIGURE_REASON_NEW_CLIENT || |
| 239 reason == CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE) { | 244 reason == syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE) { |
| 240 for (ModelTypeSet::Iterator iter = last_requested_types_.First(); | 245 for (ModelTypeSet::Iterator iter = last_requested_types_.First(); |
| 241 iter.Good(); iter.Inc()) { | 246 iter.Good(); iter.Inc()) { |
| 242 UMA_HISTOGRAM_ENUMERATION("Sync.ConfigureDataTypes", | 247 UMA_HISTOGRAM_ENUMERATION("Sync.ConfigureDataTypes", |
| 243 ModelTypeToHistogramInt(iter.Get()), | 248 syncer::ModelTypeToHistogramInt(iter.Get()), |
| 244 MODEL_TYPE_COUNT); | 249 syncer::MODEL_TYPE_COUNT); |
| 245 } | 250 } |
| 246 } | 251 } |
| 247 | 252 |
| 248 // Check for new or resolved data type crypto errors. | 253 // Check for new or resolved data type crypto errors. |
| 249 if (encryption_handler_->IsPassphraseRequired()) { | 254 if (encryption_handler_->IsPassphraseRequired()) { |
| 250 ModelTypeSet encrypted_types = encryption_handler_->GetEncryptedDataTypes(); | 255 ModelTypeSet encrypted_types = encryption_handler_->GetEncryptedDataTypes(); |
| 251 encrypted_types.RetainAll(last_requested_types_); | 256 encrypted_types.RetainAll(last_requested_types_); |
| 252 encrypted_types.RemoveAll(data_type_status_table_.GetCryptoErrorTypes()); | 257 encrypted_types.RemoveAll(data_type_status_table_.GetCryptoErrorTypes()); |
| 253 DataTypeStatusTable::TypeErrorMap crypto_errors = | 258 DataTypeStatusTable::TypeErrorMap crypto_errors = |
| 254 GenerateCryptoErrorsForTypes(encrypted_types); | 259 GenerateCryptoErrorsForTypes(encrypted_types); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 base::Time::Now() - last_restart_time_); | 297 base::Time::Now() - last_restart_time_); |
| 293 // TODO(pavely): By now some of datatypes in |download_types_queue_| could | 298 // TODO(pavely): By now some of datatypes in |download_types_queue_| could |
| 294 // have failed loading and should be excluded from configuration. I need to | 299 // have failed loading and should be excluded from configuration. I need to |
| 295 // adjust |download_types_queue_| for such types. | 300 // adjust |download_types_queue_| for such types. |
| 296 RegisterTypesWithBackend(); | 301 RegisterTypesWithBackend(); |
| 297 StartNextDownload(ModelTypeSet()); | 302 StartNextDownload(ModelTypeSet()); |
| 298 } | 303 } |
| 299 | 304 |
| 300 ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const { | 305 ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const { |
| 301 ModelTypeSet high_priority_types; | 306 ModelTypeSet high_priority_types; |
| 302 high_priority_types.PutAll(PriorityCoreTypes()); | 307 high_priority_types.PutAll(syncer::PriorityCoreTypes()); |
| 303 high_priority_types.PutAll(PriorityUserTypes()); | 308 high_priority_types.PutAll(syncer::PriorityUserTypes()); |
| 304 return high_priority_types; | 309 return high_priority_types; |
| 305 } | 310 } |
| 306 | 311 |
| 307 TypeSetPriorityList DataTypeManagerImpl::PrioritizeTypes( | 312 TypeSetPriorityList DataTypeManagerImpl::PrioritizeTypes( |
| 308 const ModelTypeSet& types) { | 313 const ModelTypeSet& types) { |
| 309 ModelTypeSet high_priority_types = GetPriorityTypes(); | 314 ModelTypeSet high_priority_types = GetPriorityTypes(); |
| 310 high_priority_types.RetainAll(types); | 315 high_priority_types.RetainAll(types); |
| 311 | 316 |
| 312 ModelTypeSet low_priority_types = Difference(types, high_priority_types); | 317 ModelTypeSet low_priority_types = |
| 318 syncer::Difference(types, high_priority_types); |
| 313 | 319 |
| 314 TypeSetPriorityList result; | 320 TypeSetPriorityList result; |
| 315 if (!high_priority_types.Empty()) | 321 if (!high_priority_types.Empty()) |
| 316 result.push(high_priority_types); | 322 result.push(high_priority_types); |
| 317 if (!low_priority_types.Empty()) | 323 if (!low_priority_types.Empty()) |
| 318 result.push(low_priority_types); | 324 result.push(low_priority_types); |
| 319 | 325 |
| 320 // Could be empty in case of purging for migration, sync nothing, etc. | 326 // Could be empty in case of purging for migration, sync nothing, etc. |
| 321 // Configure empty set to purge data from backend. | 327 // Configure empty set to purge data from backend. |
| 322 if (result.empty()) | 328 if (result.empty()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 DCHECK_EQ(CONFIGURING, state_); | 376 DCHECK_EQ(CONFIGURING, state_); |
| 371 | 377 |
| 372 // Persistence errors are reset after each backend configuration attempt | 378 // Persistence errors are reset after each backend configuration attempt |
| 373 // during which they would have been purged. | 379 // during which they would have been purged. |
| 374 data_type_status_table_.ResetPersistenceErrorsFrom(types_to_download); | 380 data_type_status_table_.ResetPersistenceErrorsFrom(types_to_download); |
| 375 | 381 |
| 376 if (!failed_configuration_types.Empty()) { | 382 if (!failed_configuration_types.Empty()) { |
| 377 DataTypeStatusTable::TypeErrorMap errors; | 383 DataTypeStatusTable::TypeErrorMap errors; |
| 378 for (ModelTypeSet::Iterator iter = failed_configuration_types.First(); | 384 for (ModelTypeSet::Iterator iter = failed_configuration_types.First(); |
| 379 iter.Good(); iter.Inc()) { | 385 iter.Good(); iter.Inc()) { |
| 380 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, | 386 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, |
| 381 "Backend failed to download type.", iter.Get()); | 387 "Backend failed to download type.", iter.Get()); |
| 382 errors[iter.Get()] = error; | 388 errors[iter.Get()] = error; |
| 383 } | 389 } |
| 384 data_type_status_table_.UpdateFailedDataTypes(errors); | 390 data_type_status_table_.UpdateFailedDataTypes(errors); |
| 385 needs_reconfigure_ = true; | 391 needs_reconfigure_ = true; |
| 386 } | 392 } |
| 387 | 393 |
| 388 if (needs_reconfigure_) { | 394 if (needs_reconfigure_) { |
| 389 download_types_queue_ = TypeSetPriorityList(); | 395 download_types_queue_ = TypeSetPriorityList(); |
| 390 ProcessReconfigure(); | 396 ProcessReconfigure(); |
| 391 return; | 397 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 // We request the full set of types here for completeness sake. All types | 477 // We request the full set of types here for completeness sake. All types |
| 472 // within the READY_AT_CONFIG set will already be started and should be | 478 // within the READY_AT_CONFIG set will already be started and should be |
| 473 // no-ops. | 479 // no-ops. |
| 474 types_to_associate = association_types_queue_.front().types; | 480 types_to_associate = association_types_queue_.front().types; |
| 475 } | 481 } |
| 476 | 482 |
| 477 DVLOG(1) << "Associating " << ModelTypeSetToString(types_to_associate); | 483 DVLOG(1) << "Associating " << ModelTypeSetToString(types_to_associate); |
| 478 model_association_manager_.StartAssociationAsync(types_to_associate); | 484 model_association_manager_.StartAssociationAsync(types_to_associate); |
| 479 } | 485 } |
| 480 | 486 |
| 481 void DataTypeManagerImpl::OnSingleDataTypeWillStop(ModelType type, | 487 void DataTypeManagerImpl::OnSingleDataTypeWillStop( |
| 482 const SyncError& error) { | 488 syncer::ModelType type, |
| 489 const syncer::SyncError& error) { |
| 483 DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type); | 490 DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type); |
| 484 DCHECK(c_it != controllers_->end()); | 491 DCHECK(c_it != controllers_->end()); |
| 485 // Delegate deactivation to the controller. | 492 // Delegate deactivation to the controller. |
| 486 c_it->second->DeactivateDataType(configurer_); | 493 c_it->second->DeactivateDataType(configurer_); |
| 487 | 494 |
| 488 if (error.IsSet()) { | 495 if (error.IsSet()) { |
| 489 DataTypeStatusTable::TypeErrorMap failed_types; | 496 DataTypeStatusTable::TypeErrorMap failed_types; |
| 490 failed_types[type] = error; | 497 failed_types[type] = error; |
| 491 data_type_status_table_.UpdateFailedDataTypes(failed_types); | 498 data_type_status_table_.UpdateFailedDataTypes(failed_types); |
| 492 | 499 |
| 493 // Unrecoverable errors will shut down the entire backend, so no need to | 500 // Unrecoverable errors will shut down the entire backend, so no need to |
| 494 // reconfigure. | 501 // reconfigure. |
| 495 if (error.error_type() != SyncError::UNRECOVERABLE_ERROR) { | 502 if (error.error_type() != syncer::SyncError::UNRECOVERABLE_ERROR) { |
| 496 needs_reconfigure_ = true; | 503 needs_reconfigure_ = true; |
| 497 last_configure_reason_ = CONFIGURE_REASON_PROGRAMMATIC; | 504 last_configure_reason_ = syncer::CONFIGURE_REASON_PROGRAMMATIC; |
| 498 // Do this asynchronously so the ModelAssociationManager has a chance to | 505 // Do this asynchronously so the ModelAssociationManager has a chance to |
| 499 // finish stopping this type, otherwise DeactivateDataType() and Stop() | 506 // finish stopping this type, otherwise DeactivateDataType() and Stop() |
| 500 // end up getting called twice on the controller. | 507 // end up getting called twice on the controller. |
| 501 base::ThreadTaskRunnerHandle::Get()->PostTask( | 508 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 502 FROM_HERE, base::Bind(&DataTypeManagerImpl::ProcessReconfigure, | 509 FROM_HERE, base::Bind(&DataTypeManagerImpl::ProcessReconfigure, |
| 503 weak_ptr_factory_.GetWeakPtr())); | 510 weak_ptr_factory_.GetWeakPtr())); |
| 504 } | 511 } |
| 505 } | 512 } |
| 506 } | 513 } |
| 507 | 514 |
| 508 void DataTypeManagerImpl::OnSingleDataTypeAssociationDone( | 515 void DataTypeManagerImpl::OnSingleDataTypeAssociationDone( |
| 509 ModelType type, | 516 syncer::ModelType type, |
| 510 const DataTypeAssociationStats& association_stats) { | 517 const syncer::DataTypeAssociationStats& association_stats) { |
| 511 DCHECK(!association_types_queue_.empty()); | 518 DCHECK(!association_types_queue_.empty()); |
| 512 DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type); | 519 DataTypeController::TypeMap::const_iterator c_it = controllers_->find(type); |
| 513 DCHECK(c_it != controllers_->end()); | 520 DCHECK(c_it != controllers_->end()); |
| 514 if (c_it->second->state() == DataTypeController::RUNNING) { | 521 if (c_it->second->state() == DataTypeController::RUNNING) { |
| 515 // Delegate activation to the controller. | 522 // Delegate activation to the controller. |
| 516 c_it->second->ActivateDataType(configurer_); | 523 c_it->second->ActivateDataType(configurer_); |
| 517 } | 524 } |
| 518 | 525 |
| 519 if (!debug_info_listener_.IsInitialized()) | 526 if (!debug_info_listener_.IsInitialized()) |
| 520 return; | 527 return; |
| 521 | 528 |
| 522 AssociationTypesInfo& info = association_types_queue_.front(); | 529 AssociationTypesInfo& info = association_types_queue_.front(); |
| 523 configuration_stats_.push_back(DataTypeConfigurationStats()); | 530 configuration_stats_.push_back(syncer::DataTypeConfigurationStats()); |
| 524 configuration_stats_.back().model_type = type; | 531 configuration_stats_.back().model_type = type; |
| 525 configuration_stats_.back().association_stats = association_stats; | 532 configuration_stats_.back().association_stats = association_stats; |
| 526 if (info.types.Has(type)) { | 533 if (info.types.Has(type)) { |
| 527 // Times in |info| only apply to non-slow types. | 534 // Times in |info| only apply to non-slow types. |
| 528 configuration_stats_.back().download_wait_time = | 535 configuration_stats_.back().download_wait_time = |
| 529 info.download_start_time - last_restart_time_; | 536 info.download_start_time - last_restart_time_; |
| 530 if (info.first_sync_types.Has(type)) { | 537 if (info.first_sync_types.Has(type)) { |
| 531 configuration_stats_.back().download_time = | 538 configuration_stats_.back().download_time = |
| 532 info.download_ready_time - info.download_start_time; | 539 info.download_ready_time - info.download_start_time; |
| 533 } | 540 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 DVLOG(1) << "Total time spent configuring: " | 645 DVLOG(1) << "Total time spent configuring: " |
| 639 << configure_time_delta_.InSecondsF() << "s"; | 646 << configure_time_delta_.InSecondsF() << "s"; |
| 640 switch (result.status) { | 647 switch (result.status) { |
| 641 case DataTypeManager::OK: | 648 case DataTypeManager::OK: |
| 642 DVLOG(1) << "NotifyDone called with result: OK"; | 649 DVLOG(1) << "NotifyDone called with result: OK"; |
| 643 UMA_HISTOGRAM_LONG_TIMES("Sync.ConfigureTime_Long.OK", | 650 UMA_HISTOGRAM_LONG_TIMES("Sync.ConfigureTime_Long.OK", |
| 644 configure_time_delta_); | 651 configure_time_delta_); |
| 645 if (debug_info_listener_.IsInitialized() && | 652 if (debug_info_listener_.IsInitialized() && |
| 646 !configuration_stats_.empty()) { | 653 !configuration_stats_.empty()) { |
| 647 debug_info_listener_.Call( | 654 debug_info_listener_.Call( |
| 648 FROM_HERE, &DataTypeDebugInfoListener::OnDataTypeConfigureComplete, | 655 FROM_HERE, |
| 656 &syncer::DataTypeDebugInfoListener::OnDataTypeConfigureComplete, |
| 649 configuration_stats_); | 657 configuration_stats_); |
| 650 } | 658 } |
| 651 configuration_stats_.clear(); | 659 configuration_stats_.clear(); |
| 652 break; | 660 break; |
| 653 case DataTypeManager::ABORTED: | 661 case DataTypeManager::ABORTED: |
| 654 DVLOG(1) << "NotifyDone called with result: ABORTED"; | 662 DVLOG(1) << "NotifyDone called with result: ABORTED"; |
| 655 UMA_HISTOGRAM_LONG_TIMES("Sync.ConfigureTime_Long.ABORTED", | 663 UMA_HISTOGRAM_LONG_TIMES("Sync.ConfigureTime_Long.ABORTED", |
| 656 configure_time_delta_); | 664 configure_time_delta_); |
| 657 break; | 665 break; |
| 658 case DataTypeManager::UNRECOVERABLE_ERROR: | 666 case DataTypeManager::UNRECOVERABLE_ERROR: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 670 DataTypeManager::State DataTypeManagerImpl::state() const { | 678 DataTypeManager::State DataTypeManagerImpl::state() const { |
| 671 return state_; | 679 return state_; |
| 672 } | 680 } |
| 673 | 681 |
| 674 void DataTypeManagerImpl::AddToConfigureTime() { | 682 void DataTypeManagerImpl::AddToConfigureTime() { |
| 675 DCHECK(!last_restart_time_.is_null()); | 683 DCHECK(!last_restart_time_.is_null()); |
| 676 configure_time_delta_ += (base::Time::Now() - last_restart_time_); | 684 configure_time_delta_ += (base::Time::Now() - last_restart_time_); |
| 677 } | 685 } |
| 678 | 686 |
| 679 ModelTypeSet DataTypeManagerImpl::GetEnabledTypes() const { | 687 ModelTypeSet DataTypeManagerImpl::GetEnabledTypes() const { |
| 680 return Difference(last_requested_types_, | 688 return syncer::Difference(last_requested_types_, |
| 681 data_type_status_table_.GetFailedTypes()); | 689 data_type_status_table_.GetFailedTypes()); |
| 682 } | 690 } |
| 683 | 691 |
| 684 } // namespace syncer | 692 } // namespace sync_driver |
| OLD | NEW |