| 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 "chrome/browser/sync/glue/model_association_manager.h" | 5 #include "chrome/browser/sync/glue/model_association_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // TODO(tim): Bug 134550. CHECKing to ensure no reentrancy on dev channel. | 139 // TODO(tim): Bug 134550. CHECKing to ensure no reentrancy on dev channel. |
| 140 // Remove this. | 140 // Remove this. |
| 141 CHECK_EQ(state_, IDLE); | 141 CHECK_EQ(state_, IDLE); |
| 142 needs_start_.clear(); | 142 needs_start_.clear(); |
| 143 needs_stop_.clear(); | 143 needs_stop_.clear(); |
| 144 failed_data_types_info_.clear(); | 144 failed_data_types_info_.clear(); |
| 145 associating_types_.Clear(); | 145 associating_types_.Clear(); |
| 146 needs_crypto_types_.Clear(); | 146 needs_crypto_types_.Clear(); |
| 147 state_ = INITIALIZED_TO_CONFIGURE; | 147 state_ = INITIALIZED_TO_CONFIGURE; |
| 148 | 148 |
| 149 DVLOG(1) << "ModelAssociationManager: Initializing"; | 149 DVLOG(1) << "ModelAssociationManager: Initializing for " |
| 150 << syncer::ModelTypeSetToString(desired_types); |
| 150 | 151 |
| 151 // Stop the types that are still loading from the previous configuration. | 152 // Stop the types that are still loading from the previous configuration. |
| 152 // If they are enabled we will start them here once again. | 153 // If they are enabled we will start them here once again. |
| 153 for (std::vector<DataTypeController*>::const_iterator it = | 154 for (std::vector<DataTypeController*>::const_iterator it = |
| 154 pending_model_load_.begin(); | 155 pending_model_load_.begin(); |
| 155 it != pending_model_load_.end(); | 156 it != pending_model_load_.end(); |
| 156 ++it) { | 157 ++it) { |
| 157 DVLOG(1) << "ModelAssociationManager: Stopping " | 158 DVLOG(1) << "ModelAssociationManager: Stopping " |
| 158 << (*it)->name() | 159 << (*it)->name() |
| 159 << " before initialization"; | 160 << " before initialization"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 state_ = IDLE; | 207 state_ = IDLE; |
| 207 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; | 208 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; |
| 208 needs_start_.clear(); | 209 needs_start_.clear(); |
| 209 needs_stop_.clear(); | 210 needs_stop_.clear(); |
| 210 associating_types_.Clear(); | 211 associating_types_.Clear(); |
| 211 failed_data_types_info_.clear(); | 212 failed_data_types_info_.clear(); |
| 212 needs_crypto_types_.Clear(); | 213 needs_crypto_types_.Clear(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void ModelAssociationManager::StopDisabledTypes() { | 216 void ModelAssociationManager::StopDisabledTypes() { |
| 216 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); | |
| 217 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; | 217 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; |
| 218 // Stop requested data types. | 218 // Stop requested data types. |
| 219 for (size_t i = 0; i < needs_stop_.size(); ++i) { | 219 for (size_t i = 0; i < needs_stop_.size(); ++i) { |
| 220 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name(); | 220 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name(); |
| 221 needs_stop_[i]->Stop(); | 221 needs_stop_[i]->Stop(); |
| 222 } | 222 } |
| 223 needs_stop_.clear(); | 223 needs_stop_.clear(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void ModelAssociationManager::Stop() { | 226 void ModelAssociationManager::Stop() { |
| 227 bool need_to_call_model_association_done = false; | 227 bool need_to_call_model_association_done = false; |
| 228 DVLOG(1) << "ModelAssociationManager: Stopping MAM"; | 228 DVLOG(1) << "ModelAssociationManager: Stopping MAM"; |
| 229 if (state_ == CONFIGURING) { | 229 if (state_ == CONFIGURING) { |
| 230 DVLOG(1) << "ModelAssociationManager: In the middle of configuratio while" | 230 DVLOG(1) << "ModelAssociationManager: In the middle of configuration while" |
| 231 << " stopping"; | 231 << " stopping"; |
| 232 state_ = ABORTED; | 232 state_ = ABORTED; |
| 233 DCHECK(currently_associating_ != NULL || | 233 DCHECK(currently_associating_ != NULL || |
| 234 needs_start_.size() > 0 || | 234 needs_start_.size() > 0 || |
| 235 pending_model_load_.size() > 0 || | 235 pending_model_load_.size() > 0 || |
| 236 waiting_to_associate_.size() > 0); | 236 waiting_to_associate_.size() > 0); |
| 237 | 237 |
| 238 if (currently_associating_) { | 238 if (currently_associating_) { |
| 239 TRACE_EVENT_END0("sync", "ModelAssociation"); | 239 TRACE_EVENT_END0("sync", "ModelAssociation"); |
| 240 DVLOG(1) << "ModelAssociationManager: stopping " | 240 DVLOG(1) << "ModelAssociationManager: stopping " |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 base::TimeDelta::FromSeconds(kDataTypeLoadWaitTimeInSeconds), | 424 base::TimeDelta::FromSeconds(kDataTypeLoadWaitTimeInSeconds), |
| 425 this, | 425 this, |
| 426 &ModelAssociationManager::LoadModelForNextType); | 426 &ModelAssociationManager::LoadModelForNextType); |
| 427 dtc->LoadModels(base::Bind( | 427 dtc->LoadModels(base::Bind( |
| 428 &ModelAssociationManager::ModelLoadCallback, | 428 &ModelAssociationManager::ModelLoadCallback, |
| 429 weak_ptr_factory_.GetWeakPtr())); | 429 weak_ptr_factory_.GetWeakPtr())); |
| 430 | 430 |
| 431 return; | 431 return; |
| 432 } | 432 } |
| 433 | 433 |
| 434 DVLOG(1) << "ModelAssociationManager: All types have models loaded." | 434 DVLOG(1) << "ModelAssociationManager: All types have models loaded. " |
| 435 << "Moving on to StartAssociatingNextType."; | 435 << "Moving on to StartAssociatingNextType."; |
| 436 | 436 |
| 437 // If all controllers have their |LoadModels| invoked then pass onto | 437 // If all controllers have their |LoadModels| invoked then pass onto |
| 438 // |StartAssociatingNextType|. | 438 // |StartAssociatingNextType|. |
| 439 StartAssociatingNextType(); | 439 StartAssociatingNextType(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void ModelAssociationManager::ModelLoadCallback( | 442 void ModelAssociationManager::ModelLoadCallback( |
| 443 syncer::ModelType type, syncer::SyncError error) { | 443 syncer::ModelType type, syncer::SyncError error) { |
| 444 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback for " | 444 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback for " |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 TypeStartCallback(DataTypeController::ASSOCIATION_FAILED, | 479 TypeStartCallback(DataTypeController::ASSOCIATION_FAILED, |
| 480 local_merge_result, | 480 local_merge_result, |
| 481 syncer::SyncMergeResult(type)); | 481 syncer::SyncMergeResult(type)); |
| 482 } | 482 } |
| 483 return; | 483 return; |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 NOTREACHED(); | 486 NOTREACHED(); |
| 487 return; | 487 return; |
| 488 } else if (state_ == IDLE) { | 488 } else if (state_ == IDLE) { |
| 489 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle" | 489 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle. " |
| 490 << "Informing DTM"; | 490 << "Informing DTM"; |
| 491 // This datatype finished loading after the deadline imposed by the | 491 // This datatype finished loading after the deadline imposed by the |
| 492 // originating configuration cycle. Inform the DataTypeManager that the | 492 // originating configuration cycle. Inform the DataTypeManager that the |
| 493 // type has loaded, so that association may begin. | 493 // type has loaded, so that association may begin. |
| 494 result_processor_->OnTypesLoaded(); | 494 result_processor_->OnTypesLoaded(); |
| 495 } else { | 495 } else { |
| 496 // If we're not IDLE or CONFIGURING, we're being invoked as part of an abort | 496 // If we're not IDLE or CONFIGURING, we're being invoked as part of an abort |
| 497 // process (possibly a reconfiguration, or disabling of a broken data type). | 497 // process (possibly a reconfiguration, or disabling of a broken data type). |
| 498 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback occurred while " | 498 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback occurred while " |
| 499 << "not IDLE or CONFIGURING. Doing nothing."; | 499 << "not IDLE or CONFIGURING. Doing nothing."; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 515 DataTypeController* dtc = waiting_to_associate_[0]; | 515 DataTypeController* dtc = waiting_to_associate_[0]; |
| 516 waiting_to_associate_.erase(waiting_to_associate_.begin()); | 516 waiting_to_associate_.erase(waiting_to_associate_.begin()); |
| 517 currently_associating_ = dtc; | 517 currently_associating_ = dtc; |
| 518 current_type_association_start_time_ = base::Time::Now(); | 518 current_type_association_start_time_ = base::Time::Now(); |
| 519 dtc->StartAssociating(base::Bind( | 519 dtc->StartAssociating(base::Bind( |
| 520 &ModelAssociationManager::TypeStartCallback, | 520 &ModelAssociationManager::TypeStartCallback, |
| 521 weak_ptr_factory_.GetWeakPtr())); | 521 weak_ptr_factory_.GetWeakPtr())); |
| 522 return; | 522 return; |
| 523 } | 523 } |
| 524 | 524 |
| 525 // We are done with this cycle of association. | 525 // We are done with this cycle of association. Stop any failed types now. |
| 526 needs_stop_.clear(); |
| 527 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); |
| 528 it != controllers_->end(); ++it) { |
| 529 DataTypeController* dtc = (*it).second.get(); |
| 530 if (failed_data_types_info_.count(dtc->type()) > 0 && |
| 531 dtc->state() != DataTypeController::NOT_RUNNING) { |
| 532 needs_stop_.push_back(dtc); |
| 533 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name(); |
| 534 } |
| 535 } |
| 536 StopDisabledTypes(); |
| 537 |
| 526 state_ = IDLE; | 538 state_ = IDLE; |
| 527 | 539 |
| 528 DataTypeManager::ConfigureStatus configure_status = DataTypeManager::OK; | 540 DataTypeManager::ConfigureStatus configure_status = DataTypeManager::OK; |
| 529 | 541 |
| 530 if (!failed_data_types_info_.empty() || | 542 if (!failed_data_types_info_.empty() || |
| 531 !GetTypesWaitingToLoad().Empty() || | 543 !GetTypesWaitingToLoad().Empty() || |
| 532 !needs_crypto_types_.Empty()) { | 544 !needs_crypto_types_.Empty()) { |
| 533 // We have not configured all types that we have been asked to configure. | 545 // We have not configured all types that we have been asked to configure. |
| 534 // Either we have failed types or types that have not completed loading | 546 // Either we have failed types or types that have not completed loading |
| 535 // yet. | 547 // yet. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 556 } | 568 } |
| 557 return result; | 569 return result; |
| 558 } | 570 } |
| 559 | 571 |
| 560 base::OneShotTimer<ModelAssociationManager>* | 572 base::OneShotTimer<ModelAssociationManager>* |
| 561 ModelAssociationManager::GetTimerForTesting() { | 573 ModelAssociationManager::GetTimerForTesting() { |
| 562 return &timer_; | 574 return &timer_; |
| 563 } | 575 } |
| 564 | 576 |
| 565 } // namespace browser_sync | 577 } // namespace browser_sync |
| OLD | NEW |