| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <functional> | 6 #include <functional> |
| 7 | 7 |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Build a ModelType -> order map for sorting. | 94 // Build a ModelType -> order map for sorting. |
| 95 for (int i = 0; i < static_cast<int>(arraysize(kStartOrder)); i++) | 95 for (int i = 0; i < static_cast<int>(arraysize(kStartOrder)); i++) |
| 96 start_order_[kStartOrder[i]] = i; | 96 start_order_[kStartOrder[i]] = i; |
| 97 } | 97 } |
| 98 | 98 |
| 99 ModelAssociationManager::~ModelAssociationManager() { | 99 ModelAssociationManager::~ModelAssociationManager() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ModelAssociationManager::Initialize( | 102 void ModelAssociationManager::Initialize( |
| 103 syncable::ModelTypeSet desired_types) { | 103 syncable::ModelTypeSet desired_types) { |
| 104 // TODO(tim): Bug 134550. CHECKing to ensure no reentrancy on dev channel. | 104 DCHECK_EQ(state_, IDLE); |
| 105 // Remove this. | |
| 106 CHECK_EQ(state_, IDLE); | |
| 107 needs_start_.clear(); | 105 needs_start_.clear(); |
| 108 needs_stop_.clear(); | 106 needs_stop_.clear(); |
| 109 failed_datatypes_info_.clear(); | 107 failed_datatypes_info_.clear(); |
| 110 desired_types_ = desired_types; | 108 desired_types_ = desired_types; |
| 111 state_ = INITIALIZED_TO_CONFIGURE; | 109 state_ = INITIAILIZED_TO_CONFIGURE; |
| 112 | 110 |
| 113 DVLOG(1) << "ModelAssociationManager: Initializing"; | 111 DVLOG(1) << "ModelAssociationManager: Initializing"; |
| 114 | 112 |
| 115 // Stop the types that are still loading from the previous configuration. | 113 // Stop the types that are still loading from the previous configuration. |
| 116 // If they are enabled we will start them here once again. | 114 // If they are enabled we will start them here once again. |
| 117 for (std::vector<DataTypeController*>::const_iterator it = | 115 for (std::vector<DataTypeController*>::const_iterator it = |
| 118 pending_model_load_.begin(); | 116 pending_model_load_.begin(); |
| 119 it != pending_model_load_.end(); | 117 it != pending_model_load_.end(); |
| 120 ++it) { | 118 ++it) { |
| 121 DVLOG(1) << "ModelAssociationManager: Stopping " | 119 DVLOG(1) << "ModelAssociationManager: Stopping " |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name(); | 147 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name(); |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 // Sort these according to kStartOrder. | 150 // Sort these according to kStartOrder. |
| 153 std::sort(needs_stop_.begin(), | 151 std::sort(needs_stop_.begin(), |
| 154 needs_stop_.end(), | 152 needs_stop_.end(), |
| 155 SortComparator(&start_order_)); | 153 SortComparator(&start_order_)); |
| 156 } | 154 } |
| 157 | 155 |
| 158 void ModelAssociationManager::StartAssociationAsync() { | 156 void ModelAssociationManager::StartAssociationAsync() { |
| 159 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); | 157 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); |
| 160 state_ = CONFIGURING; | 158 state_ = CONFIGURING; |
| 161 DVLOG(1) << "ModelAssociationManager: Going to start model association"; | 159 DVLOG(1) << "ModelAssociationManager: Going to start model association"; |
| 162 LoadModelForNextType(); | 160 LoadModelForNextType(); |
| 163 } | 161 } |
| 164 | 162 |
| 165 void ModelAssociationManager::ResetForReconfiguration() { | 163 void ModelAssociationManager::ResetForReconfiguration() { |
| 166 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); | 164 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); |
| 167 state_ = IDLE; | 165 state_ = IDLE; |
| 168 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; | 166 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; |
| 169 needs_start_.clear(); | 167 needs_start_.clear(); |
| 170 needs_stop_.clear(); | 168 needs_stop_.clear(); |
| 171 failed_datatypes_info_.clear(); | 169 failed_datatypes_info_.clear(); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void ModelAssociationManager::StopDisabledTypes() { | 172 void ModelAssociationManager::StopDisabledTypes() { |
| 175 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE); | 173 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); |
| 176 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; | 174 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; |
| 177 // Stop requested data types. | 175 // Stop requested data types. |
| 178 for (size_t i = 0; i < needs_stop_.size(); ++i) { | 176 for (size_t i = 0; i < needs_stop_.size(); ++i) { |
| 179 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name(); | 177 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name(); |
| 180 needs_stop_[i]->Stop(); | 178 needs_stop_[i]->Stop(); |
| 181 } | 179 } |
| 182 needs_stop_.clear(); | 180 needs_stop_.clear(); |
| 183 } | 181 } |
| 184 | 182 |
| 185 void ModelAssociationManager::Stop() { | 183 void ModelAssociationManager::Stop() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 | 204 |
| 207 DCHECK_EQ(IDLE, state_); | 205 DCHECK_EQ(IDLE, state_); |
| 208 | 206 |
| 209 // We are in the midle of model association. We need to inform the caller | 207 // We are in the midle of model association. We need to inform the caller |
| 210 // so the caller can send notificationst to PSS layer. | 208 // so the caller can send notificationst to PSS layer. |
| 211 need_to_call_model_association_done = true; | 209 need_to_call_model_association_done = true; |
| 212 } | 210 } |
| 213 | 211 |
| 214 // Now continue stopping any types that have already started. | 212 // Now continue stopping any types that have already started. |
| 215 DCHECK(state_ == IDLE || | 213 DCHECK(state_ == IDLE || |
| 216 state_ == INITIALIZED_TO_CONFIGURE); | 214 state_ == INITIAILIZED_TO_CONFIGURE); |
| 217 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); | 215 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); |
| 218 it != controllers_->end(); ++it) { | 216 it != controllers_->end(); ++it) { |
| 219 DataTypeController* dtc = (*it).second; | 217 DataTypeController* dtc = (*it).second; |
| 220 if (dtc->state() != DataTypeController::NOT_RUNNING && | 218 if (dtc->state() != DataTypeController::NOT_RUNNING && |
| 221 dtc->state() != DataTypeController::STOPPING) { | 219 dtc->state() != DataTypeController::STOPPING) { |
| 222 dtc->Stop(); | 220 dtc->Stop(); |
| 223 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name(); | 221 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name(); |
| 224 } | 222 } |
| 225 } | 223 } |
| 226 | 224 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // Treat it like a regular error. | 409 // Treat it like a regular error. |
| 412 AppendToFailedDatatypesAndLogError( | 410 AppendToFailedDatatypesAndLogError( |
| 413 DataTypeController::ASSOCIATION_FAILED, | 411 DataTypeController::ASSOCIATION_FAILED, |
| 414 error); | 412 error); |
| 415 } | 413 } |
| 416 return; | 414 return; |
| 417 } | 415 } |
| 418 } | 416 } |
| 419 NOTREACHED(); | 417 NOTREACHED(); |
| 420 return; | 418 return; |
| 421 } else if (state_ == IDLE) { | 419 } else { |
| 422 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle" | 420 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle" |
| 423 << "Informing DTM"; | 421 << "Informing DTM"; |
| 424 // This datatype finished loading after the deadline imposed by the | 422 // This datatype finished loading after the deadline imposed by the |
| 425 // originating configuration cycle. Inform the DataTypeManager that the | 423 // originating configuration cycle. Inform the DataTypeManager that the |
| 426 // type has loaded, so that association may begin. | 424 // type has loaded, so that association may begin. |
| 427 result_processor_->OnTypesLoaded(); | 425 result_processor_->OnTypesLoaded(); |
| 428 } else { | |
| 429 // If we're not IDLE or CONFIGURING, we're being invoked as part of an abort | |
| 430 // process (possibly a reconfiguration, or disabling of a broken data type). | |
| 431 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback occurred while " | |
| 432 << "not IDLE or CONFIGURING. Doing nothing."; | |
| 433 } | 426 } |
| 434 | 427 |
| 435 } | 428 } |
| 436 | 429 |
| 437 void ModelAssociationManager::StartAssociatingNextType() { | 430 void ModelAssociationManager::StartAssociatingNextType() { |
| 438 DCHECK_EQ(state_, CONFIGURING); | 431 DCHECK_EQ(state_, CONFIGURING); |
| 439 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL)); | 432 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL)); |
| 440 | 433 |
| 441 DVLOG(1) << "ModelAssociationManager: StartAssociatingNextType"; | 434 DVLOG(1) << "ModelAssociationManager: StartAssociatingNextType"; |
| 442 if (!waiting_to_associate_.empty()) { | 435 if (!waiting_to_associate_.empty()) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 495 } |
| 503 return result; | 496 return result; |
| 504 } | 497 } |
| 505 | 498 |
| 506 base::OneShotTimer<ModelAssociationManager>* | 499 base::OneShotTimer<ModelAssociationManager>* |
| 507 ModelAssociationManager::GetTimerForTesting() { | 500 ModelAssociationManager::GetTimerForTesting() { |
| 508 return &timer_; | 501 return &timer_; |
| 509 } | 502 } |
| 510 | 503 |
| 511 } // namespace browser_sync | 504 } // namespace browser_sync |
| 505 |
| OLD | NEW |