OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 return; | 344 return; |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 SyncBackendHost::PendingConfigureDataTypesState:: | 348 SyncBackendHost::PendingConfigureDataTypesState:: |
349 PendingConfigureDataTypesState() : deleted_type(false) {} | 349 PendingConfigureDataTypesState() : deleted_type(false) {} |
350 | 350 |
351 SyncBackendHost::PendingConfigureDataTypesState:: | 351 SyncBackendHost::PendingConfigureDataTypesState:: |
352 ~PendingConfigureDataTypesState() {} | 352 ~PendingConfigureDataTypesState() {} |
353 | 353 |
354 // static | |
355 SyncBackendHost::PendingConfigureDataTypesState* | |
356 SyncBackendHost::MakePendingConfigModeState( | |
357 const DataTypeController::TypeMap& data_type_controllers, | |
358 const syncable::ModelTypeSet& types, | |
359 CancelableTask* ready_task, | |
360 ModelSafeRoutingInfo* routing_info) { | |
361 PendingConfigureDataTypesState* state = new PendingConfigureDataTypesState(); | |
362 | |
363 for (DataTypeController::TypeMap::const_iterator it = | |
364 data_type_controllers.begin(); | |
365 it != data_type_controllers.end(); ++it) { | |
366 syncable::ModelType type = it->first; | |
367 | |
368 // If a type is not specified, remove it from the routing_info. | |
369 if (types.count(type) == 0) { | |
370 state->deleted_type = (routing_info->erase(type) > 0); | |
tim (not reviewing)
2011/04/19 18:07:05
this line is wrong. we need to just set deleted_t
| |
371 } else { | |
372 // Add a newly specified data type as GROUP_PASSIVE into the | |
373 // routing_info, if it does not already exist. | |
374 if (routing_info->count(type) == 0) { | |
375 (*routing_info)[type] = GROUP_PASSIVE; | |
376 state->added_types.set(type); | |
377 } | |
378 } | |
379 } | |
380 | |
381 state->ready_task.reset(ready_task); | |
382 state->initial_types = types; | |
383 return state; | |
384 } | |
385 | |
354 void SyncBackendHost::ConfigureDataTypes( | 386 void SyncBackendHost::ConfigureDataTypes( |
355 const DataTypeController::TypeMap& data_type_controllers, | 387 const DataTypeController::TypeMap& data_type_controllers, |
356 const syncable::ModelTypeSet& types, | 388 const syncable::ModelTypeSet& types, |
357 CancelableTask* ready_task) { | 389 CancelableTask* ready_task) { |
358 // Only one configure is allowed at a time. | 390 // Only one configure is allowed at a time. |
359 DCHECK(!pending_config_mode_state_.get()); | 391 DCHECK(!pending_config_mode_state_.get()); |
360 DCHECK(!pending_download_state_.get()); | 392 DCHECK(!pending_download_state_.get()); |
361 DCHECK(syncapi_initialized_); | 393 DCHECK(syncapi_initialized_); |
362 | 394 |
363 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { | 395 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { |
364 ConfigureAutofillMigration(); | 396 ConfigureAutofillMigration(); |
365 } | 397 } |
366 | 398 |
367 scoped_ptr<PendingConfigureDataTypesState> state(new | |
368 PendingConfigureDataTypesState()); | |
369 | |
370 { | 399 { |
371 base::AutoLock lock(registrar_lock_); | 400 base::AutoLock lock(registrar_lock_); |
372 for (DataTypeController::TypeMap::const_iterator it = | 401 pending_config_mode_state_.reset( |
373 data_type_controllers.begin(); | 402 MakePendingConfigModeState(data_type_controllers, types, ready_task, |
374 it != data_type_controllers.end(); ++it) { | 403 ®istrar_.routing_info)); |
375 syncable::ModelType type = (*it).first; | |
376 | |
377 // If a type is not specified, remove it from the routing_info. | |
378 if (types.count(type) == 0) { | |
379 registrar_.routing_info.erase(type); | |
380 state->deleted_type = true; | |
381 } else { | |
382 // Add a newly specified data type as GROUP_PASSIVE into the | |
383 // routing_info, if it does not already exist. | |
384 if (registrar_.routing_info.count(type) == 0) { | |
385 registrar_.routing_info[type] = GROUP_PASSIVE; | |
386 state->added_types.set(type); | |
387 } | |
388 } | |
389 } | |
390 } | 404 } |
391 | 405 |
392 state->ready_task.reset(ready_task); | |
393 state->initial_types = types; | |
394 pending_config_mode_state_.reset(state.release()); | |
395 | |
396 // If we're doing the first configure (at startup) this is redundant as the | 406 // If we're doing the first configure (at startup) this is redundant as the |
397 // syncer thread always must start in config mode. | 407 // syncer thread always must start in config mode. |
398 if (using_new_syncer_thread_) { | 408 if (using_new_syncer_thread_) { |
399 core_->syncapi()->StartConfigurationMode(NewCallback(core_.get(), | 409 core_->syncapi()->StartConfigurationMode(NewCallback(core_.get(), |
400 &SyncBackendHost::Core::FinishConfigureDataTypes)); | 410 &SyncBackendHost::Core::FinishConfigureDataTypes)); |
401 } else { | 411 } else { |
402 FinishConfigureDataTypesOnFrontendLoop(); | 412 FinishConfigureDataTypesOnFrontendLoop(); |
403 } | 413 } |
404 } | 414 } |
405 | 415 |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1187 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1197 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
1188 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1198 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); |
1189 } | 1199 } |
1190 | 1200 |
1191 void SyncBackendHost::Core::DeferNudgeForCleanup() { | 1201 void SyncBackendHost::Core::DeferNudgeForCleanup() { |
1192 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1202 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
1193 deferred_nudge_for_cleanup_requested_ = true; | 1203 deferred_nudge_for_cleanup_requested_ = true; |
1194 } | 1204 } |
1195 | 1205 |
1196 } // namespace browser_sync | 1206 } // namespace browser_sync |
OLD | NEW |