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

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

Issue 10387144: [Sync] - Implement isolated model association. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For submitting. Created 8 years, 7 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>
6 #include <functional>
7
8 #include "base/debug/trace_event.h"
9
10 #include "base/logging.h"
11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h"
13
5 #include "chrome/browser/sync/glue/model_association_manager.h" 14 #include "chrome/browser/sync/glue/model_association_manager.h"
6 15
7 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
8 #include <algorithm> 17 #include <algorithm>
9 #include <functional> 18 #include <functional>
10 19
11 #include "base/debug/trace_event.h" 20 #include "base/debug/trace_event.h"
12 21
13 #include "base/logging.h" 22 #include "base/logging.h"
14 #include "base/message_loop.h" 23 #include "base/message_loop.h"
15 #include "base/metrics/histogram.h" 24 #include "base/metrics/histogram.h"
16 25
17 26
18 using content::BrowserThread; 27 using content::BrowserThread;
19 using syncable::ModelTypeSet; 28 using syncable::ModelTypeSet;
20 29
21 namespace browser_sync { 30 namespace browser_sync {
31 // The amount of time we wait for a datatype to load. If the type has
32 // not finished loading we move on to the next type. Once this type
33 // finishes loading we will do a configure to associate this type. Note
34 // that in most cases types finish loading before this timeout.
35 const int64 kDataTypeLoadWaitTimeInSeconds = 120;
22 namespace { 36 namespace {
23 37
24 static const syncable::ModelType kStartOrder[] = { 38 static const syncable::ModelType kStartOrder[] = {
25 syncable::NIGORI, // Listed for completeness. 39 syncable::NIGORI, // Listed for completeness.
26 syncable::BOOKMARKS, 40 syncable::BOOKMARKS,
27 syncable::PREFERENCES, 41 syncable::PREFERENCES,
28 syncable::AUTOFILL, 42 syncable::AUTOFILL,
29 syncable::AUTOFILL_PROFILE, 43 syncable::AUTOFILL_PROFILE,
30 syncable::EXTENSION_SETTINGS, 44 syncable::EXTENSION_SETTINGS,
31 syncable::EXTENSIONS, 45 syncable::EXTENSIONS,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 101
88 void ModelAssociationManager::Initialize( 102 void ModelAssociationManager::Initialize(
89 syncable::ModelTypeSet desired_types) { 103 syncable::ModelTypeSet desired_types) {
90 DCHECK_EQ(state_, IDLE); 104 DCHECK_EQ(state_, IDLE);
91 needs_start_.clear(); 105 needs_start_.clear();
92 needs_stop_.clear(); 106 needs_stop_.clear();
93 failed_datatypes_info_.clear(); 107 failed_datatypes_info_.clear();
94 desired_types_ = desired_types; 108 desired_types_ = desired_types;
95 state_ = INITIAILIZED_TO_CONFIGURE; 109 state_ = INITIAILIZED_TO_CONFIGURE;
96 110
111 DVLOG(1) << "ModelAssociationManager: Initializing";
112
113 // Stop the types that are still loading from the previous configuration.
114 // If they are enabled we will start them here once again.
115 for (std::vector<DataTypeController*>::const_iterator it =
116 pending_model_load_.begin();
117 it != pending_model_load_.end();
118 ++it) {
119 DVLOG(1) << "ModelAssociationManager: Stopping "
120 << (*it)->name()
121 << " before initialization";
122 (*it)->Stop();
123 }
124
125 pending_model_load_.clear();
126 waiting_to_associate_.clear();
127 currently_associating_ = NULL;
128
97 // We need to calculate our |needs_start_| and |needs_stop_| list. 129 // We need to calculate our |needs_start_| and |needs_stop_| list.
98 GetControllersNeedingStart(&needs_start_); 130 GetControllersNeedingStart(&needs_start_);
99 // Sort these according to kStartOrder. 131 // Sort these according to kStartOrder.
100 std::sort(needs_start_.begin(), 132 std::sort(needs_start_.begin(),
101 needs_start_.end(), 133 needs_start_.end(),
102 SortComparator(&start_order_)); 134 SortComparator(&start_order_));
103 135
104 // Add any data type controllers into that needs_stop_ list that are 136 // Add any data type controllers into that needs_stop_ list that are
105 // currently MODEL_STARTING, ASSOCIATING, RUNNING or DISABLED. 137 // currently MODEL_STARTING, ASSOCIATING, RUNNING or DISABLED.
106 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 138 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
107 it != controllers_->end(); ++it) { 139 it != controllers_->end(); ++it) {
108 DataTypeController* dtc = (*it).second; 140 DataTypeController* dtc = (*it).second;
109 if (!desired_types.Has(dtc->type()) && ( 141 if (!desired_types.Has(dtc->type()) && (
110 dtc->state() == DataTypeController::MODEL_STARTING || 142 dtc->state() == DataTypeController::MODEL_STARTING ||
111 dtc->state() == DataTypeController::ASSOCIATING || 143 dtc->state() == DataTypeController::ASSOCIATING ||
112 dtc->state() == DataTypeController::RUNNING || 144 dtc->state() == DataTypeController::RUNNING ||
113 dtc->state() == DataTypeController::DISABLED)) { 145 dtc->state() == DataTypeController::DISABLED)) {
114 needs_stop_.push_back(dtc); 146 needs_stop_.push_back(dtc);
115 DVLOG(1) << "Will stop " << dtc->name(); 147 DVLOG(1) << "ModelTypeToString: Will stop " << dtc->name();
116 } 148 }
117 } 149 }
118 // Sort these according to kStartOrder. 150 // Sort these according to kStartOrder.
119 std::sort(needs_stop_.begin(), 151 std::sort(needs_stop_.begin(),
120 needs_stop_.end(), 152 needs_stop_.end(),
121 SortComparator(&start_order_)); 153 SortComparator(&start_order_));
122 } 154 }
123 155
124 void ModelAssociationManager::StartAssociationAsync() { 156 void ModelAssociationManager::StartAssociationAsync() {
125 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 157 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE);
126 state_ = CONFIGURING; 158 state_ = CONFIGURING;
159 DVLOG(1) << "ModelAssociationManager: Going to start model association";
127 LoadModelForNextType(); 160 LoadModelForNextType();
128 } 161 }
129 162
130 void ModelAssociationManager::ResetForReconfiguration() { 163 void ModelAssociationManager::ResetForReconfiguration() {
131 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 164 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE);
132 state_ = IDLE; 165 state_ = IDLE;
166 DVLOG(1) << "ModelAssociationManager: Reseting for reconfiguration";
133 needs_start_.clear(); 167 needs_start_.clear();
134 needs_stop_.clear(); 168 needs_stop_.clear();
135 failed_datatypes_info_.clear(); 169 failed_datatypes_info_.clear();
136 } 170 }
137 171
138 void ModelAssociationManager::StopDisabledTypes() { 172 void ModelAssociationManager::StopDisabledTypes() {
139 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE); 173 DCHECK_EQ(state_, INITIAILIZED_TO_CONFIGURE);
174 DVLOG(1) << "ModelAssociationManager: Stopping disabled types.";
140 // Stop requested data types. 175 // Stop requested data types.
141 for (size_t i = 0; i < needs_stop_.size(); ++i) { 176 for (size_t i = 0; i < needs_stop_.size(); ++i) {
142 DVLOG(1) << "Stopping " << needs_stop_[i]->name(); 177 DVLOG(1) << "ModelAssociationManager: Stopping " << needs_stop_[i]->name();
143 needs_stop_[i]->Stop(); 178 needs_stop_[i]->Stop();
144 } 179 }
145 needs_stop_.clear(); 180 needs_stop_.clear();
146 } 181 }
147 182
148 void ModelAssociationManager::Stop() { 183 void ModelAssociationManager::Stop() {
149 bool need_to_call_model_association_done = false; 184 bool need_to_call_model_association_done = false;
185 DVLOG(1) << "ModelAssociationManager: Stopping MAM";
150 if (state_ == CONFIGURING) { 186 if (state_ == CONFIGURING) {
187 DVLOG(1) << "ModelAssociationManager: In the middle of configuratio while"
188 << " stopping";
151 state_ = ABORTED; 189 state_ = ABORTED;
152 DCHECK(currently_associating_ != NULL || 190 DCHECK(currently_associating_ != NULL ||
153 needs_start_.size() > 0 || 191 needs_start_.size() > 0 ||
154 pending_model_load_.size() > 0 || 192 pending_model_load_.size() > 0 ||
155 waiting_to_associate_.size() > 0); 193 waiting_to_associate_.size() > 0);
156 194
157 if (currently_associating_) { 195 if (currently_associating_) {
196 DVLOG(1) << "ModelAssociationManager: stopping "
197 << currently_associating_->name();
158 currently_associating_->Stop(); 198 currently_associating_->Stop();
159 } else { 199 } else {
160 // DTCs in other lists would be stopped below. 200 // DTCs in other lists would be stopped below.
161 state_ = IDLE; 201 state_ = IDLE;
162 } 202 }
163 203
164 DCHECK_EQ(IDLE, state_); 204 DCHECK_EQ(IDLE, state_);
165 205
166 // 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
167 // so the caller can send notificationst to PSS layer. 207 // so the caller can send notificationst to PSS layer.
168 need_to_call_model_association_done = true; 208 need_to_call_model_association_done = true;
169 } 209 }
170 210
171 // Now continue stopping any types that have already started. 211 // Now continue stopping any types that have already started.
172 DCHECK(state_ == IDLE || 212 DCHECK(state_ == IDLE ||
173 state_ == INITIAILIZED_TO_CONFIGURE); 213 state_ == INITIAILIZED_TO_CONFIGURE);
174 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 214 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
175 it != controllers_->end(); ++it) { 215 it != controllers_->end(); ++it) {
176 DataTypeController* dtc = (*it).second; 216 DataTypeController* dtc = (*it).second;
177 if (dtc->state() != DataTypeController::NOT_RUNNING && 217 if (dtc->state() != DataTypeController::NOT_RUNNING &&
178 dtc->state() != DataTypeController::STOPPING) { 218 dtc->state() != DataTypeController::STOPPING) {
179 dtc->Stop(); 219 dtc->Stop();
180 DVLOG(1) << "Stopped " << dtc->name(); 220 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name();
181 } 221 }
182 } 222 }
183 223
184 if (need_to_call_model_association_done) { 224 if (need_to_call_model_association_done) {
225 DVLOG(1) << "ModelAssociationManager: Calling OnModelAssociationDone";
185 DataTypeManager::ConfigureResult result(DataTypeManager::ABORTED, 226 DataTypeManager::ConfigureResult result(DataTypeManager::ABORTED,
186 desired_types_, 227 desired_types_,
187 failed_datatypes_info_); 228 failed_datatypes_info_,
229 syncable::ModelTypeSet());
188 result_processor_->OnModelAssociationDone(result); 230 result_processor_->OnModelAssociationDone(result);
189 } 231 }
190 232
191 failed_datatypes_info_.clear(); 233 failed_datatypes_info_.clear();
192 } 234 }
193 235
194 bool ModelAssociationManager::GetControllersNeedingStart( 236 bool ModelAssociationManager::GetControllersNeedingStart(
195 std::vector<DataTypeController*>* needs_start) { 237 std::vector<DataTypeController*>* needs_start) {
238 DVLOG(1) << "ModelAssociationManager: GetControllersNeedingStart";
196 // Add any data type controllers into the needs_start_ list that are 239 // Add any data type controllers into the needs_start_ list that are
197 // currently NOT_RUNNING or STOPPING. 240 // currently NOT_RUNNING or STOPPING.
198 bool found_any = false; 241 bool found_any = false;
199 for (ModelTypeSet::Iterator it = desired_types_.First(); 242 for (ModelTypeSet::Iterator it = desired_types_.First();
200 it.Good(); it.Inc()) { 243 it.Good(); it.Inc()) {
201 DataTypeController::TypeMap::const_iterator dtc = 244 DataTypeController::TypeMap::const_iterator dtc =
202 controllers_->find(it.Get()); 245 controllers_->find(it.Get());
203 if (dtc != controllers_->end() && 246 if (dtc != controllers_->end() &&
204 (dtc->second->state() == DataTypeController::NOT_RUNNING || 247 (dtc->second->state() == DataTypeController::NOT_RUNNING ||
205 dtc->second->state() == DataTypeController::STOPPING)) { 248 dtc->second->state() == DataTypeController::STOPPING)) {
206 found_any = true; 249 found_any = true;
207 if (needs_start) 250 if (needs_start)
208 needs_start->push_back(dtc->second.get()); 251 needs_start->push_back(dtc->second.get());
209 if (dtc->second->state() == DataTypeController::DISABLED) { 252 if (dtc->second->state() == DataTypeController::DISABLED) {
210 DVLOG(1) << "Found " << syncable::ModelTypeToString(dtc->second->type()) 253 DVLOG(1) << "ModelAssociationManager: Found "\
254 << syncable::ModelTypeToString(dtc->second->type())
211 << " in disabled state."; 255 << " in disabled state.";
212 } 256 }
213 } 257 }
214 } 258 }
215 return found_any; 259 return found_any;
216 } 260 }
217 261
262 void ModelAssociationManager::AppendToFailedDatatypesAndLogError(
263 DataTypeController::StartResult result,
264 const SyncError& error) {
265 failed_datatypes_info_.push_back(error);
266 LOG(ERROR) << "Failed to associate models for "
267 << syncable::ModelTypeToString(error.type());
268 UMA_HISTOGRAM_ENUMERATION("Sync.ConfigureFailed",
269 error.type(),
270 syncable::MODEL_TYPE_COUNT);
271 }
272
218 void ModelAssociationManager::TypeStartCallback( 273 void ModelAssociationManager::TypeStartCallback(
219 DataTypeController::StartResult result, 274 DataTypeController::StartResult result,
220 const SyncError& error) { 275 const SyncError& error) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222 277
278 DVLOG(1) << "ModelAssociationManager: TypeStartCallback";
223 if (state_ == ABORTED) { 279 if (state_ == ABORTED) {
224 // Now that we have finished with the current type we can stop 280 // Now that we have finished with the current type we can stop
225 // if abort was called. 281 // if abort was called.
282 DVLOG(1) << "ModelAssociationManager: Doing an early return"
283 << " because of abort";
226 state_ = IDLE; 284 state_ = IDLE;
227 return; 285 return;
228 } 286 }
229 287
230 DCHECK(state_ == CONFIGURING); 288 DCHECK(state_ == CONFIGURING);
231 289
232 // We are done with this type. Clear it. 290 // We are done with this type. Clear it.
233 DataTypeController* started_dtc = currently_associating_; 291 DataTypeController* started_dtc = currently_associating_;
234 currently_associating_ = NULL; 292 currently_associating_ = NULL;
235 293
236 if (result == DataTypeController::ASSOCIATION_FAILED) { 294 if (result == DataTypeController::ASSOCIATION_FAILED) {
237 failed_datatypes_info_.push_back(error); 295 DVLOG(1) << "ModelAssociationManager: Encountered a failed type";
238 LOG(ERROR) << "Failed to associate models for " 296 AppendToFailedDatatypesAndLogError(result, error);
239 << syncable::ModelTypeToString(error.type());
240 UMA_HISTOGRAM_ENUMERATION("Sync.ConfigureFailed",
241 error.type(),
242 syncable::MODEL_TYPE_COUNT);
243 } 297 }
244 298
245 // If the type started normally, continue to the next type. 299 // If the type started normally, continue to the next type.
246 // If the type is waiting for the cryptographer, continue to the next type. 300 // If the type is waiting for the cryptographer, continue to the next type.
247 // Once the cryptographer is ready, we'll attempt to restart this type. 301 // Once the cryptographer is ready, we'll attempt to restart this type.
248 // If this type encountered a type specific error continue to the next type. 302 // If this type encountered a type specific error continue to the next type.
249 if (result == DataTypeController::NEEDS_CRYPTO || 303 if (result == DataTypeController::NEEDS_CRYPTO ||
250 result == DataTypeController::OK || 304 result == DataTypeController::OK ||
251 result == DataTypeController::OK_FIRST_RUN || 305 result == DataTypeController::OK_FIRST_RUN ||
252 result == DataTypeController::ASSOCIATION_FAILED) { 306 result == DataTypeController::ASSOCIATION_FAILED) {
307 DVLOG(1) << "ModelAssociationManager: type start callback returned "
308 << result << " so calling LoadModelForNextType";
253 LoadModelForNextType(); 309 LoadModelForNextType();
254 return; 310 return;
255 } 311 }
256 312
257 // Any other result requires reconfiguration. Pass it on through the callback. 313 // Any other result requires reconfiguration. Pass it on through the callback.
258 LOG(ERROR) << "Failed to configure " << started_dtc->name(); 314 LOG(ERROR) << "Failed to configure " << started_dtc->name();
259 DCHECK(error.IsSet()); 315 DCHECK(error.IsSet());
260 DCHECK_EQ(started_dtc->type(), error.type()); 316 DCHECK_EQ(started_dtc->type(), error.type());
261 DataTypeManager::ConfigureStatus configure_status = 317 DataTypeManager::ConfigureStatus configure_status =
262 DataTypeManager::ABORTED; 318 DataTypeManager::ABORTED;
(...skipping 10 matching lines...) Expand all
273 } 329 }
274 330
275 std::list<SyncError> errors; 331 std::list<SyncError> errors;
276 errors.push_back(error); 332 errors.push_back(error);
277 333
278 // Put our state to idle. 334 // Put our state to idle.
279 state_ = IDLE; 335 state_ = IDLE;
280 336
281 DataTypeManager::ConfigureResult configure_result(configure_status, 337 DataTypeManager::ConfigureResult configure_result(configure_status,
282 desired_types_, 338 desired_types_,
283 errors); 339 errors,
340 syncable::ModelTypeSet());
284 result_processor_->OnModelAssociationDone(configure_result); 341 result_processor_->OnModelAssociationDone(configure_result);
285 } 342 }
286 343
287 void ModelAssociationManager::LoadModelForNextType() { 344 void ModelAssociationManager::LoadModelForNextType() {
345 DVLOG(1) << "ModelAssociationManager: LoadModelForNextType";
288 if (!needs_start_.empty()) { 346 if (!needs_start_.empty()) {
289 DVLOG(1) << "Starting " << needs_start_[0]->name(); 347 DVLOG(1) << "ModelAssociationManager: Starting " << needs_start_[0]->name();
290 348
291 DataTypeController* dtc = needs_start_[0]; 349 DataTypeController* dtc = needs_start_[0];
292 needs_start_.erase(needs_start_.begin()); 350 needs_start_.erase(needs_start_.begin());
293 // Move from |needs_start_| to |pending_model_load_|. 351 // Move from |needs_start_| to |pending_model_load_|.
294 pending_model_load_.push_back(dtc); 352 pending_model_load_.insert(pending_model_load_.begin(), dtc);
353 timer_.Start(FROM_HERE,
354 base::TimeDelta::FromSeconds(kDataTypeLoadWaitTimeInSeconds),
355 this,
356 &ModelAssociationManager::LoadModelForNextType);
295 dtc->LoadModels(base::Bind( 357 dtc->LoadModels(base::Bind(
296 &ModelAssociationManager::ModelLoadCallback, 358 &ModelAssociationManager::ModelLoadCallback,
297 weak_ptr_factory_.GetWeakPtr())); 359 weak_ptr_factory_.GetWeakPtr()));
360
298 return; 361 return;
299 } 362 }
300 363
364 DVLOG(1) << "ModelAssociationManager: All types have models loaded."
365 << "Moving on to StartAssociatingNextType.";
366
301 // If all controllers have their |LoadModels| invoked then pass onto 367 // If all controllers have their |LoadModels| invoked then pass onto
302 // |StartAssociatingNextType|. 368 // |StartAssociatingNextType|.
303 StartAssociatingNextType(); 369 StartAssociatingNextType();
304 } 370 }
305 371
306 void ModelAssociationManager::ModelLoadCallback( 372 void ModelAssociationManager::ModelLoadCallback(
307 syncable::ModelType type, SyncError error) { 373 syncable::ModelType type, SyncError error) {
308 DCHECK_EQ(state_, CONFIGURING); 374 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback for "
309 375 << syncable::ModelTypeToString(type);
310 for (std::vector<DataTypeController*>::iterator it = 376 if (state_ == CONFIGURING) {
311 pending_model_load_.begin(); 377 DVLOG(1) << "ModelAssociationManager: ModelLoadCallback while configuring";
312 it != pending_model_load_.end(); 378 for (std::vector<DataTypeController*>::iterator it =
313 ++it) { 379 pending_model_load_.begin();
314 if ((*it)->type() == type) { 380 it != pending_model_load_.end();
315 DataTypeController* dtc = *it; 381 ++it) {
316 pending_model_load_.erase(it); 382 if ((*it)->type() == type) {
317 if (!error.IsSet()) { 383 // Each type is given |kDataTypeLoadWaitTimeInSeconds| time to load
318 waiting_to_associate_.push_back(dtc); 384 // (as controlled by the timer.). If the type does not load in that
319 StartAssociatingNextType(); 385 // time we move on to the next type. However if the type does
320 } else { 386 // finish loading in that time we want to stop the timer. We stop
321 // Treat it like a regular error. 387 // the timer, if the type that loaded is the same as the type that
322 DCHECK(currently_associating_ == NULL); 388 // we started the timer for(as indicated by the type on the head
323 currently_associating_ = dtc; 389 // of the list).
324 TypeStartCallback(DataTypeController::ASSOCIATION_FAILED, error); 390 // Note: Regardless of this timer value the associations will always
391 // take place serially. The only thing this timer controls is how serial
392 // the model load is. If this timer has a value of zero seconds then
393 // the model loads will all be parallel.
394 if (it == pending_model_load_.begin()) {
395 DVLOG(1) << "ModelAssociationManager: Stopping timer";
396 timer_.Stop();
397 }
398 DataTypeController* dtc = *it;
399 pending_model_load_.erase(it);
400 if (!error.IsSet()) {
401 DVLOG(1) << "ModelAssociationManager:"
402 << " Calling StartAssociatingNextType";
403 waiting_to_associate_.push_back(dtc);
404 StartAssociatingNextType();
405 } else {
406 DVLOG(1) << "ModelAssociationManager: Encountered error loading";
407 // Treat it like a regular error.
408 AppendToFailedDatatypesAndLogError(
409 DataTypeController::ASSOCIATION_FAILED,
410 error);
411 }
412 return;
325 } 413 }
326 return;
327 } 414 }
415 NOTREACHED();
416 return;
417 } else {
418 DVLOG(1) << "ModelAssociationManager: Models loaded after configure cycle"
419 << "Informing DTM";
420 // This datatype finished loading after the deadline imposed by the
421 // originating configuration cycle. Inform the DataTypeManager that the
422 // type has loaded, so that association may begin.
423 result_processor_->OnTypesLoaded();
328 } 424 }
329 425
330 NOTREACHED();
331 } 426 }
332 427
333
334 void ModelAssociationManager::StartAssociatingNextType() { 428 void ModelAssociationManager::StartAssociatingNextType() {
335 DCHECK_EQ(state_, CONFIGURING); 429 DCHECK_EQ(state_, CONFIGURING);
336 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL)); 430 DCHECK_EQ(currently_associating_, static_cast<DataTypeController*>(NULL));
431
432 DVLOG(1) << "ModelAssociationManager: StartAssociatingNextType";
337 if (!waiting_to_associate_.empty()) { 433 if (!waiting_to_associate_.empty()) {
338 DVLOG(1) << "Starting " << waiting_to_associate_[0]->name(); 434 DVLOG(1) << "ModelAssociationManager: Starting "
435 << waiting_to_associate_[0]->name();
339 TRACE_EVENT_BEGIN1("sync", "ModelAssociation", 436 TRACE_EVENT_BEGIN1("sync", "ModelAssociation",
340 "DataType", 437 "DataType",
341 ModelTypeToString(waiting_to_associate_[0]->type())); 438 ModelTypeToString(waiting_to_associate_[0]->type()));
342 DataTypeController* dtc = waiting_to_associate_[0]; 439 DataTypeController* dtc = waiting_to_associate_[0];
343 waiting_to_associate_.erase(waiting_to_associate_.begin()); 440 waiting_to_associate_.erase(waiting_to_associate_.begin());
344 currently_associating_ = dtc; 441 currently_associating_ = dtc;
345 dtc->StartAssociating(base::Bind( 442 dtc->StartAssociating(base::Bind(
346 &ModelAssociationManager::TypeStartCallback, 443 &ModelAssociationManager::TypeStartCallback,
347 weak_ptr_factory_.GetWeakPtr())); 444 weak_ptr_factory_.GetWeakPtr()));
348 return; 445 return;
349 } 446 }
350 447
351 // We are done with this cycle of association. 448 // We are done with this cycle of association.
352 state_ = IDLE; 449 state_ = IDLE;
353 // Do a fresh calculation to see if controllers need starting to account for 450 // Do a fresh calculation to see if controllers need starting to account for
354 // things like encryption, which may still need to be sorted out before we 451 // things like encryption, which may still need to be sorted out before we
355 // can announce we're "Done" configuration entirely. 452 // can announce we're "Done" configuration entirely.
356 if (GetControllersNeedingStart(NULL)) { 453 if (GetControllersNeedingStart(NULL)) {
357 DVLOG(1) << "GetControllersNeedingStart returned true." 454 DVLOG(1) << "ModelAssociationManager: GetControllersNeedingStart"
358 << " Blocking DataTypeManager"; 455 << " returned true. Blocking DataTypeManager";
359 456
360 DataTypeManager::ConfigureResult configure_result( 457 DataTypeManager::ConfigureResult configure_result(
361 DataTypeManager::CONFIGURE_BLOCKED, 458 DataTypeManager::CONFIGURE_BLOCKED,
362 desired_types_, 459 desired_types_,
363 failed_datatypes_info_); 460 failed_datatypes_info_,
461 syncable::ModelTypeSet());
364 state_ = IDLE; 462 state_ = IDLE;
365 result_processor_->OnModelAssociationDone(configure_result); 463 result_processor_->OnModelAssociationDone(configure_result);
366 return; 464 return;
367 } 465 }
368 466
369 DataTypeManager::ConfigureStatus configure_status = DataTypeManager::OK; 467 DataTypeManager::ConfigureStatus configure_status = DataTypeManager::OK;
370 if (!failed_datatypes_info_.empty()) 468
469 if (!failed_datatypes_info_.empty() ||
470 !GetTypesWaitingToLoad().Empty()) {
471 // We have not configured all types that we have been asked to configure.
472 // Either we have failed types or types that have not completed loading
473 // yet.
474 DVLOG(1) << "ModelAssociationManager: setting partial success";
371 configure_status = DataTypeManager::PARTIAL_SUCCESS; 475 configure_status = DataTypeManager::PARTIAL_SUCCESS;
476 }
372 477
373 DataTypeManager::ConfigureResult result(configure_status, 478 DataTypeManager::ConfigureResult result(configure_status,
374 desired_types_, 479 desired_types_,
375 failed_datatypes_info_); 480 failed_datatypes_info_,
481 GetTypesWaitingToLoad());
376 result_processor_->OnModelAssociationDone(result); 482 result_processor_->OnModelAssociationDone(result);
377 return; 483 return;
378 } 484 }
379 485
486 syncable::ModelTypeSet ModelAssociationManager::GetTypesWaitingToLoad() {
487 syncable::ModelTypeSet result;
488 for (std::vector<DataTypeController*>::const_iterator it =
489 pending_model_load_.begin();
490 it != pending_model_load_.end();
491 ++it) {
492 result.Put((*it)->type());
493 }
494 return result;
495 }
496
497 base::OneShotTimer<ModelAssociationManager>*
498 ModelAssociationManager::GetTimerForTesting() {
499 return &timer_;
500 }
501
380 } // namespace browser_sync 502 } // namespace browser_sync
381 503
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