| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 virtual void OnConnectionStatusChange( | 90 virtual void OnConnectionStatusChange( |
| 91 sync_api::ConnectionStatus status) OVERRIDE; | 91 sync_api::ConnectionStatus status) OVERRIDE; |
| 92 virtual void OnPassphraseRequired( | 92 virtual void OnPassphraseRequired( |
| 93 sync_api::PassphraseRequiredReason reason, | 93 sync_api::PassphraseRequiredReason reason, |
| 94 const sync_pb::EncryptedData& pending_keys) OVERRIDE; | 94 const sync_pb::EncryptedData& pending_keys) OVERRIDE; |
| 95 virtual void OnPassphraseAccepted() OVERRIDE; | 95 virtual void OnPassphraseAccepted() OVERRIDE; |
| 96 virtual void OnBootstrapTokenUpdated( | 96 virtual void OnBootstrapTokenUpdated( |
| 97 const std::string& bootstrap_token) OVERRIDE; | 97 const std::string& bootstrap_token) OVERRIDE; |
| 98 virtual void OnStopSyncingPermanently() OVERRIDE; | 98 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 100 virtual void OnClearServerDataFailed() OVERRIDE; | |
| 101 virtual void OnClearServerDataSucceeded() OVERRIDE; | |
| 102 virtual void OnEncryptedTypesChanged( | 100 virtual void OnEncryptedTypesChanged( |
| 103 syncable::ModelTypeSet encrypted_types, | 101 syncable::ModelTypeSet encrypted_types, |
| 104 bool encrypt_everything) OVERRIDE; | 102 bool encrypt_everything) OVERRIDE; |
| 105 virtual void OnEncryptionComplete() OVERRIDE; | 103 virtual void OnEncryptionComplete() OVERRIDE; |
| 106 virtual void OnActionableError( | 104 virtual void OnActionableError( |
| 107 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; | 105 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; |
| 108 | 106 |
| 109 // Note: | 107 // Note: |
| 110 // | 108 // |
| 111 // The Do* methods are the various entry points from our | 109 // The Do* methods are the various entry points from our |
| 112 // SyncBackendHost. They are all called on the sync thread to | 110 // SyncBackendHost. They are all called on the sync thread to |
| 113 // actually perform synchronous (and potentially blocking) syncapi | 111 // actually perform synchronous (and potentially blocking) syncapi |
| 114 // operations. | 112 // operations. |
| 115 // | 113 // |
| 116 // Called to perform initialization of the syncapi on behalf of | 114 // Called to perform initialization of the syncapi on behalf of |
| 117 // SyncBackendHost::Initialize. | 115 // SyncBackendHost::Initialize. |
| 118 void DoInitialize(const DoInitializeOptions& options); | 116 void DoInitialize(const DoInitializeOptions& options); |
| 119 | 117 |
| 120 // Called to perform credential update on behalf of | 118 // Called to perform credential update on behalf of |
| 121 // SyncBackendHost::UpdateCredentials | 119 // SyncBackendHost::UpdateCredentials |
| 122 void DoUpdateCredentials(const sync_api::SyncCredentials& credentials); | 120 void DoUpdateCredentials(const sync_api::SyncCredentials& credentials); |
| 123 | 121 |
| 124 // Called when the user disables or enables a sync type. | 122 // Called when the user disables or enables a sync type. |
| 125 void DoUpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); | 123 void DoUpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); |
| 126 | 124 |
| 127 // Called to tell the syncapi to start syncing (generally after | 125 // Called to tell the syncapi to start syncing (generally after |
| 128 // initialization and authentication). | 126 // initialization and authentication). |
| 129 void DoStartSyncing(const ModelSafeRoutingInfo& routing_info); | 127 void DoStartSyncing(const ModelSafeRoutingInfo& routing_info); |
| 130 | 128 |
| 131 // Called to clear server data. | |
| 132 void DoRequestClearServerData(); | |
| 133 | |
| 134 // Called to cleanup disabled types. | 129 // Called to cleanup disabled types. |
| 135 void DoRequestCleanupDisabledTypes( | 130 void DoRequestCleanupDisabledTypes( |
| 136 const browser_sync::ModelSafeRoutingInfo& routing_info); | 131 const browser_sync::ModelSafeRoutingInfo& routing_info); |
| 137 | 132 |
| 138 // Called to set the passphrase for encryption. | 133 // Called to set the passphrase for encryption. |
| 139 void DoSetEncryptionPassphrase(const std::string& passphrase, | 134 void DoSetEncryptionPassphrase(const std::string& passphrase, |
| 140 bool is_explicit); | 135 bool is_explicit); |
| 141 | 136 |
| 142 // Called to decrypt the pending keys. | 137 // Called to decrypt the pending keys. |
| 143 void DoSetDecryptionPassphrase(const std::string& passphrase); | 138 void DoSetDecryptionPassphrase(const std::string& passphrase); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 void SyncBackendHost::ActivateDataType( | 616 void SyncBackendHost::ActivateDataType( |
| 622 syncable::ModelType type, ModelSafeGroup group, | 617 syncable::ModelType type, ModelSafeGroup group, |
| 623 ChangeProcessor* change_processor) { | 618 ChangeProcessor* change_processor) { |
| 624 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); | 619 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); |
| 625 } | 620 } |
| 626 | 621 |
| 627 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { | 622 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { |
| 628 registrar_->DeactivateDataType(type); | 623 registrar_->DeactivateDataType(type); |
| 629 } | 624 } |
| 630 | 625 |
| 631 bool SyncBackendHost::RequestClearServerData() { | |
| 632 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
| 633 base::Bind(&SyncBackendHost::Core::DoRequestClearServerData, | |
| 634 core_.get())); | |
| 635 return true; | |
| 636 } | |
| 637 | |
| 638 sync_api::UserShare* SyncBackendHost::GetUserShare() const { | 626 sync_api::UserShare* SyncBackendHost::GetUserShare() const { |
| 639 DCHECK(initialized()); | 627 DCHECK(initialized()); |
| 640 return core_->sync_manager()->GetUserShare(); | 628 return core_->sync_manager()->GetUserShare(); |
| 641 } | 629 } |
| 642 | 630 |
| 643 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { | 631 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { |
| 644 DCHECK(initialized()); | 632 DCHECK(initialized()); |
| 645 return core_->sync_manager()->GetDetailedStatus(); | 633 return core_->sync_manager()->GetDetailedStatus(); |
| 646 } | 634 } |
| 647 | 635 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 | 969 |
| 982 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { | 970 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { |
| 983 if (!sync_loop_) | 971 if (!sync_loop_) |
| 984 return; | 972 return; |
| 985 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 973 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 986 host_.Call( | 974 host_.Call( |
| 987 FROM_HERE, | 975 FROM_HERE, |
| 988 &SyncBackendHost::NotifyUpdatedToken, token); | 976 &SyncBackendHost::NotifyUpdatedToken, token); |
| 989 } | 977 } |
| 990 | 978 |
| 991 void SyncBackendHost::Core::OnClearServerDataFailed() { | |
| 992 if (!sync_loop_) | |
| 993 return; | |
| 994 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 995 host_.Call( | |
| 996 FROM_HERE, | |
| 997 &SyncBackendHost::HandleClearServerDataFailedOnFrontendLoop); | |
| 998 } | |
| 999 | |
| 1000 void SyncBackendHost::Core::OnClearServerDataSucceeded() { | |
| 1001 if (!sync_loop_) | |
| 1002 return; | |
| 1003 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1004 host_.Call( | |
| 1005 FROM_HERE, | |
| 1006 &SyncBackendHost::HandleClearServerDataSucceededOnFrontendLoop); | |
| 1007 } | |
| 1008 | |
| 1009 void SyncBackendHost::Core::OnEncryptedTypesChanged( | 979 void SyncBackendHost::Core::OnEncryptedTypesChanged( |
| 1010 syncable::ModelTypeSet encrypted_types, | 980 syncable::ModelTypeSet encrypted_types, |
| 1011 bool encrypt_everything) { | 981 bool encrypt_everything) { |
| 1012 if (!sync_loop_) | 982 if (!sync_loop_) |
| 1013 return; | 983 return; |
| 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 984 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1015 // NOTE: We're in a transaction. | 985 // NOTE: We're in a transaction. |
| 1016 host_.Call( | 986 host_.Call( |
| 1017 FROM_HERE, | 987 FROM_HERE, |
| 1018 &SyncBackendHost::NotifyEncryptedTypesChanged, | 988 &SyncBackendHost::NotifyEncryptedTypesChanged, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1111 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1142 sync_manager_->UpdateEnabledTypes(enabled_types); | 1112 sync_manager_->UpdateEnabledTypes(enabled_types); |
| 1143 } | 1113 } |
| 1144 | 1114 |
| 1145 void SyncBackendHost::Core::DoStartSyncing( | 1115 void SyncBackendHost::Core::DoStartSyncing( |
| 1146 const ModelSafeRoutingInfo& routing_info) { | 1116 const ModelSafeRoutingInfo& routing_info) { |
| 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1117 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1148 sync_manager_->StartSyncingNormally(routing_info); | 1118 sync_manager_->StartSyncingNormally(routing_info); |
| 1149 } | 1119 } |
| 1150 | 1120 |
| 1151 void SyncBackendHost::Core::DoRequestClearServerData() { | |
| 1152 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1153 sync_manager_->RequestClearServerData(); | |
| 1154 } | |
| 1155 | |
| 1156 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes( | 1121 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes( |
| 1157 const browser_sync::ModelSafeRoutingInfo& routing_info) { | 1122 const browser_sync::ModelSafeRoutingInfo& routing_info) { |
| 1158 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1123 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1159 sync_manager_->RequestCleanupDisabledTypes(routing_info); | 1124 sync_manager_->RequestCleanupDisabledTypes(routing_info); |
| 1160 } | 1125 } |
| 1161 | 1126 |
| 1162 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1127 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| 1163 const std::string& passphrase, | 1128 const std::string& passphrase, |
| 1164 bool is_explicit) { | 1129 bool is_explicit) { |
| 1165 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1130 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1379 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1415 frontend_->OnEncryptionComplete(); | 1380 frontend_->OnEncryptionComplete(); |
| 1416 } | 1381 } |
| 1417 | 1382 |
| 1418 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { | 1383 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { |
| 1419 if (!frontend_) | 1384 if (!frontend_) |
| 1420 return; | 1385 return; |
| 1421 frontend_->OnStopSyncingPermanently(); | 1386 frontend_->OnStopSyncingPermanently(); |
| 1422 } | 1387 } |
| 1423 | 1388 |
| 1424 void SyncBackendHost::HandleClearServerDataSucceededOnFrontendLoop() { | |
| 1425 if (!frontend_) | |
| 1426 return; | |
| 1427 frontend_->OnClearServerDataSucceeded(); | |
| 1428 } | |
| 1429 | |
| 1430 void SyncBackendHost::HandleClearServerDataFailedOnFrontendLoop() { | |
| 1431 if (!frontend_) | |
| 1432 return; | |
| 1433 frontend_->OnClearServerDataFailed(); | |
| 1434 } | |
| 1435 | |
| 1436 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( | 1389 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( |
| 1437 sync_api::ConnectionStatus status) { | 1390 sync_api::ConnectionStatus status) { |
| 1438 if (!frontend_) | 1391 if (!frontend_) |
| 1439 return; | 1392 return; |
| 1440 | 1393 |
| 1441 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1394 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1442 | 1395 |
| 1443 frontend_->OnConnectionStatusChange(status); | 1396 frontend_->OnConnectionStatusChange(status); |
| 1444 } | 1397 } |
| 1445 | 1398 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1470 FROM_HERE, | 1423 FROM_HERE, |
| 1471 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1424 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1472 core_.get(), sync_thread_done_callback)); | 1425 core_.get(), sync_thread_done_callback)); |
| 1473 } | 1426 } |
| 1474 | 1427 |
| 1475 #undef SDVLOG | 1428 #undef SDVLOG |
| 1476 | 1429 |
| 1477 #undef SLOG | 1430 #undef SLOG |
| 1478 | 1431 |
| 1479 } // namespace browser_sync | 1432 } // namespace browser_sync |
| OLD | NEW |