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

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

Powered by Google App Engine
This is Rietveld 408576698