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