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

Side by Side Diff: components/sync_driver/model_association_manager.cc

Issue 317453002: sync: cut a few profile deps from DataTypeControllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move OnUserShareReady Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sync_driver/model_association_manager.h" 5 #include "components/sync_driver/model_association_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 syncer_merge_result.pre_association_version(); 103 syncer_merge_result.pre_association_version();
104 stats.association_wait_time = association_wait_time; 104 stats.association_wait_time = association_wait_time;
105 stats.association_time = association_time; 105 stats.association_time = association_time;
106 return stats; 106 return stats;
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 110
111 ModelAssociationManager::ModelAssociationManager( 111 ModelAssociationManager::ModelAssociationManager(
112 const DataTypeController::TypeMap* controllers, 112 const DataTypeController::TypeMap* controllers,
113 ModelAssociationResultProcessor* processor) 113 ModelAssociationManagerDelegate* processor)
114 : state_(IDLE), 114 : state_(IDLE),
115 controllers_(controllers), 115 controllers_(controllers),
116 result_processor_(processor), 116 delegate_(processor),
117 weak_ptr_factory_(this), 117 weak_ptr_factory_(this),
118 configure_status_(DataTypeManager::UNKNOWN) { 118 configure_status_(DataTypeManager::UNKNOWN) {
119 // Ensure all data type controllers are stopped. 119 // Ensure all data type controllers are stopped.
120 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 120 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
121 it != controllers_->end(); ++it) { 121 it != controllers_->end(); ++it) {
122 DCHECK_EQ(DataTypeController::NOT_RUNNING, (*it).second->state()); 122 DCHECK_EQ(DataTypeController::NOT_RUNNING, (*it).second->state());
123 } 123 }
124 } 124 }
125 125
126 ModelAssociationManager::~ModelAssociationManager() { 126 ModelAssociationManager::~ModelAssociationManager() {
(...skipping 16 matching lines...) Expand all
143 143
144 DVLOG(1) << "ModelAssociationManager: Initializing for " 144 DVLOG(1) << "ModelAssociationManager: Initializing for "
145 << syncer::ModelTypeSetToString(desired_types_); 145 << syncer::ModelTypeSetToString(desired_types_);
146 146
147 state_ = INITIALIZED_TO_CONFIGURE; 147 state_ = INITIALIZED_TO_CONFIGURE;
148 148
149 StopDisabledTypes(); 149 StopDisabledTypes();
150 LoadEnabledTypes(); 150 LoadEnabledTypes();
151 } 151 }
152 152
153 void ModelAssociationManager::StopDatatype(DataTypeController* dtc) {
154 // First tell the sync backend that we no longer want to listen to
155 // changes for this type.
156 delegate_->OnSingleDataTypeWillStop(dtc->type());
157
158 // Then tell all data type specific logic to shut down.
159 dtc->Stop();
160 }
161
153 void ModelAssociationManager::StopDisabledTypes() { 162 void ModelAssociationManager::StopDisabledTypes() {
154 DVLOG(1) << "ModelAssociationManager: Stopping disabled types."; 163 DVLOG(1) << "ModelAssociationManager: Stopping disabled types.";
155 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 164 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
156 it != controllers_->end(); ++it) { 165 it != controllers_->end(); ++it) {
157 DataTypeController* dtc = (*it).second.get(); 166 DataTypeController* dtc = (*it).second.get();
158 if (dtc->state() != DataTypeController::NOT_RUNNING && 167 if (dtc->state() != DataTypeController::NOT_RUNNING &&
159 (!desired_types_.Has(dtc->type()) || 168 (!desired_types_.Has(dtc->type()) ||
160 failed_data_types_info_.count(dtc->type()) > 0)) { 169 failed_data_types_info_.count(dtc->type()) > 0)) {
161 DVLOG(1) << "ModelTypeToString: stop " << dtc->name(); 170 DVLOG(1) << "ModelTypeToString: stop " << dtc->name();
162 dtc->Stop(); 171 StopDatatype(dtc);
163
164 loaded_types_.Remove(dtc->type()); 172 loaded_types_.Remove(dtc->type());
165 associated_types_.Remove(dtc->type()); 173 associated_types_.Remove(dtc->type());
166 } 174 }
167 } 175 }
168 } 176 }
169 177
170 void ModelAssociationManager::LoadEnabledTypes() { 178 void ModelAssociationManager::LoadEnabledTypes() {
171 // Load in kStartOrder. 179 // Load in kStartOrder.
172 for (size_t i = 0; i < arraysize(kStartOrder); i++) { 180 for (size_t i = 0; i < arraysize(kStartOrder); i++) {
173 syncer::ModelType type = kStartOrder[i]; 181 syncer::ModelType type = kStartOrder[i];
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 262
255 void ModelAssociationManager::Stop() { 263 void ModelAssociationManager::Stop() {
256 // Ignore callbacks from controllers. 264 // Ignore callbacks from controllers.
257 weak_ptr_factory_.InvalidateWeakPtrs(); 265 weak_ptr_factory_.InvalidateWeakPtrs();
258 266
259 // Stop started data types. 267 // Stop started data types.
260 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin(); 268 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
261 it != controllers_->end(); ++it) { 269 it != controllers_->end(); ++it) {
262 DataTypeController* dtc = (*it).second.get(); 270 DataTypeController* dtc = (*it).second.get();
263 if (dtc->state() != DataTypeController::NOT_RUNNING) { 271 if (dtc->state() != DataTypeController::NOT_RUNNING) {
264 dtc->Stop(); 272 StopDatatype(dtc);
265 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name(); 273 DVLOG(1) << "ModelAssociationManager: Stopped " << dtc->name();
266 } 274 }
267 } 275 }
268 276
269 desired_types_.Clear(); 277 desired_types_.Clear();
270 loaded_types_.Clear(); 278 loaded_types_.Clear();
271 associated_types_.Clear(); 279 associated_types_.Clear();
272 slow_types_.Clear(); 280 slow_types_.Clear();
273 281
274 if (state_ == CONFIGURING) { 282 if (state_ == CONFIGURING) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 354
347 DCHECK(!associated_types_.Has(type)); 355 DCHECK(!associated_types_.Has(type));
348 if (DataTypeController::IsSuccessfulResult(start_result)) { 356 if (DataTypeController::IsSuccessfulResult(start_result)) {
349 associated_types_.Put(type); 357 associated_types_.Put(type);
350 } else if (state_ == IDLE) { 358 } else if (state_ == IDLE) {
351 // For type that failed in IDLE mode, simply stop the controller. Next 359 // For type that failed in IDLE mode, simply stop the controller. Next
352 // configuration will try to restart from scratch if the type is still 360 // configuration will try to restart from scratch if the type is still
353 // enabled. 361 // enabled.
354 DataTypeController* dtc = controllers_->find(type)->second.get(); 362 DataTypeController* dtc = controllers_->find(type)->second.get();
355 if (dtc->state() != DataTypeController::NOT_RUNNING) 363 if (dtc->state() != DataTypeController::NOT_RUNNING)
356 dtc->Stop(); 364 StopDatatype(dtc);
357 loaded_types_.Remove(type); 365 loaded_types_.Remove(type);
358 } else { 366 } else {
359 // Record error in CONFIGURING or INITIALIZED_TO_CONFIGURE mode. The error 367 // Record error in CONFIGURING or INITIALIZED_TO_CONFIGURE mode. The error
360 // will be reported when data types association finishes. 368 // will be reported when data types association finishes.
361 if (start_result == DataTypeController::NEEDS_CRYPTO) { 369 if (start_result == DataTypeController::NEEDS_CRYPTO) {
362 DVLOG(1) << "ModelAssociationManager: Encountered an undecryptable type"; 370 DVLOG(1) << "ModelAssociationManager: Encountered an undecryptable type";
363 needs_crypto_types_.Put(type); 371 needs_crypto_types_.Put(type);
364 } else { 372 } else {
365 DVLOG(1) << "ModelAssociationManager: Encountered a failed type"; 373 DVLOG(1) << "ModelAssociationManager: Encountered a failed type";
366 AppendToFailedDatatypesAndLogError(local_merge_result.error()); 374 AppendToFailedDatatypesAndLogError(local_merge_result.error());
(...skipping 15 matching lines...) Expand all
382 syncer::ProtocolTypes().Has(type)) { 390 syncer::ProtocolTypes().Has(type)) {
383 base::TimeDelta association_wait_time = 391 base::TimeDelta association_wait_time =
384 std::max(base::TimeDelta(), type_start_time - association_start_time_); 392 std::max(base::TimeDelta(), type_start_time - association_start_time_);
385 base::TimeDelta association_time = 393 base::TimeDelta association_time =
386 base::TimeTicks::Now() - type_start_time;; 394 base::TimeTicks::Now() - type_start_time;;
387 syncer::DataTypeAssociationStats stats = 395 syncer::DataTypeAssociationStats stats =
388 BuildAssociationStatsFromMergeResults(local_merge_result, 396 BuildAssociationStatsFromMergeResults(local_merge_result,
389 syncer_merge_result, 397 syncer_merge_result,
390 association_wait_time, 398 association_wait_time,
391 association_time); 399 association_time);
392 result_processor_->OnSingleDataTypeAssociationDone(type, stats); 400 delegate_->OnSingleDataTypeAssociationDone(type, stats);
393 } 401 }
394 402
395 // Update configuration result. 403 // Update configuration result.
396 if (configure_status_ == DataTypeManager::OK && 404 if (configure_status_ == DataTypeManager::OK &&
397 start_result == DataTypeController::ASSOCIATION_FAILED) { 405 start_result == DataTypeController::ASSOCIATION_FAILED) {
398 configure_status_ = DataTypeManager::PARTIAL_SUCCESS; 406 configure_status_ = DataTypeManager::PARTIAL_SUCCESS;
399 } 407 }
400 if (start_result == DataTypeController::UNRECOVERABLE_ERROR) 408 if (start_result == DataTypeController::UNRECOVERABLE_ERROR)
401 configure_status_ = DataTypeManager::UNRECOVERABLE_ERROR; 409 configure_status_ = DataTypeManager::UNRECOVERABLE_ERROR;
402 410
(...skipping 30 matching lines...) Expand all
433 DVLOG(1) << "ModelAssociationManager: setting partial success"; 441 DVLOG(1) << "ModelAssociationManager: setting partial success";
434 configure_status_ = DataTypeManager::PARTIAL_SUCCESS; 442 configure_status_ = DataTypeManager::PARTIAL_SUCCESS;
435 } 443 }
436 444
437 DataTypeManager::ConfigureResult result(configure_status_, 445 DataTypeManager::ConfigureResult result(configure_status_,
438 requested_types_, 446 requested_types_,
439 failed_data_types_info_, 447 failed_data_types_info_,
440 associating_types_, 448 associating_types_,
441 needs_crypto_types_); 449 needs_crypto_types_);
442 450
443 // Reset state before notifying |result_processor_| because that might 451 // Reset state before notifying |delegate_| because that might
444 // trigger a new round of configuration. 452 // trigger a new round of configuration.
445 ResetForNextAssociation(); 453 ResetForNextAssociation();
446 state_ = IDLE; 454 state_ = IDLE;
447 455
448 result_processor_->OnModelAssociationDone(result); 456 delegate_->OnModelAssociationDone(result);
449 } 457 }
450 458
451 base::OneShotTimer<ModelAssociationManager>* 459 base::OneShotTimer<ModelAssociationManager>*
452 ModelAssociationManager::GetTimerForTesting() { 460 ModelAssociationManager::GetTimerForTesting() {
453 return &timer_; 461 return &timer_;
454 } 462 }
455 463
456 } // namespace browser_sync 464 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/model_association_manager.h ('k') | components/sync_driver/model_association_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698