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

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

Issue 6690020: sync: hook up ServerConnectionManager <> SyncerThread2 and tie up more loose ends (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/debug
Patch Set: rebase Created 9 years, 9 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) 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // If our state is not determined then we should not have the autofill 338 // If our state is not determined then we should not have the autofill
339 // profile node. 339 // profile node.
340 DCHECK(false); 340 DCHECK(false);
341 341
342 // just set it as not migrated. 342 // just set it as not migrated.
343 SetAutofillMigrationState(syncable::NOT_MIGRATED); 343 SetAutofillMigrationState(syncable::NOT_MIGRATED);
344 return; 344 return;
345 } 345 }
346 } 346 }
347 347
348 SyncBackendHost::PendingConfigureDataTypesState::
349 PendingConfigureDataTypesState() : deleted_type(false) {}
350
348 void SyncBackendHost::ConfigureDataTypes( 351 void SyncBackendHost::ConfigureDataTypes(
349 const DataTypeController::TypeMap& data_type_controllers, 352 const DataTypeController::TypeMap& data_type_controllers,
350 const syncable::ModelTypeSet& types, 353 const syncable::ModelTypeSet& types,
351 CancelableTask* ready_task) { 354 CancelableTask* ready_task) {
352 // Only one configure is allowed at a time. 355 // Only one configure is allowed at a time.
353 DCHECK(!configure_ready_task_.get()); 356 DCHECK(!pending_config_mode_state_.get());
357 DCHECK(!pending_download_state_.get());
354 DCHECK(syncapi_initialized_); 358 DCHECK(syncapi_initialized_);
355 359
356 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { 360 if (types.count(syncable::AUTOFILL_PROFILE) != 0) {
357 ConfigureAutofillMigration(); 361 ConfigureAutofillMigration();
358 } 362 }
359 363
360 bool deleted_type = false; 364 scoped_ptr<PendingConfigureDataTypesState> state(new
361 syncable::ModelTypeBitSet added_types; 365 PendingConfigureDataTypesState());
362 366
363 { 367 {
364 base::AutoLock lock(registrar_lock_); 368 base::AutoLock lock(registrar_lock_);
365 for (DataTypeController::TypeMap::const_iterator it = 369 for (DataTypeController::TypeMap::const_iterator it =
366 data_type_controllers.begin(); 370 data_type_controllers.begin();
367 it != data_type_controllers.end(); ++it) { 371 it != data_type_controllers.end(); ++it) {
368 syncable::ModelType type = (*it).first; 372 syncable::ModelType type = (*it).first;
369 373
370 // If a type is not specified, remove it from the routing_info. 374 // If a type is not specified, remove it from the routing_info.
371 if (types.count(type) == 0) { 375 if (types.count(type) == 0) {
372 registrar_.routing_info.erase(type); 376 registrar_.routing_info.erase(type);
373 deleted_type = true; 377 state->deleted_type = true;
374 } else { 378 } else {
375 // Add a newly specified data type as GROUP_PASSIVE into the 379 // Add a newly specified data type as GROUP_PASSIVE into the
376 // routing_info, if it does not already exist. 380 // routing_info, if it does not already exist.
377 if (registrar_.routing_info.count(type) == 0) { 381 if (registrar_.routing_info.count(type) == 0) {
378 registrar_.routing_info[type] = GROUP_PASSIVE; 382 registrar_.routing_info[type] = GROUP_PASSIVE;
379 added_types.set(type); 383 state->added_types.set(type);
380 } 384 }
381 } 385 }
382 } 386 }
383 } 387 }
384 388
385 // If no new data types were added to the passive group, no need to 389 state->ready_task.reset(ready_task);
386 // wait for the syncer. 390 state->initial_types = types;
387 if (core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) { 391 pending_config_mode_state_.reset(state.release());
388 ready_task->Run(); 392
389 delete ready_task; 393 // If we're doing the first configure (at startup) this is redundant as the
394 // syncer thread always must start in config mode.
395 if (using_new_syncer_thread_) {
396 core_->syncapi()->StartConfigurationMode(NewCallback(core_.get(),
397 &SyncBackendHost::Core::FinishConfigureDataTypes));
390 } else { 398 } else {
391 // Save the task here so we can run it when the syncer finishes 399 FinishConfigureDataTypesOnFrontendLoop();
392 // initializing the new data types. It will be run only when the
393 // set of initially synced data types matches the types requested in
394 // this configure.
395 configure_ready_task_.reset(ready_task);
396 configure_initial_sync_types_ = types;
397 } 400 }
401 }
398 402
403 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() {
404 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
399 // Nudge the syncer. This is necessary for both datatype addition/deletion. 405 // Nudge the syncer. This is necessary for both datatype addition/deletion.
400 // 406 //
401 // Deletions need a nudge in order to ensure the deletion occurs in a timely 407 // Deletions need a nudge in order to ensure the deletion occurs in a timely
402 // manner (see issue 56416). 408 // manner (see issue 56416).
403 // 409 //
404 // In the case of additions, on the next sync cycle, the syncer should 410 // In the case of additions, on the next sync cycle, the syncer should
405 // notice that the routing info has changed and start the process of 411 // notice that the routing info has changed and start the process of
406 // downloading updates for newly added data types. Once this is 412 // downloading updates for newly added data types. Once this is
407 // complete, the configure_ready_task_ is run via an 413 // complete, the configure_state_.ready_task_ is run via an
408 // OnInitializationComplete notification. 414 // OnInitializationComplete notification.
409 ScheduleSyncEventForConfigChange(deleted_type, added_types); 415 bool need_download = false;
416 if (pending_config_mode_state_->deleted_type) {
Nicolas Zea 2011/03/25 18:53:03 Should we check pending_config_mode_state_.get() f
tim (not reviewing) 2011/03/28 20:02:25 Discussed offline, think this is fine.
417 if (using_new_syncer_thread_) {
418 core_thread_.message_loop()->PostTask(FROM_HERE,
419 NewRunnableMethod(core_.get(),
420 &SyncBackendHost::Core::DeferNudgeForCleanup));
421 } else {
422 need_download = true;
423 }
424 }
425
426 if (core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) {
427 pending_config_mode_state_->ready_task->Run();
428 } else {
429 if (!pending_config_mode_state_->added_types.any()) {
430 LOG(WARNING) << "No new types, but initial sync not finished."
431 << "Possible sync db corruption / removal.";
432 // TODO(tim): Log / UMA / count this somehow?
433 // TODO(tim): If no added types, we could (should?) config only for
434 // types that are needed... but this is a rare corruption edge case or
435 // implies the user mucked around with their syncdb, so for now do all.
436 pending_config_mode_state_->added_types =
437 syncable::ModelTypeBitSetFromSet(
438 pending_config_mode_state_->initial_types);
439 }
440 need_download = true;
441 }
442
443 if (need_download) {
Nicolas Zea 2011/03/25 18:53:03 Presumably with the new syncer implementation we c
tim (not reviewing) 2011/03/28 20:02:25 Discussed offline, we don't wind up here but Handl
444 pending_download_state_.reset(pending_config_mode_state_.release());
445 if (using_new_syncer_thread_) {
446 RequestConfig(pending_download_state_->added_types);
447 } else {
448 RequestNudge();
449 }
450 }
451
452 pending_config_mode_state_.reset();
410 453
411 // Notify the SyncManager about the new types. 454 // Notify the SyncManager about the new types.
412 core_thread_.message_loop()->PostTask(FROM_HERE, 455 core_thread_.message_loop()->PostTask(FROM_HERE,
413 NewRunnableMethod(core_.get(), 456 NewRunnableMethod(core_.get(),
414 &SyncBackendHost::Core::DoUpdateEnabledTypes)); 457 &SyncBackendHost::Core::DoUpdateEnabledTypes));
415 } 458 }
416 459
417 void SyncBackendHost::ScheduleSyncEventForConfigChange(bool deleted_type,
418 const syncable::ModelTypeBitSet& added_types) {
419 // We can only nudge when we've either deleted a dataype or added one, else
420 // we can cause unnecessary syncs. Unit tests cover this.
421 if (using_new_syncer_thread_) {
422 if (added_types.size() > 0)
423 RequestConfig(added_types);
424
425 // TODO(tim): Bug 76233. Fix this once only one impl exists.
426 if (deleted_type) {
427 core_thread_.message_loop()->PostTask(FROM_HERE,
428 NewRunnableMethod(core_.get(),
429 &SyncBackendHost::Core::DeferNudgeForCleanup));
430 }
431 } else if (deleted_type ||
432 !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) {
433 RequestNudge();
434 }
435 }
436
437 void SyncBackendHost::EncryptDataTypes( 460 void SyncBackendHost::EncryptDataTypes(
438 const syncable::ModelTypeSet& encrypted_types) { 461 const syncable::ModelTypeSet& encrypted_types) {
439 core_thread_.message_loop()->PostTask(FROM_HERE, 462 core_thread_.message_loop()->PostTask(FROM_HERE,
440 NewRunnableMethod(core_.get(), 463 NewRunnableMethod(core_.get(),
441 &SyncBackendHost::Core::DoEncryptDataTypes, 464 &SyncBackendHost::Core::DoEncryptDataTypes,
442 encrypted_types)); 465 encrypted_types));
443 } 466 }
444 467
445 void SyncBackendHost::RequestNudge() { 468 void SyncBackendHost::RequestNudge() {
446 core_thread_.message_loop()->PostTask(FROM_HERE, 469 core_thread_.message_loop()->PostTask(FROM_HERE,
447 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); 470 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge));
448 } 471 }
449 472
450 void SyncBackendHost::RequestConfig( 473 void SyncBackendHost::RequestConfig(
451 const syncable::ModelTypeBitSet& added_types) { 474 const syncable::ModelTypeBitSet& added_types) {
452 DCHECK(core_->syncapi()); 475 DCHECK(core_->syncapi());
453 core_->syncapi()->RequestConfig(added_types); 476
477 syncable::ModelTypeBitSet types_copy(added_types);
478 if (IsNigoriEnabled())
479 types_copy.set(syncable::NIGORI);
480
481 core_->syncapi()->RequestConfig(types_copy);
454 } 482 }
455 483
456 void SyncBackendHost::ActivateDataType( 484 void SyncBackendHost::ActivateDataType(
457 DataTypeController* data_type_controller, 485 DataTypeController* data_type_controller,
458 ChangeProcessor* change_processor) { 486 ChangeProcessor* change_processor) {
459 base::AutoLock lock(registrar_lock_); 487 base::AutoLock lock(registrar_lock_);
460 488
461 // Ensure that the given data type is in the PASSIVE group. 489 // Ensure that the given data type is in the PASSIVE group.
462 browser_sync::ModelSafeRoutingInfo::iterator i = 490 browser_sync::ModelSafeRoutingInfo::iterator i =
463 registrar_.routing_info.find(data_type_controller->type()); 491 registrar_.routing_info.find(data_type_controller->type());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 600 }
573 601
574 void SyncBackendHost::Core::NotifyEncryptionComplete( 602 void SyncBackendHost::Core::NotifyEncryptionComplete(
575 const syncable::ModelTypeSet& encrypted_types) { 603 const syncable::ModelTypeSet& encrypted_types) {
576 if (!host_) 604 if (!host_)
577 return; 605 return;
578 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 606 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
579 host_->frontend_->OnEncryptionComplete(encrypted_types); 607 host_->frontend_->OnEncryptionComplete(encrypted_types);
580 } 608 }
581 609
610 void SyncBackendHost::Core::FinishConfigureDataTypes() {
611 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
612 &SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop));
613 }
614
615 void SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop() {
616 host_->FinishConfigureDataTypesOnFrontendLoop();
617 }
618
582 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( 619 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions(
583 const GURL& service_url, 620 const GURL& service_url,
584 sync_api::HttpPostProviderFactory* http_bridge_factory, 621 sync_api::HttpPostProviderFactory* http_bridge_factory,
585 const sync_api::SyncCredentials& credentials, 622 const sync_api::SyncCredentials& credentials,
586 bool delete_sync_data_folder, 623 bool delete_sync_data_folder,
587 const std::string& restored_key_for_bootstrapping, 624 const std::string& restored_key_for_bootstrapping,
588 bool setup_for_test_mode) 625 bool setup_for_test_mode)
589 : service_url(service_url), 626 : service_url(service_url),
590 http_bridge_factory(http_bridge_factory), 627 http_bridge_factory(http_bridge_factory),
591 credentials(credentials), 628 credentials(credentials),
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 SyncSessionSnapshot* snapshot) { 895 SyncSessionSnapshot* snapshot) {
859 if (!host_ || !host_->frontend_) 896 if (!host_ || !host_->frontend_)
860 return; 897 return;
861 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 898 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
862 899
863 host_->last_snapshot_.reset(snapshot); 900 host_->last_snapshot_.reset(snapshot);
864 901
865 // If we are waiting for a configuration change, check here to see 902 // If we are waiting for a configuration change, check here to see
866 // if this sync cycle has initialized all of the types we've been 903 // if this sync cycle has initialized all of the types we've been
867 // waiting for. 904 // waiting for.
868 if (host_->configure_ready_task_.get()) { 905 if (host_->pending_download_state_.get()) {
869 bool found_all = true; 906 bool found_all_added = true;
870 for (syncable::ModelTypeSet::const_iterator it = 907 for (syncable::ModelTypeSet::const_iterator it =
871 host_->configure_initial_sync_types_.begin(); 908 host_->pending_download_state_->initial_types.begin();
872 it != host_->configure_initial_sync_types_.end(); ++it) { 909 it != host_->pending_download_state_->initial_types.end();
873 found_all &= snapshot->initial_sync_ended.test(*it); 910 ++it) {
911 if (host_->pending_download_state_->added_types.test(*it))
912 found_all_added &= snapshot->initial_sync_ended.test(*it);
874 } 913 }
875 914 if (!found_all_added) {
876 if (found_all) { 915 DCHECK(!host_->using_new_syncer_thread_);
877 host_->configure_ready_task_->Run(); 916 } else {
878 host_->configure_ready_task_.reset(); 917 host_->pending_download_state_->ready_task->Run();
879 host_->configure_initial_sync_types_.clear(); 918 host_->pending_download_state_.reset();
880 } 919 }
881 } 920 }
882 host_->frontend_->OnSyncCycleCompleted(); 921 host_->frontend_->OnSyncCycleCompleted();
883 } 922 }
884 923
885 void SyncBackendHost::Core::OnInitializationComplete() { 924 void SyncBackendHost::Core::OnInitializationComplete() {
886 if (!host_ || !host_->frontend_) 925 if (!host_ || !host_->frontend_)
887 return; // We may have been told to Shutdown before initialization 926 return; // We may have been told to Shutdown before initialization
888 // completed. 927 // completed.
889 928
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); 1174 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop());
1136 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); 1175 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender);
1137 } 1176 }
1138 1177
1139 void SyncBackendHost::Core::DeferNudgeForCleanup() { 1178 void SyncBackendHost::Core::DeferNudgeForCleanup() {
1140 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); 1179 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop());
1141 deferred_nudge_for_cleanup_requested_ = true; 1180 deferred_nudge_for_cleanup_requested_ = true;
1142 } 1181 }
1143 1182
1144 } // namespace browser_sync 1183 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698