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

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

Issue 10824410: [Sync] Refactor passphrase state handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 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) 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 30 matching lines...) Expand all
41 #include "jingle/notifier/base/notifier_options.h" 41 #include "jingle/notifier/base/notifier_options.h"
42 #include "net/base/host_port_pair.h" 42 #include "net/base/host_port_pair.h"
43 #include "net/url_request/url_request_context_getter.h" 43 #include "net/url_request/url_request_context_getter.h"
44 #include "sync/internal_api/public/base_transaction.h" 44 #include "sync/internal_api/public/base_transaction.h"
45 #include "sync/internal_api/public/engine/model_safe_worker.h" 45 #include "sync/internal_api/public/engine/model_safe_worker.h"
46 #include "sync/internal_api/public/http_bridge.h" 46 #include "sync/internal_api/public/http_bridge.h"
47 #include "sync/internal_api/public/internal_components_factory_impl.h" 47 #include "sync/internal_api/public/internal_components_factory_impl.h"
48 #include "sync/internal_api/public/read_transaction.h" 48 #include "sync/internal_api/public/read_transaction.h"
49 #include "sync/internal_api/public/sync_manager_factory.h" 49 #include "sync/internal_api/public/sync_manager_factory.h"
50 #include "sync/internal_api/public/util/experiments.h" 50 #include "sync/internal_api/public/util/experiments.h"
51 #include "sync/internal_api/public/util/sync_string_conversions.h"
51 #include "sync/notifier/sync_notifier.h" 52 #include "sync/notifier/sync_notifier.h"
52 #include "sync/protocol/encryption.pb.h" 53 #include "sync/protocol/encryption.pb.h"
53 #include "sync/protocol/sync.pb.h" 54 #include "sync/protocol/sync.pb.h"
54 #include "sync/util/nigori.h" 55 #include "sync/util/nigori.h"
55 56
56 static const int kSaveChangesIntervalSeconds = 10; 57 static const int kSaveChangesIntervalSeconds = 10;
57 static const FilePath::CharType kSyncDataFolderName[] = 58 static const FilePath::CharType kSyncDataFolderName[] =
58 FILE_PATH_LITERAL("Sync Data"); 59 FILE_PATH_LITERAL("Sync Data");
59 60
60 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 61 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const sync_pb::EncryptedData& pending_keys) OVERRIDE; 109 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
109 virtual void OnPassphraseAccepted() OVERRIDE; 110 virtual void OnPassphraseAccepted() OVERRIDE;
110 virtual void OnBootstrapTokenUpdated( 111 virtual void OnBootstrapTokenUpdated(
111 const std::string& bootstrap_token) OVERRIDE; 112 const std::string& bootstrap_token) OVERRIDE;
112 virtual void OnEncryptedTypesChanged( 113 virtual void OnEncryptedTypesChanged(
113 syncer::ModelTypeSet encrypted_types, 114 syncer::ModelTypeSet encrypted_types,
114 bool encrypt_everything) OVERRIDE; 115 bool encrypt_everything) OVERRIDE;
115 virtual void OnEncryptionComplete() OVERRIDE; 116 virtual void OnEncryptionComplete() OVERRIDE;
116 virtual void OnCryptographerStateChanged( 117 virtual void OnCryptographerStateChanged(
117 syncer::Cryptographer* cryptographer) OVERRIDE; 118 syncer::Cryptographer* cryptographer) OVERRIDE;
119 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE;
118 120
119 // syncer::SyncNotifierObserver implementation. 121 // syncer::SyncNotifierObserver implementation.
120 virtual void OnNotificationsEnabled() OVERRIDE; 122 virtual void OnNotificationsEnabled() OVERRIDE;
121 virtual void OnNotificationsDisabled( 123 virtual void OnNotificationsDisabled(
122 syncer::NotificationsDisabledReason reason) OVERRIDE; 124 syncer::NotificationsDisabledReason reason) OVERRIDE;
123 virtual void OnIncomingNotification( 125 virtual void OnIncomingNotification(
124 const syncer::ObjectIdStateMap& id_state_map, 126 const syncer::ObjectIdStateMap& id_state_map,
125 syncer::IncomingNotificationSource source) OVERRIDE; 127 syncer::IncomingNotificationSource source) OVERRIDE;
126 128
127 // Note: 129 // Note:
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 name_(name), 320 name_(name),
319 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), 321 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName),
320 weak_ptr_factory_.GetWeakPtr())), 322 weak_ptr_factory_.GetWeakPtr())),
321 initialization_state_(NOT_ATTEMPTED), 323 initialization_state_(NOT_ATTEMPTED),
322 sync_prefs_(sync_prefs), 324 sync_prefs_(sync_prefs),
323 sync_notifier_factory_( 325 sync_notifier_factory_(
324 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 326 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
325 profile_->GetRequestContext()), 327 profile_->GetRequestContext()),
326 content::GetUserAgent(GURL()), 328 content::GetUserAgent(GURL()),
327 invalidator_storage), 329 invalidator_storage),
328 frontend_(NULL) { 330 frontend_(NULL),
331 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) {
329 } 332 }
330 333
331 SyncBackendHost::SyncBackendHost(Profile* profile) 334 SyncBackendHost::SyncBackendHost(Profile* profile)
332 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 335 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
333 sync_thread_("Chrome_SyncThread"), 336 sync_thread_("Chrome_SyncThread"),
334 frontend_loop_(MessageLoop::current()), 337 frontend_loop_(MessageLoop::current()),
335 profile_(profile), 338 profile_(profile),
336 name_("Unknown"), 339 name_("Unknown"),
337 initialization_state_(NOT_ATTEMPTED), 340 initialization_state_(NOT_ATTEMPTED),
338 sync_notifier_factory_( 341 sync_notifier_factory_(
339 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 342 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
340 profile_->GetRequestContext()), 343 profile_->GetRequestContext()),
341 content::GetUserAgent(GURL()), 344 content::GetUserAgent(GURL()),
342 base::WeakPtr<syncer::InvalidationStateTracker>()), 345 base::WeakPtr<syncer::InvalidationStateTracker>()),
343 frontend_(NULL) { 346 frontend_(NULL),
347 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) {
344 } 348 }
345 349
346 SyncBackendHost::~SyncBackendHost() { 350 SyncBackendHost::~SyncBackendHost() {
347 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 351 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
348 DCHECK(!chrome_sync_notification_bridge_.get()); 352 DCHECK(!chrome_sync_notification_bridge_.get());
349 DCHECK(!registrar_.get()); 353 DCHECK(!registrar_.get());
350 } 354 }
351 355
352 namespace { 356 namespace {
353 357
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 759
756 bool SyncBackendHost::IsNigoriEnabled() const { 760 bool SyncBackendHost::IsNigoriEnabled() const {
757 return registrar_.get() && registrar_->IsNigoriEnabled(); 761 return registrar_.get() && registrar_->IsNigoriEnabled();
758 } 762 }
759 763
760 bool SyncBackendHost::IsUsingExplicitPassphrase() { 764 bool SyncBackendHost::IsUsingExplicitPassphrase() {
761 // This should only be called once the nigori node has been downloaded, as 765 // This should only be called once the nigori node has been downloaded, as
762 // otherwise we have no idea what kind of passphrase we are using. This will 766 // otherwise we have no idea what kind of passphrase we are using. This will
763 // NOTREACH in sync_manager and return false if we fail to load the nigori 767 // NOTREACH in sync_manager and return false if we fail to load the nigori
764 // node. 768 // node.
765 // TODO(zea): cache this value here, then make the encryption handler 769 // TODO(zea): expose whether the custom passphrase is a frozen implicit
766 // NonThreadSafe and only accessible from the sync thread. 770 // passphrase or not to provide better messaging.
767 return IsNigoriEnabled() && 771 return IsNigoriEnabled() && (
768 core_->sync_manager()->GetEncryptionHandler()-> 772 cached_passphrase_state_ == syncer::CUSTOM_PASSPHRASE ||
769 IsUsingExplicitPassphrase(); 773 cached_passphrase_state_ == syncer::FROZEN_IMPLICIT_PASSPHRASE);
770 } 774 }
771 775
772 bool SyncBackendHost::IsCryptographerReady( 776 bool SyncBackendHost::IsCryptographerReady(
773 const syncer::BaseTransaction* trans) const { 777 const syncer::BaseTransaction* trans) const {
774 return initialized() && trans->GetCryptographer()->is_ready(); 778 return initialized() && trans->GetCryptographer()->is_ready();
775 } 779 }
776 780
777 void SyncBackendHost::GetModelSafeRoutingInfo( 781 void SyncBackendHost::GetModelSafeRoutingInfo(
778 syncer::ModelSafeRoutingInfo* out) const { 782 syncer::ModelSafeRoutingInfo* out) const {
779 if (initialized()) { 783 if (initialized()) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 host_.Call( 1022 host_.Call(
1019 FROM_HERE, 1023 FROM_HERE,
1020 &SyncBackendHost::NotifyEncryptionComplete); 1024 &SyncBackendHost::NotifyEncryptionComplete);
1021 } 1025 }
1022 1026
1023 void SyncBackendHost::Core::OnCryptographerStateChanged( 1027 void SyncBackendHost::Core::OnCryptographerStateChanged(
1024 syncer::Cryptographer* cryptographer) { 1028 syncer::Cryptographer* cryptographer) {
1025 // Do nothing. 1029 // Do nothing.
1026 } 1030 }
1027 1031
1032 void SyncBackendHost::Core::OnPassphraseStateChanged(
1033 syncer::PassphraseState state) {
1034 host_.Call(
1035 FROM_HERE,
1036 &SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop,
1037 state);
1038 }
1039
1028 void SyncBackendHost::Core::OnActionableError( 1040 void SyncBackendHost::Core::OnActionableError(
1029 const syncer::SyncProtocolError& sync_error) { 1041 const syncer::SyncProtocolError& sync_error) {
1030 if (!sync_loop_) 1042 if (!sync_loop_)
1031 return; 1043 return;
1032 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1044 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1033 host_.Call( 1045 host_.Call(
1034 FROM_HERE, 1046 FROM_HERE,
1035 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1047 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1036 sync_error); 1048 sync_error);
1037 } 1049 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 const syncer::ModelSafeRoutingInfo& routing_info) { 1171 const syncer::ModelSafeRoutingInfo& routing_info) {
1160 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1172 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1161 sync_manager_->StartSyncingNormally(routing_info); 1173 sync_manager_->StartSyncingNormally(routing_info);
1162 } 1174 }
1163 1175
1164 void SyncBackendHost::Core::DoAssociateNigori() { 1176 void SyncBackendHost::Core::DoAssociateNigori() {
1165 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1177 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1166 sync_manager_->GetEncryptionHandler()->AddObserver(this); 1178 sync_manager_->GetEncryptionHandler()->AddObserver(this);
1167 sync_manager_->GetEncryptionHandler()->Init(); 1179 sync_manager_->GetEncryptionHandler()->Init();
1168 host_.Call(FROM_HERE, 1180 host_.Call(FROM_HERE,
1181 &SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop,
1182 sync_manager_->GetEncryptionHandler()->GetPassphraseState());
1183 host_.Call(FROM_HERE,
1169 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1184 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1170 true); 1185 true);
1171 } 1186 }
1172 1187
1173 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1188 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1174 const std::string& passphrase, 1189 const std::string& passphrase,
1175 bool is_explicit) { 1190 bool is_explicit) {
1176 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1191 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1177 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( 1192 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(
1178 passphrase, is_explicit); 1193 passphrase, is_explicit);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 } 1527 }
1513 1528
1514 void SyncBackendHost::NotifyEncryptionComplete() { 1529 void SyncBackendHost::NotifyEncryptionComplete() {
1515 if (!frontend_) 1530 if (!frontend_)
1516 return; 1531 return;
1517 1532
1518 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1533 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1519 frontend_->OnEncryptionComplete(); 1534 frontend_->OnEncryptionComplete();
1520 } 1535 }
1521 1536
1537 void SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop(
1538 syncer::PassphraseState state) {
1539 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1540 DVLOG(1) << "Passphrase state changed to "
1541 << syncer::PassphraseStateToString(state);
1542 cached_passphrase_state_ = state;
1543 }
1544
1522 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { 1545 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() {
1523 if (!frontend_) 1546 if (!frontend_)
1524 return; 1547 return;
1525 frontend_->OnStopSyncingPermanently(); 1548 frontend_->OnStopSyncingPermanently();
1526 } 1549 }
1527 1550
1528 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( 1551 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop(
1529 syncer::ConnectionStatus status) { 1552 syncer::ConnectionStatus status) {
1530 if (!frontend_) 1553 if (!frontend_)
1531 return; 1554 return;
1532 1555
1533 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1556 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1534 1557
1535 frontend_->OnConnectionStatusChange(status); 1558 frontend_->OnConnectionStatusChange(status);
1536 } 1559 }
1537 1560
1538 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( 1561 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop(
1539 const syncer::ModelTypeSet failed_configuration_types) { 1562 const syncer::ModelTypeSet failed_configuration_types) {
1540 HandleInitializationCompletedOnFrontendLoop( 1563 HandleInitializationCompletedOnFrontendLoop(
1541 failed_configuration_types.Empty()); 1564 failed_configuration_types.Empty());
1542 } 1565 }
1543 1566
1544 #undef SDVLOG 1567 #undef SDVLOG
1545 1568
1546 #undef SLOG 1569 #undef SLOG
1547 1570
1548 } // namespace browser_sync 1571 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | sync/internal_api/debug_info_event_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698