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