| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 virtual void OnPassphraseAccepted() OVERRIDE; | 111 virtual void OnPassphraseAccepted() OVERRIDE; |
| 112 virtual void OnBootstrapTokenUpdated( | 112 virtual void OnBootstrapTokenUpdated( |
| 113 const std::string& bootstrap_token, | 113 const std::string& bootstrap_token, |
| 114 syncer::BootstrapTokenType type) OVERRIDE; | 114 syncer::BootstrapTokenType type) OVERRIDE; |
| 115 virtual void OnEncryptedTypesChanged( | 115 virtual void OnEncryptedTypesChanged( |
| 116 syncer::ModelTypeSet encrypted_types, | 116 syncer::ModelTypeSet encrypted_types, |
| 117 bool encrypt_everything) OVERRIDE; | 117 bool encrypt_everything) OVERRIDE; |
| 118 virtual void OnEncryptionComplete() OVERRIDE; | 118 virtual void OnEncryptionComplete() OVERRIDE; |
| 119 virtual void OnCryptographerStateChanged( | 119 virtual void OnCryptographerStateChanged( |
| 120 syncer::Cryptographer* cryptographer) OVERRIDE; | 120 syncer::Cryptographer* cryptographer) OVERRIDE; |
| 121 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; | 121 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type) OVERRIDE; |
| 122 | 122 |
| 123 // syncer::InvalidationHandler implementation. | 123 // syncer::InvalidationHandler implementation. |
| 124 virtual void OnInvalidatorStateChange( | 124 virtual void OnInvalidatorStateChange( |
| 125 syncer::InvalidatorState state) OVERRIDE; | 125 syncer::InvalidatorState state) OVERRIDE; |
| 126 virtual void OnIncomingInvalidation( | 126 virtual void OnIncomingInvalidation( |
| 127 const syncer::ObjectIdStateMap& id_state_map, | 127 const syncer::ObjectIdStateMap& id_state_map, |
| 128 syncer::IncomingInvalidationSource source) OVERRIDE; | 128 syncer::IncomingInvalidationSource source) OVERRIDE; |
| 129 | 129 |
| 130 // Note: | 130 // Note: |
| 131 // | 131 // |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 322 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
| 323 weak_ptr_factory_.GetWeakPtr())), | 323 weak_ptr_factory_.GetWeakPtr())), |
| 324 initialization_state_(NOT_ATTEMPTED), | 324 initialization_state_(NOT_ATTEMPTED), |
| 325 sync_prefs_(sync_prefs), | 325 sync_prefs_(sync_prefs), |
| 326 invalidator_factory_( | 326 invalidator_factory_( |
| 327 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 327 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| 328 profile_->GetRequestContext()), | 328 profile_->GetRequestContext()), |
| 329 content::GetUserAgent(GURL()), | 329 content::GetUserAgent(GURL()), |
| 330 invalidator_storage), | 330 invalidator_storage), |
| 331 frontend_(NULL), | 331 frontend_(NULL), |
| 332 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { | 332 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| 333 } | 333 } |
| 334 | 334 |
| 335 SyncBackendHost::SyncBackendHost(Profile* profile) | 335 SyncBackendHost::SyncBackendHost(Profile* profile) |
| 336 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 336 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 337 sync_thread_("Chrome_SyncThread"), | 337 sync_thread_("Chrome_SyncThread"), |
| 338 frontend_loop_(MessageLoop::current()), | 338 frontend_loop_(MessageLoop::current()), |
| 339 profile_(profile), | 339 profile_(profile), |
| 340 name_("Unknown"), | 340 name_("Unknown"), |
| 341 initialization_state_(NOT_ATTEMPTED), | 341 initialization_state_(NOT_ATTEMPTED), |
| 342 invalidator_factory_( | 342 invalidator_factory_( |
| 343 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 343 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| 344 profile_->GetRequestContext()), | 344 profile_->GetRequestContext()), |
| 345 content::GetUserAgent(GURL()), | 345 content::GetUserAgent(GURL()), |
| 346 base::WeakPtr<syncer::InvalidationStateTracker>()), | 346 base::WeakPtr<syncer::InvalidationStateTracker>()), |
| 347 frontend_(NULL), | 347 frontend_(NULL), |
| 348 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { | 348 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| 349 } | 349 } |
| 350 | 350 |
| 351 SyncBackendHost::~SyncBackendHost() { | 351 SyncBackendHost::~SyncBackendHost() { |
| 352 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 352 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 353 DCHECK(!chrome_sync_notification_bridge_.get()); | 353 DCHECK(!chrome_sync_notification_bridge_.get()); |
| 354 DCHECK(!registrar_.get()); | 354 DCHECK(!registrar_.get()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 namespace { | 357 namespace { |
| 358 | 358 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 } | 763 } |
| 764 | 764 |
| 765 bool SyncBackendHost::IsUsingExplicitPassphrase() { | 765 bool SyncBackendHost::IsUsingExplicitPassphrase() { |
| 766 // This should only be called once the nigori node has been downloaded, as | 766 // This should only be called once the nigori node has been downloaded, as |
| 767 // otherwise we have no idea what kind of passphrase we are using. This will | 767 // otherwise we have no idea what kind of passphrase we are using. This will |
| 768 // NOTREACH in sync_manager and return false if we fail to load the nigori | 768 // NOTREACH in sync_manager and return false if we fail to load the nigori |
| 769 // node. | 769 // node. |
| 770 // TODO(zea): expose whether the custom passphrase is a frozen implicit | 770 // TODO(zea): expose whether the custom passphrase is a frozen implicit |
| 771 // passphrase or not to provide better messaging. | 771 // passphrase or not to provide better messaging. |
| 772 return IsNigoriEnabled() && ( | 772 return IsNigoriEnabled() && ( |
| 773 cached_passphrase_state_ == syncer::CUSTOM_PASSPHRASE || | 773 cached_passphrase_type_ == syncer::CUSTOM_PASSPHRASE || |
| 774 cached_passphrase_state_ == syncer::FROZEN_IMPLICIT_PASSPHRASE); | 774 cached_passphrase_type_ == syncer::FROZEN_IMPLICIT_PASSPHRASE); |
| 775 } | 775 } |
| 776 | 776 |
| 777 bool SyncBackendHost::IsCryptographerReady( | 777 bool SyncBackendHost::IsCryptographerReady( |
| 778 const syncer::BaseTransaction* trans) const { | 778 const syncer::BaseTransaction* trans) const { |
| 779 return initialized() && trans->GetCryptographer()->is_ready(); | 779 return initialized() && trans->GetCryptographer()->is_ready(); |
| 780 } | 780 } |
| 781 | 781 |
| 782 void SyncBackendHost::GetModelSafeRoutingInfo( | 782 void SyncBackendHost::GetModelSafeRoutingInfo( |
| 783 syncer::ModelSafeRoutingInfo* out) const { | 783 syncer::ModelSafeRoutingInfo* out) const { |
| 784 if (initialized()) { | 784 if (initialized()) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 host_.Call( | 1012 host_.Call( |
| 1013 FROM_HERE, | 1013 FROM_HERE, |
| 1014 &SyncBackendHost::NotifyEncryptionComplete); | 1014 &SyncBackendHost::NotifyEncryptionComplete); |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 void SyncBackendHost::Core::OnCryptographerStateChanged( | 1017 void SyncBackendHost::Core::OnCryptographerStateChanged( |
| 1018 syncer::Cryptographer* cryptographer) { | 1018 syncer::Cryptographer* cryptographer) { |
| 1019 // Do nothing. | 1019 // Do nothing. |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 void SyncBackendHost::Core::OnPassphraseStateChanged( | 1022 void SyncBackendHost::Core::OnPassphraseTypeChanged( |
| 1023 syncer::PassphraseState state) { | 1023 syncer::PassphraseType type) { |
| 1024 host_.Call( | 1024 host_.Call( |
| 1025 FROM_HERE, | 1025 FROM_HERE, |
| 1026 &SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop, | 1026 &SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop, |
| 1027 state); | 1027 type); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 void SyncBackendHost::Core::OnActionableError( | 1030 void SyncBackendHost::Core::OnActionableError( |
| 1031 const syncer::SyncProtocolError& sync_error) { | 1031 const syncer::SyncProtocolError& sync_error) { |
| 1032 if (!sync_loop_) | 1032 if (!sync_loop_) |
| 1033 return; | 1033 return; |
| 1034 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1034 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1035 host_.Call( | 1035 host_.Call( |
| 1036 FROM_HERE, | 1036 FROM_HERE, |
| 1037 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1037 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 void SyncBackendHost::NotifyEncryptionComplete() { | 1509 void SyncBackendHost::NotifyEncryptionComplete() { |
| 1510 if (!frontend_) | 1510 if (!frontend_) |
| 1511 return; | 1511 return; |
| 1512 | 1512 |
| 1513 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1513 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1514 frontend_->OnEncryptionComplete(); | 1514 frontend_->OnEncryptionComplete(); |
| 1515 } | 1515 } |
| 1516 | 1516 |
| 1517 void SyncBackendHost::HandlePassphraseStateChangedOnFrontendLoop( | 1517 void SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop( |
| 1518 syncer::PassphraseState state) { | 1518 syncer::PassphraseType type) { |
| 1519 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1519 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1520 DVLOG(1) << "Passphrase state changed to " | 1520 DVLOG(1) << "Passphrase type changed to " |
| 1521 << syncer::PassphraseStateToString(state); | 1521 << syncer::PassphraseTypeToString(type); |
| 1522 cached_passphrase_state_ = state; | 1522 cached_passphrase_type_ = type; |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { | 1525 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { |
| 1526 if (!frontend_) | 1526 if (!frontend_) |
| 1527 return; | 1527 return; |
| 1528 frontend_->OnStopSyncingPermanently(); | 1528 frontend_->OnStopSyncingPermanently(); |
| 1529 } | 1529 } |
| 1530 | 1530 |
| 1531 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( | 1531 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( |
| 1532 syncer::ConnectionStatus status) { | 1532 syncer::ConnectionStatus status) { |
| 1533 if (!frontend_) | 1533 if (!frontend_) |
| 1534 return; | 1534 return; |
| 1535 | 1535 |
| 1536 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1536 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1537 | 1537 |
| 1538 frontend_->OnConnectionStatusChange(status); | 1538 frontend_->OnConnectionStatusChange(status); |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( | 1541 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
| 1542 const syncer::ModelTypeSet failed_configuration_types) { | 1542 const syncer::ModelTypeSet failed_configuration_types) { |
| 1543 HandleInitializationCompletedOnFrontendLoop( | 1543 HandleInitializationCompletedOnFrontendLoop( |
| 1544 failed_configuration_types.Empty()); | 1544 failed_configuration_types.Empty()); |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 #undef SDVLOG | 1547 #undef SDVLOG |
| 1548 | 1548 |
| 1549 #undef SLOG | 1549 #undef SLOG |
| 1550 | 1550 |
| 1551 } // namespace browser_sync | 1551 } // namespace browser_sync |
| OLD | NEW |