| OLD | NEW |
| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 registrar_.reset(); | 417 registrar_.reset(); |
| 418 frontend_ = NULL; | 418 frontend_ = NULL; |
| 419 core_ = NULL; // Releases reference to core_. | 419 core_ = NULL; // Releases reference to core_. |
| 420 } | 420 } |
| 421 | 421 |
| 422 void SyncBackendHost::ConfigureDataTypes( | 422 void SyncBackendHost::ConfigureDataTypes( |
| 423 syncable::ModelTypeSet types_to_add, | 423 syncable::ModelTypeSet types_to_add, |
| 424 syncable::ModelTypeSet types_to_remove, | 424 syncable::ModelTypeSet types_to_remove, |
| 425 sync_api::ConfigureReason reason, | 425 sync_api::ConfigureReason reason, |
| 426 base::Callback<void(syncable::ModelTypeSet)> ready_task, | 426 base::Callback<void(syncable::ModelTypeSet)> ready_task, |
| 427 base::Callback<void()> retry_callback, |
| 427 bool enable_nigori) { | 428 bool enable_nigori) { |
| 428 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; | 429 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; |
| 429 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; | 430 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; |
| 430 if (enable_nigori) { | 431 if (enable_nigori) { |
| 431 types_to_add_with_nigori.Put(syncable::NIGORI); | 432 types_to_add_with_nigori.Put(syncable::NIGORI); |
| 432 types_to_remove_with_nigori.Remove(syncable::NIGORI); | 433 types_to_remove_with_nigori.Remove(syncable::NIGORI); |
| 433 } else { | 434 } else { |
| 434 types_to_add_with_nigori.Remove(syncable::NIGORI); | 435 types_to_add_with_nigori.Remove(syncable::NIGORI); |
| 435 types_to_remove_with_nigori.Put(syncable::NIGORI); | 436 types_to_remove_with_nigori.Put(syncable::NIGORI); |
| 436 } | 437 } |
| 437 // Only one configure is allowed at a time. | 438 // Only one configure is allowed at a time. |
| 438 DCHECK(!pending_config_mode_state_.get()); | 439 DCHECK(!pending_config_mode_state_.get()); |
| 439 DCHECK(!pending_download_state_.get()); | 440 DCHECK(!pending_download_state_.get()); |
| 440 DCHECK_GT(initialization_state_, NOT_INITIALIZED); | 441 DCHECK_GT(initialization_state_, NOT_INITIALIZED); |
| 441 | 442 |
| 442 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); | 443 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); |
| 443 pending_config_mode_state_->ready_task = ready_task; | 444 pending_config_mode_state_->ready_task = ready_task; |
| 444 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; | 445 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; |
| 445 pending_config_mode_state_->added_types = | 446 pending_config_mode_state_->added_types = |
| 446 registrar_->ConfigureDataTypes(types_to_add_with_nigori, | 447 registrar_->ConfigureDataTypes(types_to_add_with_nigori, |
| 447 types_to_remove_with_nigori); | 448 types_to_remove_with_nigori); |
| 448 pending_config_mode_state_->reason = reason; | 449 pending_config_mode_state_->reason = reason; |
| 450 pending_config_mode_state_->retry_callback = retry_callback; |
| 449 | 451 |
| 450 // Cleanup disabled types before starting configuration so that | 452 // Cleanup disabled types before starting configuration so that |
| 451 // callers can assume that the data types are cleaned up once | 453 // callers can assume that the data types are cleaned up once |
| 452 // configuration is done. | 454 // configuration is done. |
| 453 if (!types_to_remove_with_nigori.Empty()) { | 455 if (!types_to_remove_with_nigori.Empty()) { |
| 454 sync_thread_.message_loop()->PostTask( | 456 sync_thread_.message_loop()->PostTask( |
| 455 FROM_HERE, | 457 FROM_HERE, |
| 456 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes, | 458 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes, |
| 457 core_.get())); | 459 core_.get())); |
| 458 } | 460 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 577 |
| 576 // Process any changes to the datatypes we're syncing. | 578 // Process any changes to the datatypes we're syncing. |
| 577 // TODO(sync): add support for removing types. | 579 // TODO(sync): add support for removing types. |
| 578 if (initialized()) | 580 if (initialized()) |
| 579 AddExperimentalTypes(); | 581 AddExperimentalTypes(); |
| 580 | 582 |
| 581 // If we are waiting for a configuration change, check here to see | 583 // If we are waiting for a configuration change, check here to see |
| 582 // if this sync cycle has initialized all of the types we've been | 584 // if this sync cycle has initialized all of the types we've been |
| 583 // waiting for. | 585 // waiting for. |
| 584 if (pending_download_state_.get()) { | 586 if (pending_download_state_.get()) { |
| 585 scoped_ptr<PendingConfigureDataTypesState> state( | 587 const syncable::ModelTypeSet types_to_add = |
| 586 pending_download_state_.release()); | 588 pending_download_state_->types_to_add; |
| 587 const syncable::ModelTypeSet types_to_add = state->types_to_add; | 589 const syncable::ModelTypeSet added_types = |
| 588 const syncable::ModelTypeSet added_types = state->added_types; | 590 pending_download_state_->added_types; |
| 589 DCHECK(types_to_add.HasAll(added_types)); | 591 DCHECK(types_to_add.HasAll(added_types)); |
| 590 const syncable::ModelTypeSet initial_sync_ended = | 592 const syncable::ModelTypeSet initial_sync_ended = |
| 591 snapshot->initial_sync_ended; | 593 snapshot->initial_sync_ended; |
| 592 const syncable::ModelTypeSet failed_configuration_types = | 594 const syncable::ModelTypeSet failed_configuration_types = |
| 593 Difference(added_types, initial_sync_ended); | 595 Difference(added_types, initial_sync_ended); |
| 594 SDVLOG(1) | 596 SDVLOG(1) |
| 595 << "Added types: " | 597 << "Added types: " |
| 596 << syncable::ModelTypeSetToString(added_types) | 598 << syncable::ModelTypeSetToString(added_types) |
| 597 << ", configured types: " | 599 << ", configured types: " |
| 598 << syncable::ModelTypeSetToString(initial_sync_ended) | 600 << syncable::ModelTypeSetToString(initial_sync_ended) |
| 599 << ", failed configuration types: " | 601 << ", failed configuration types: " |
| 600 << syncable::ModelTypeSetToString(failed_configuration_types); | 602 << syncable::ModelTypeSetToString(failed_configuration_types); |
| 603 |
| 604 if (!failed_configuration_types.Empty() && |
| 605 snapshot->retry_scheduled) { |
| 606 // Inform the caller that download failed but we are retrying. |
| 607 if (!pending_download_state_->retry_in_progress) { |
| 608 pending_download_state_->retry_callback.Run(); |
| 609 pending_download_state_->retry_in_progress = true; |
| 610 } |
| 611 // Nothing more to do. |
| 612 return; |
| 613 } |
| 614 |
| 615 scoped_ptr<PendingConfigureDataTypesState> state( |
| 616 pending_download_state_.release()); |
| 601 state->ready_task.Run(failed_configuration_types); | 617 state->ready_task.Run(failed_configuration_types); |
| 618 |
| 619 // Syncer did not report an error but did not download everything |
| 620 // we requested either. So abort. The caller of the config will cleanup. |
| 602 if (!failed_configuration_types.Empty()) | 621 if (!failed_configuration_types.Empty()) |
| 603 return; | 622 return; |
| 604 } | 623 } |
| 605 | 624 |
| 606 if (initialized()) | 625 if (initialized()) |
| 607 frontend_->OnSyncCycleCompleted(); | 626 frontend_->OnSyncCycleCompleted(); |
| 608 } | 627 } |
| 609 | 628 |
| 610 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() { | 629 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() { |
| 611 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 630 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 DCHECK(backend.get()); | 745 DCHECK(backend.get()); |
| 727 } | 746 } |
| 728 | 747 |
| 729 SyncBackendHost::Core::~Core() { | 748 SyncBackendHost::Core::~Core() { |
| 730 DCHECK(!sync_manager_.get()); | 749 DCHECK(!sync_manager_.get()); |
| 731 DCHECK(!sync_loop_); | 750 DCHECK(!sync_loop_); |
| 732 } | 751 } |
| 733 | 752 |
| 734 SyncBackendHost::PendingConfigureDataTypesState:: | 753 SyncBackendHost::PendingConfigureDataTypesState:: |
| 735 PendingConfigureDataTypesState() | 754 PendingConfigureDataTypesState() |
| 736 : reason(sync_api::CONFIGURE_REASON_UNKNOWN) {} | 755 : reason(sync_api::CONFIGURE_REASON_UNKNOWN), |
| 756 retry_in_progress(false) {} |
| 737 | 757 |
| 738 SyncBackendHost::PendingConfigureDataTypesState:: | 758 SyncBackendHost::PendingConfigureDataTypesState:: |
| 739 ~PendingConfigureDataTypesState() {} | 759 ~PendingConfigureDataTypesState() {} |
| 740 | 760 |
| 741 void SyncBackendHost::Core::OnSyncCycleCompleted( | 761 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| 742 const SyncSessionSnapshot* snapshot) { | 762 const SyncSessionSnapshot* snapshot) { |
| 743 if (!sync_loop_) | 763 if (!sync_loop_) |
| 744 return; | 764 return; |
| 745 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 765 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 746 host_.Call( | 766 host_.Call( |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 sync_manager_->SaveChanges(); | 1072 sync_manager_->SaveChanges(); |
| 1053 } | 1073 } |
| 1054 | 1074 |
| 1055 void SyncBackendHost::AddExperimentalTypes() { | 1075 void SyncBackendHost::AddExperimentalTypes() { |
| 1056 CHECK(initialized()); | 1076 CHECK(initialized()); |
| 1057 syncable::ModelTypeSet to_add; | 1077 syncable::ModelTypeSet to_add; |
| 1058 if (core_->sync_manager()->ReceivedExperimentalTypes(&to_add)) | 1078 if (core_->sync_manager()->ReceivedExperimentalTypes(&to_add)) |
| 1059 frontend_->OnDataTypesChanged(to_add); | 1079 frontend_->OnDataTypesChanged(to_add); |
| 1060 } | 1080 } |
| 1061 | 1081 |
| 1082 void SyncBackendHost::OnNigoriDownloadRetry() { |
| 1083 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1084 if (!frontend_) |
| 1085 return; |
| 1086 |
| 1087 frontend_->OnSyncConfigureRetry(); |
| 1088 } |
| 1089 |
| 1062 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( | 1090 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
| 1063 const WeakHandle<JsBackend>& js_backend, bool success) { | 1091 const WeakHandle<JsBackend>& js_backend, bool success) { |
| 1064 DCHECK_NE(NOT_ATTEMPTED, initialization_state_); | 1092 DCHECK_NE(NOT_ATTEMPTED, initialization_state_); |
| 1065 if (!frontend_) | 1093 if (!frontend_) |
| 1066 return; | 1094 return; |
| 1067 | 1095 |
| 1068 // We've at least created the sync manager at this point, but if that is all | 1096 // We've at least created the sync manager at this point, but if that is all |
| 1069 // we've done we're just beginning the initialization process. | 1097 // we've done we're just beginning the initialization process. |
| 1070 if (initialization_state_ == CREATING_SYNC_MANAGER) | 1098 if (initialization_state_ == CREATING_SYNC_MANAGER) |
| 1071 initialization_state_ = NOT_INITIALIZED; | 1099 initialization_state_ = NOT_INITIALIZED; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1091 initialization_state_ = DOWNLOADING_NIGORI; | 1119 initialization_state_ = DOWNLOADING_NIGORI; |
| 1092 ConfigureDataTypes( | 1120 ConfigureDataTypes( |
| 1093 syncable::ModelTypeSet(), | 1121 syncable::ModelTypeSet(), |
| 1094 syncable::ModelTypeSet(), | 1122 syncable::ModelTypeSet(), |
| 1095 sync_api::CONFIGURE_REASON_NEW_CLIENT, | 1123 sync_api::CONFIGURE_REASON_NEW_CLIENT, |
| 1096 // Calls back into this function. | 1124 // Calls back into this function. |
| 1097 base::Bind( | 1125 base::Bind( |
| 1098 &SyncBackendHost:: | 1126 &SyncBackendHost:: |
| 1099 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1127 HandleNigoriConfigurationCompletedOnFrontendLoop, |
| 1100 weak_ptr_factory_.GetWeakPtr(), js_backend), | 1128 weak_ptr_factory_.GetWeakPtr(), js_backend), |
| 1129 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| 1130 weak_ptr_factory_.GetWeakPtr()), |
| 1101 true); | 1131 true); |
| 1102 break; | 1132 break; |
| 1103 case DOWNLOADING_NIGORI: | 1133 case DOWNLOADING_NIGORI: |
| 1104 initialization_state_ = REFRESHING_NIGORI; | 1134 initialization_state_ = REFRESHING_NIGORI; |
| 1105 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1135 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
| 1106 // if necessary. | 1136 // if necessary. |
| 1107 RefreshNigori( | 1137 RefreshNigori( |
| 1108 base::Bind( | 1138 base::Bind( |
| 1109 &SyncBackendHost:: | 1139 &SyncBackendHost:: |
| 1110 HandleInitializationCompletedOnFrontendLoop, | 1140 HandleInitializationCompletedOnFrontendLoop, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 FROM_HERE, | 1295 FROM_HERE, |
| 1266 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1296 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1267 core_.get(), sync_thread_done_callback)); | 1297 core_.get(), sync_thread_done_callback)); |
| 1268 } | 1298 } |
| 1269 | 1299 |
| 1270 #undef SDVLOG | 1300 #undef SDVLOG |
| 1271 | 1301 |
| 1272 #undef SLOG | 1302 #undef SLOG |
| 1273 | 1303 |
| 1274 } // namespace browser_sync | 1304 } // namespace browser_sync |
| OLD | NEW |