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