Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1431)

Side by Side Diff: chrome/browser/sync/glue/model_association_manager.cc

Issue 10689178: Merge 144583 - sync: fix reentrancy crash in ModelAssociationManager (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1180/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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); 104 // TODO(tim): Bug 134550. CHECKing to ensure no reentrancy on dev channel.
105 // Remove this.
106 CHECK_EQ(state_, IDLE);
105 needs_start_.clear(); 107 needs_start_.clear();
106 needs_stop_.clear(); 108 needs_stop_.clear();
107 failed_datatypes_info_.clear(); 109 failed_datatypes_info_.clear();
108 desired_types_ = desired_types; 110 desired_types_ = desired_types;
109 state_ = INITIAILIZED_TO_CONFIGURE; 111 state_ = INITIALIZED_TO_CONFIGURE;
110 112
111 DVLOG(1) << "ModelAssociationManager: Initializing"; 113 DVLOG(1) << "ModelAssociationManager: Initializing";
112 114
113 // Stop the types that are still loading from the previous configuration. 115 // Stop the types that are still loading from the previous configuration.
114 // If they are enabled we will start them here once again. 116 // If they are enabled we will start them here once again.
115 for (std::vector<DataTypeController*>::const_iterator it = 117 for (std::vector<DataTypeController*>::const_iterator it =
116 pending_model_load_.begin(); 118 pending_model_load_.begin();
117 it != pending_model_load_.end(); 119 it != pending_model_load_.end();
118 ++it) { 120 ++it) {
119 DVLOG(1) << "ModelAssociationManager: Stopping " 121 DVLOG(1) << "ModelAssociationManager: Stopping "
(...skipping 27 matching lines...) Expand all
147 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name(); 149 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name();
148 } 150 }
149 } 151 }
150 // Sort these according to kStartOrder. 152 // Sort these according to kStartOrder.
151 std::sort(needs_stop_.begin(), 153 std::sort(needs_stop_.begin(),
152 needs_stop_.end(), 154 needs_stop_.end(),
153 SortComparator(&start_order_)); 155 SortComparator(&start_order_));
154 } 156 }
155 157
156 void ModelAssociationManager::StartAssociationAsync() { 158 void ModelAssociationManager::StartAssociationAsync() {
157 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 159 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE);
158 state_ = CONFIGURING; 160 state_ = CONFIGURING;
159 DVLOG(1) << "ModelAssociationManager: Going to start model association"; 161 DVLOG(1) << "ModelAssociationManager: Going to start model association";
160 LoadModelForNextType(); 162 LoadModelForNextType();
161 } 163 }
162 164
163 void ModelAssociationManager::ResetForReconfiguration() { 165 void ModelAssociationManager::ResetForReconfiguration() {
164 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 166 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE);
165 state_ = IDLE; 167 state_ = IDLE;
166 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration"; 168 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration";
167 needs_start_.clear(); 169 needs_start_.clear();
168 needs_stop_.clear(); 170 needs_stop_.clear();
169 failed_datatypes_info_.clear(); 171 failed_datatypes_info_.clear();
170 } 172 }
171 173
172 void ModelAssociationManager::StopDisabledTypes() { 174 void ModelAssociationManager::StopDisabledTypes() {
173 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 175 DCHECK_EQ(state_, INITIALIZED_TO_CONFIGURE);
174 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; 176 DVLOG(1) << "ModelAssociationManager: Stopping disabled types.";
175 // Stop requested data types. 177 // Stop requested data types.
176 for (size_t i = 0; i < needs_stop_.size(); ++i) { 178 for (size_t i = 0; i < needs_stop_.size(); ++i) {
177 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name(); 179 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name();
178 needs_stop_[i]->Stop(); 180 needs_stop_[i]->Stop();
179 } 181 }
180 needs_stop_.clear(); 182 needs_stop_.clear();
181 } 183 }
182 184
183 void ModelAssociationManager::Stop() { 185 void ModelAssociationManager::Stop() {
(...skipping 20 matching lines...) Expand all
204 206
205 DCHECK_EQ(IDLE, state_); 207 DCHECK_EQ(IDLE, state_);
206 208
207 // We are in the midle of model association. We need to inform the caller 209 // We are in the midle of model association. We need to inform the caller
208 // so the caller can send notificationst to PSS layer. 210 // so the caller can send notificationst to PSS layer.
209 need_to_call_model_association_done = true; 211 need_to_call_model_association_done = true;
210 } 212 }
211 213
212 // Now continue stopping any types that have already started. 214 // Now continue stopping any types that have already started.
213 DCHECK(state_ == IDLE || 215 DCHECK(state_ == IDLE ||
214 state_ == INITIAILIZED_TO_CONFIGURE); 216 state_ == INITIALIZED_TO_CONFIGURE);
215 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 217 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
216 it != controllers_->end(); ++it) { 218 it != controllers_->end(); ++it) {
217 DataTypeController* dtc = (*it).second; 219 DataTypeController* dtc = (*it).second;
218 if (dtc->state() != DataTypeController::NOT_RUNNING && 220 if (dtc->state() != DataTypeController::NOT_RUNNING &&
219 dtc->state() != DataTypeController::STOPPING) { 221 dtc->state() != DataTypeController::STOPPING) {
220 dtc->Stop(); 222 dtc->Stop();
221 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name(); 223 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name();
222 } 224 }
223 } 225 }
224 226
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // Treat it like a regular error. 411 // Treat it like a regular error.
410 AppendToFailedDatatypesAndLogError( 412 AppendToFailedDatatypesAndLogError(
411 DataTypeController::ASSOCIATION_FAILED, 413 DataTypeController::ASSOCIATION_FAILED,
412 error); 414 error);
413 } 415 }
414 return; 416 return;
415 } 417 }
416 } 418 }
417 NOTREACHED(); 419 NOTREACHED();
418 return; 420 return;
419 } else { 421 } else if (state_ == IDLE) {
420 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle" 422 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle"
421 << "Informing DTM"; 423 << "Informing DTM";
422 // This datatype finished loading after the deadline imposed by the 424 // This datatype finished loading after the deadline imposed by the
423 // originating configuration cycle. Inform the DataTypeManager that the 425 // originating configuration cycle. Inform the DataTypeManager that the
424 // type has loaded, so that association may begin. 426 // type has loaded, so that association may begin.
425 result_processor_->OnTypesLoaded(); 427 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.";
426 } 433 }
427 434
428 } 435 }
429 436
430 void ModelAssociationManager::StartAssociatingNextType() { 437 void ModelAssociationManager::StartAssociatingNextType() {
431 DCHECK_EQ(state_, CONFIGURING); 438 DCHECK_EQ(state_, CONFIGURING);
432 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL)); 439 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL));
433 440
434 DVLOG(1) << "ModelAssociationManager: StartAssociatingNextType"; 441 DVLOG(1) << "ModelAssociationManager: StartAssociatingNextType";
435 if (!waiting_to_associate_.empty()) { 442 if (!waiting_to_associate_.empty()) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 502 }
496 return result; 503 return result;
497 } 504 }
498 505
499 base::OneShotTimer<ModelAssociationManager>* 506 base::OneShotTimer<ModelAssociationManager>*
500 ModelAssociationManager::GetTimerForTesting() { 507 ModelAssociationManager::GetTimerForTesting() {
501 return &timer_; 508 return &timer_;
502 } 509 }
503 510
504 } // namespace browser_sync 511 } // namespace browser_sync
505
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/model_association_manager.h ('k') | chrome/browser/sync/glue/model_association_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698