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

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

Issue 10878015: [Sync] Move keystore key handling to SyncEncryptionHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 3 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
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | sync/engine/download_updates_command.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; 102 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
103 virtual void OnActionableError( 103 virtual void OnActionableError(
104 const syncer::SyncProtocolError& sync_error) OVERRIDE; 104 const syncer::SyncProtocolError& sync_error) OVERRIDE;
105 105
106 // SyncEncryptionHandler::Observer implementation. 106 // SyncEncryptionHandler::Observer implementation.
107 virtual void OnPassphraseRequired( 107 virtual void OnPassphraseRequired(
108 syncer::PassphraseRequiredReason reason, 108 syncer::PassphraseRequiredReason reason,
109 const sync_pb::EncryptedData& pending_keys) OVERRIDE; 109 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
110 virtual void OnPassphraseAccepted() OVERRIDE; 110 virtual void OnPassphraseAccepted() OVERRIDE;
111 virtual void OnBootstrapTokenUpdated( 111 virtual void OnBootstrapTokenUpdated(
112 const std::string& bootstrap_token) OVERRIDE; 112 const std::string& bootstrap_token,
113 syncer::BootstrapTokenType type) OVERRIDE;
113 virtual void OnEncryptedTypesChanged( 114 virtual void OnEncryptedTypesChanged(
114 syncer::ModelTypeSet encrypted_types, 115 syncer::ModelTypeSet encrypted_types,
115 bool encrypt_everything) OVERRIDE; 116 bool encrypt_everything) OVERRIDE;
116 virtual void OnEncryptionComplete() OVERRIDE; 117 virtual void OnEncryptionComplete() OVERRIDE;
117 virtual void OnCryptographerStateChanged( 118 virtual void OnCryptographerStateChanged(
118 syncer::Cryptographer* cryptographer) OVERRIDE; 119 syncer::Cryptographer* cryptographer) OVERRIDE;
119 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; 120 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE;
120 121
121 // syncer::InvalidationHandler implementation. 122 // syncer::InvalidationHandler implementation.
122 virtual void OnNotificationsEnabled() OVERRIDE; 123 virtual void OnNotificationsEnabled() OVERRIDE;
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 DCHECK(!sync_manager_.get()); 890 DCHECK(!sync_manager_.get());
890 DCHECK(!sync_loop_); 891 DCHECK(!sync_loop_);
891 } 892 }
892 893
893 void SyncBackendHost::Core::OnSyncCycleCompleted( 894 void SyncBackendHost::Core::OnSyncCycleCompleted(
894 const SyncSessionSnapshot& snapshot) { 895 const SyncSessionSnapshot& snapshot) {
895 if (!sync_loop_) 896 if (!sync_loop_)
896 return; 897 return;
897 DCHECK_EQ(MessageLoop::current(), sync_loop_); 898 DCHECK_EQ(MessageLoop::current(), sync_loop_);
898 899
899 if (snapshot.model_neutral_state().last_get_key_result ==
900 syncer::SYNCER_OK) {
901 // If we just received a new keystore key, get it and make sure we update
902 // the bootstrap token with it.
903 std::string keystore_token;
904 sync_manager_->GetKeystoreKeyBootstrapToken(&keystore_token);
905 if (!keystore_token.empty()) {
906 DVLOG(1) << "Persisting keystore encryption bootstrap token.";
907 host_.Call(FROM_HERE,
908 &SyncBackendHost::PersistEncryptionBootstrapToken,
909 keystore_token,
910 KEYSTORE_BOOTSTRAP_TOKEN);
911 } else {
912 NOTREACHED();
913 }
914 }
915
916 host_.Call( 900 host_.Call(
917 FROM_HERE, 901 FROM_HERE,
918 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 902 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
919 snapshot); 903 snapshot);
920 } 904 }
921 905
922 906
923 void SyncBackendHost::Core::OnInitializationComplete( 907 void SyncBackendHost::Core::OnInitializationComplete(
924 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 908 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
925 bool success, 909 bool success,
926 const syncer::ModelTypeSet restored_types) { 910 const syncer::ModelTypeSet restored_types) {
927 DCHECK_EQ(MessageLoop::current(), sync_loop_); 911 DCHECK_EQ(MessageLoop::current(), sync_loop_);
928 912
929 if (!success) { 913 if (!success) {
930 DoDestroySyncManager(); 914 DoDestroySyncManager();
915 } else {
916 // Register for encryption related changes now. We have to do this before
917 // the associate nigori state in order to receive notifications triggered
918 // by the initial download of the nigori node.
919 sync_manager_->GetEncryptionHandler()->AddObserver(this);
931 } 920 }
932 921
933 host_.Call( 922 host_.Call(
934 FROM_HERE, 923 FROM_HERE,
935 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop, 924 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop,
936 js_backend, success, restored_types); 925 js_backend, success, restored_types);
937 926
938 if (success) { 927 if (success) {
939 // Initialization is complete, so we can schedule recurring SaveChanges. 928 // Initialization is complete, so we can schedule recurring SaveChanges.
940 sync_loop_->PostTask(FROM_HERE, 929 sync_loop_->PostTask(FROM_HERE,
(...skipping 25 matching lines...) Expand all
966 void SyncBackendHost::Core::OnPassphraseAccepted() { 955 void SyncBackendHost::Core::OnPassphraseAccepted() {
967 if (!sync_loop_) 956 if (!sync_loop_)
968 return; 957 return;
969 DCHECK_EQ(MessageLoop::current(), sync_loop_); 958 DCHECK_EQ(MessageLoop::current(), sync_loop_);
970 host_.Call( 959 host_.Call(
971 FROM_HERE, 960 FROM_HERE,
972 &SyncBackendHost::NotifyPassphraseAccepted); 961 &SyncBackendHost::NotifyPassphraseAccepted);
973 } 962 }
974 963
975 void SyncBackendHost::Core::OnBootstrapTokenUpdated( 964 void SyncBackendHost::Core::OnBootstrapTokenUpdated(
976 const std::string& bootstrap_token) { 965 const std::string& bootstrap_token,
966 syncer::BootstrapTokenType type) {
977 if (!sync_loop_) 967 if (!sync_loop_)
978 return; 968 return;
979 DCHECK_EQ(MessageLoop::current(), sync_loop_); 969 DCHECK_EQ(MessageLoop::current(), sync_loop_);
980 host_.Call(FROM_HERE, 970 host_.Call(FROM_HERE,
981 &SyncBackendHost::PersistEncryptionBootstrapToken, 971 &SyncBackendHost::PersistEncryptionBootstrapToken,
982 bootstrap_token, 972 bootstrap_token,
983 PASSPHRASE_BOOTSTRAP_TOKEN); 973 type);
984 } 974 }
985 975
986 void SyncBackendHost::Core::OnStopSyncingPermanently() { 976 void SyncBackendHost::Core::OnStopSyncingPermanently() {
987 if (!sync_loop_) 977 if (!sync_loop_)
988 return; 978 return;
989 DCHECK_EQ(MessageLoop::current(), sync_loop_); 979 DCHECK_EQ(MessageLoop::current(), sync_loop_);
990 host_.Call( 980 host_.Call(
991 FROM_HERE, 981 FROM_HERE,
992 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop); 982 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop);
993 } 983 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 } 1158 }
1169 1159
1170 void SyncBackendHost::Core::DoStartSyncing( 1160 void SyncBackendHost::Core::DoStartSyncing(
1171 const syncer::ModelSafeRoutingInfo& routing_info) { 1161 const syncer::ModelSafeRoutingInfo& routing_info) {
1172 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1162 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1173 sync_manager_->StartSyncingNormally(routing_info); 1163 sync_manager_->StartSyncingNormally(routing_info);
1174 } 1164 }
1175 1165
1176 void SyncBackendHost::Core::DoAssociateNigori() { 1166 void SyncBackendHost::Core::DoAssociateNigori() {
1177 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1167 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1178 sync_manager_->GetEncryptionHandler()->AddObserver(this);
1179 sync_manager_->GetEncryptionHandler()->Init(); 1168 sync_manager_->GetEncryptionHandler()->Init();
1180 host_.Call(FROM_HERE, 1169 host_.Call(FROM_HERE,
1181 &SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop,
1182 sync_manager_->GetEncryptionHandler()->GetPassphraseState());
1183 host_.Call(FROM_HERE,
1184 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1170 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1185 true); 1171 true);
1186 } 1172 }
1187 1173
1188 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1174 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1189 const std::string& passphrase, 1175 const std::string& passphrase,
1190 bool is_explicit) { 1176 bool is_explicit) {
1191 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1177 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1192 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( 1178 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(
1193 passphrase, is_explicit); 1179 passphrase, is_explicit);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 } 1407 }
1422 1408
1423 void SyncBackendHost::RetryConfigurationOnFrontendLoop( 1409 void SyncBackendHost::RetryConfigurationOnFrontendLoop(
1424 const base::Closure& retry_callback) { 1410 const base::Closure& retry_callback) {
1425 SDVLOG(1) << "Failed to complete configuration, informing of retry."; 1411 SDVLOG(1) << "Failed to complete configuration, informing of retry.";
1426 retry_callback.Run(); 1412 retry_callback.Run();
1427 } 1413 }
1428 1414
1429 void SyncBackendHost::PersistEncryptionBootstrapToken( 1415 void SyncBackendHost::PersistEncryptionBootstrapToken(
1430 const std::string& token, 1416 const std::string& token,
1431 BootstrapTokenType token_type) { 1417 syncer::BootstrapTokenType token_type) {
1432 CHECK(sync_prefs_.get()); 1418 CHECK(sync_prefs_.get());
1433 DCHECK(!token.empty()); 1419 DCHECK(!token.empty());
1434 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) 1420 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN)
1435 sync_prefs_->SetEncryptionBootstrapToken(token); 1421 sync_prefs_->SetEncryptionBootstrapToken(token);
1436 else 1422 else
1437 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); 1423 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token);
1438 } 1424 }
1439 1425
1440 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1426 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1441 const syncer::SyncProtocolError& sync_error) { 1427 const syncer::SyncProtocolError& sync_error) {
1442 if (!frontend_) 1428 if (!frontend_)
1443 return; 1429 return;
1444 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1430 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 const syncer::ModelTypeSet failed_configuration_types) { 1548 const syncer::ModelTypeSet failed_configuration_types) {
1563 HandleInitializationCompletedOnFrontendLoop( 1549 HandleInitializationCompletedOnFrontendLoop(
1564 failed_configuration_types.Empty()); 1550 failed_configuration_types.Empty());
1565 } 1551 }
1566 1552
1567 #undef SDVLOG 1553 #undef SDVLOG
1568 1554
1569 #undef SLOG 1555 #undef SLOG
1570 1556
1571 } // namespace browser_sync 1557 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | sync/engine/download_updates_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698