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

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: fix 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 request_nudge = false;
416 if (pending_config_mode_state_->deleted_type) {
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 request_nudge = 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 pending_download_state_.reset(pending_config_mode_state_.release());
441 if (using_new_syncer_thread_) {
442 RequestConfig(pending_download_state_->added_types);
443 } else {
444 request_nudge = true;
445 }
446 }
447
448 if (request_nudge)
449 RequestNudge();
450
451 pending_config_mode_state_.reset();
410 452
411 // Notify the SyncManager about the new types. 453 // Notify the SyncManager about the new types.
412 core_thread_.message_loop()->PostTask(FROM_HERE, 454 core_thread_.message_loop()->PostTask(FROM_HERE,
413 NewRunnableMethod(core_.get(), 455 NewRunnableMethod(core_.get(),
414 &SyncBackendHost::Core::DoUpdateEnabledTypes)); 456 &SyncBackendHost::Core::DoUpdateEnabledTypes));
415 } 457 }
416 458
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( 459 void SyncBackendHost::EncryptDataTypes(
438 const syncable::ModelTypeSet& encrypted_types) { 460 const syncable::ModelTypeSet& encrypted_types) {
439 core_thread_.message_loop()->PostTask(FROM_HERE, 461 core_thread_.message_loop()->PostTask(FROM_HERE,
440 NewRunnableMethod(core_.get(), 462 NewRunnableMethod(core_.get(),
441 &SyncBackendHost::Core::DoEncryptDataTypes, 463 &SyncBackendHost::Core::DoEncryptDataTypes,
442 encrypted_types)); 464 encrypted_types));
443 } 465 }
444 466
445 void SyncBackendHost::RequestNudge() { 467 void SyncBackendHost::RequestNudge() {
446 core_thread_.message_loop()->PostTask(FROM_HERE, 468 core_thread_.message_loop()->PostTask(FROM_HERE,
447 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); 469 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge));
448 } 470 }
449 471
450 void SyncBackendHost::RequestConfig( 472 void SyncBackendHost::RequestConfig(
451 const syncable::ModelTypeBitSet& added_types) { 473 const syncable::ModelTypeBitSet& added_types) {
452 DCHECK(core_->syncapi()); 474 DCHECK(core_->syncapi());
453 core_->syncapi()->RequestConfig(added_types); 475
476 syncable::ModelTypeBitSet types_copy(added_types);
477 if (IsNigoriEnabled())
478 types_copy.set(syncable::NIGORI);
479
480 core_->syncapi()->RequestConfig(types_copy);
454 } 481 }
455 482
456 void SyncBackendHost::ActivateDataType( 483 void SyncBackendHost::ActivateDataType(
457 DataTypeController* data_type_controller, 484 DataTypeController* data_type_controller,
458 ChangeProcessor* change_processor) { 485 ChangeProcessor* change_processor) {
459 base::AutoLock lock(registrar_lock_); 486 base::AutoLock lock(registrar_lock_);
460 487
461 // Ensure that the given data type is in the PASSIVE group. 488 // Ensure that the given data type is in the PASSIVE group.
462 browser_sync::ModelSafeRoutingInfo::iterator i = 489 browser_sync::ModelSafeRoutingInfo::iterator i =
463 registrar_.routing_info.find(data_type_controller->type()); 490 registrar_.routing_info.find(data_type_controller->type());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 599 }
573 600
574 void SyncBackendHost::Core::NotifyEncryptionComplete( 601 void SyncBackendHost::Core::NotifyEncryptionComplete(
575 const syncable::ModelTypeSet& encrypted_types) { 602 const syncable::ModelTypeSet& encrypted_types) {
576 if (!host_) 603 if (!host_)
577 return; 604 return;
578 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 605 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
579 host_->frontend_->OnEncryptionComplete(encrypted_types); 606 host_->frontend_->OnEncryptionComplete(encrypted_types);
580 } 607 }
581 608
609 void SyncBackendHost::Core::FinishConfigureDataTypes() {
610 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
611 &SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop));
612 }
613
614 void SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop() {
615 host_->FinishConfigureDataTypesOnFrontendLoop();
616 }
617
582 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( 618 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions(
583 const GURL& service_url, 619 const GURL& service_url,
584 sync_api::HttpPostProviderFactory* http_bridge_factory, 620 sync_api::HttpPostProviderFactory* http_bridge_factory,
585 const sync_api::SyncCredentials& credentials, 621 const sync_api::SyncCredentials& credentials,
586 bool delete_sync_data_folder, 622 bool delete_sync_data_folder,
587 const std::string& restored_key_for_bootstrapping, 623 const std::string& restored_key_for_bootstrapping,
588 bool setup_for_test_mode) 624 bool setup_for_test_mode)
589 : service_url(service_url), 625 : service_url(service_url),
590 http_bridge_factory(http_bridge_factory), 626 http_bridge_factory(http_bridge_factory),
591 credentials(credentials), 627 credentials(credentials),
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 SyncSessionSnapshot* snapshot) { 894 SyncSessionSnapshot* snapshot) {
859 if (!host_ || !host_->frontend_) 895 if (!host_ || !host_->frontend_)
860 return; 896 return;
861 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 897 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
862 898
863 host_->last_snapshot_.reset(snapshot); 899 host_->last_snapshot_.reset(snapshot);
864 900
865 // If we are waiting for a configuration change, check here to see 901 // 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 902 // if this sync cycle has initialized all of the types we've been
867 // waiting for. 903 // waiting for.
868 if (host_->configure_ready_task_.get()) { 904 if (host_->pending_download_state_.get()) {
869 bool found_all = true; 905 bool found_all_added = true;
870 for (syncable::ModelTypeSet::const_iterator it = 906 for (syncable::ModelTypeSet::const_iterator it =
871 host_->configure_initial_sync_types_.begin(); 907 host_->pending_download_state_->initial_types.begin();
872 it != host_->configure_initial_sync_types_.end(); ++it) { 908 it != host_->pending_download_state_->initial_types.end();
873 found_all &= snapshot->initial_sync_ended.test(*it); 909 ++it) {
910 if (host_->pending_download_state_->added_types.test(*it))
911 found_all_added &= snapshot->initial_sync_ended.test(*it);
874 } 912 }
875 913 if (!found_all_added) {
876 if (found_all) { 914 CHECK(false);
877 host_->configure_ready_task_->Run(); 915 DCHECK(!host_->using_new_syncer_thread_);
878 host_->configure_ready_task_.reset(); 916 } else {
879 host_->configure_initial_sync_types_.clear(); 917 host_->pending_download_state_->ready_task->Run();
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
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698