Chromium Code Reviews| Index: components/sync/engine_impl/sync_encryption_handler_impl.cc |
| diff --git a/components/sync/core_impl/sync_encryption_handler_impl.cc b/components/sync/engine_impl/sync_encryption_handler_impl.cc |
| similarity index 93% |
| rename from components/sync/core_impl/sync_encryption_handler_impl.cc |
| rename to components/sync/engine_impl/sync_encryption_handler_impl.cc |
| index d431c491ca3789a7ef250729f61e4055a668e56b..528ce2c940ece852f5664e91ce32bb752530e810 100644 |
| --- a/components/sync/core_impl/sync_encryption_handler_impl.cc |
| +++ b/components/sync/engine_impl/sync_encryption_handler_impl.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "components/sync/core_impl/sync_encryption_handler_impl.h" |
| +#include "components/sync/engine_impl/sync_encryption_handler_impl.h" |
| #include <stddef.h> |
| #include <stdint.h> |
| @@ -296,14 +296,15 @@ void SyncEncryptionHandlerImpl::Init() { |
| // Always trigger an encrypted types and cryptographer state change event at |
| // init time so observers get the initial values. |
| - FOR_EACH_OBSERVER(Observer, observers_, |
| - OnEncryptedTypesChanged( |
| - UnlockVault(trans.GetWrappedTrans()).encrypted_types, |
| - encrypt_everything_)); |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnCryptographerStateChanged( |
| - &UnlockVaultMutable(trans.GetWrappedTrans())->cryptographer)); |
| + for (auto& observer : observers_) { |
| + observer.OnEncryptedTypesChanged( |
| + UnlockVault(trans.GetWrappedTrans()).encrypted_types, |
| + encrypt_everything_); |
| + } |
| + for (auto& observer : observers_) { |
| + observer.OnCryptographerStateChanged( |
| + &UnlockVaultMutable(trans.GetWrappedTrans())->cryptographer); |
| + } |
| // If the cryptographer is not ready (either it has pending keys or we |
| // failed to initialize it), we don't want to try and re-encrypt the data. |
| @@ -394,10 +395,10 @@ void SyncEncryptionHandlerImpl::SetEncryptionPassphrase( |
| DVLOG(1) << "Setting explicit passphrase for encryption."; |
| *passphrase_type = PassphraseType::CUSTOM_PASSPHRASE; |
| custom_passphrase_time_ = base::Time::Now(); |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged( |
| - *passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| } else { |
| DVLOG(1) << "Setting implicit passphrase for encryption."; |
| } |
| @@ -644,9 +645,10 @@ void SyncEncryptionHandlerImpl::ApplyNigoriUpdate( |
| weak_ptr_factory_.GetWeakPtr())); |
| } |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnCryptographerStateChanged(&UnlockVaultMutable(trans)->cryptographer)); |
| + for (auto& observer : observers_) { |
| + observer.OnCryptographerStateChanged( |
| + &UnlockVaultMutable(trans)->cryptographer); |
| + } |
| } |
| void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes( |
| @@ -693,9 +695,10 @@ bool SyncEncryptionHandlerImpl::SetKeystoreKeys( |
| std::string keystore_bootstrap = PackKeystoreBootstrapToken( |
| old_keystore_keys_, keystore_key_, cryptographer->encryptor()); |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnBootstrapTokenUpdated(keystore_bootstrap, KEYSTORE_BOOTSTRAP_TOKEN)); |
| + for (auto& observer : observers_) { |
| + observer.OnBootstrapTokenUpdated(keystore_bootstrap, |
| + KEYSTORE_BOOTSTRAP_TOKEN); |
| + } |
| DVLOG(1) << "Keystore bootstrap token updated."; |
| // If this is a first time sync, we get the encryption keys before we process |
| @@ -854,8 +857,9 @@ void SyncEncryptionHandlerImpl::ReEncryptEverything(WriteTransaction* trans) { |
| DVLOG(1) << "Re-encrypt everything complete."; |
| // NOTE: We notify from within a transaction. |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnEncryptionComplete()); |
| + for (auto& observer : observers_) { |
| + observer.OnEncryptionComplete(); |
| + } |
| } |
| bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( |
| @@ -892,10 +896,10 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( |
| << PassphraseTypeToString(*passphrase_type) << " to " |
| << PassphraseTypeToString(nigori_passphrase_type); |
| *passphrase_type = nigori_passphrase_type; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged(*passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| } |
| if (*passphrase_type == PassphraseType::KEYSTORE_PASSPHRASE && |
| encrypt_everything_) { |
| @@ -908,10 +912,10 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( |
| DVLOG(1) << "Changing passphrase state to FROZEN_IMPLICIT_PASSPHRASE " |
| << "due to full encryption."; |
| *passphrase_type = PassphraseType::FROZEN_IMPLICIT_PASSPHRASE; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged(*passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| } |
| } else { |
| // It's possible that while we're waiting for migration a client that does |
| @@ -919,10 +923,10 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( |
| if (nigori.keybag_is_frozen() && |
| *passphrase_type != PassphraseType::CUSTOM_PASSPHRASE) { |
| *passphrase_type = PassphraseType::CUSTOM_PASSPHRASE; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged(*passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| } |
| } |
| @@ -973,14 +977,16 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( |
| if (cryptographer->has_pending_keys()) { |
| DVLOG(1) << "OnPassphraseRequired Sent"; |
| sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseRequired(REASON_DECRYPTION, pending_keys)); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseRequired(REASON_DECRYPTION, pending_keys); |
| + } |
| } else if (!cryptographer->is_ready()) { |
| DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
| << "ready"; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData())); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseRequired(REASON_ENCRYPTION, |
| + sync_pb::EncryptedData()); |
| + } |
| } |
| // Check if the current local encryption state is stricter/newer than the |
| @@ -1090,9 +1096,9 @@ bool SyncEncryptionHandlerImpl::UpdateEncryptedTypesFromNigori( |
| if (!encrypt_everything_) { |
| encrypt_everything_ = true; |
| *encrypted_types = EncryptableUserTypes(); |
| - FOR_EACH_OBSERVER( |
| - Observer, observers_, |
| - OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
| + for (auto& observer : observers_) { |
| + observer.OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_); |
| + } |
| } |
| DCHECK(*encrypted_types == EncryptableUserTypes()); |
| return false; |
| @@ -1143,10 +1149,10 @@ void SyncEncryptionHandlerImpl::SetCustomPassphrase( |
| &UnlockVaultMutable(trans->GetWrappedTrans())->passphrase_type; |
| *passphrase_type = PassphraseType::CUSTOM_PASSPHRASE; |
| custom_passphrase_time_ = base::Time::Now(); |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged(*passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| FinishSetPassphrase(true, bootstrap_token, trans, nigori_node); |
| } |
| @@ -1161,8 +1167,9 @@ void SyncEncryptionHandlerImpl::NotifyObserversOfLocalCustomPassphrase( |
| sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE || |
| nigori_state.nigori_specifics.passphrase_type() == |
| sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE); |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnLocalSetPassphraseEncryption(nigori_state)); |
| + for (auto& observer : observers_) { |
| + observer.OnLocalSetPassphraseEncryption(nigori_state); |
| + } |
| } |
| void SyncEncryptionHandlerImpl::DecryptPendingKeysWithExplicitPassphrase( |
| @@ -1210,19 +1217,20 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase( |
| WriteTransaction* trans, |
| WriteNode* nigori_node) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnCryptographerStateChanged( |
| - &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer)); |
| + for (auto& observer : observers_) { |
| + observer.OnCryptographerStateChanged( |
| + &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer); |
| + } |
| // It's possible we need to change the bootstrap token even if we failed to |
| // set the passphrase (for example if we need to preserve the new GAIA |
| // passphrase). |
| if (!bootstrap_token.empty()) { |
| DVLOG(1) << "Passphrase bootstrap token updated."; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnBootstrapTokenUpdated(bootstrap_token, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| + for (auto& observer : observers_) { |
| + observer.OnBootstrapTokenUpdated(bootstrap_token, |
| + PASSPHRASE_BOOTSTRAP_TOKEN); |
| + } |
| } |
| const Cryptographer& cryptographer = |
| @@ -1232,13 +1240,15 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase( |
| LOG(ERROR) << "Attempt to change passphrase failed while cryptographer " |
| << "was ready."; |
| } else if (cryptographer.has_pending_keys()) { |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseRequired(REASON_DECRYPTION, |
| - cryptographer.GetPendingKeys())); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseRequired(REASON_DECRYPTION, |
| + cryptographer.GetPendingKeys()); |
| + } |
| } else { |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData())); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseRequired(REASON_ENCRYPTION, |
| + sync_pb::EncryptedData()); |
| + } |
| } |
| return; |
| } |
| @@ -1274,8 +1284,9 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase( |
| // Must do this after OnPassphraseTypeChanged, in order to ensure the PSS |
| // checks the passphrase state after it has been set. |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseAccepted()); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseAccepted(); |
| + } |
| // Does nothing if everything is already encrypted. |
| // TODO(zea): If we just migrated and enabled encryption, this will be |
| @@ -1294,9 +1305,9 @@ void SyncEncryptionHandlerImpl::MergeEncryptedTypes( |
| ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; |
| if (!encrypted_types->HasAll(new_encrypted_types)) { |
| *encrypted_types = new_encrypted_types; |
| - FOR_EACH_OBSERVER( |
| - Observer, observers_, |
| - OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
| + for (auto& observer : observers_) { |
| + observer.OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_); |
| + } |
| } |
| } |
| @@ -1427,8 +1438,9 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore( |
| return false; |
| } |
| if (!cryptographer_was_ready && cryptographer->is_ready()) { |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseAccepted()); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseAccepted(); |
| + } |
| } |
| } else { |
| // We're in backwards compatible mode -- either the account has an |
| @@ -1482,14 +1494,15 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore( |
| TimeToProtoTime(custom_passphrase_time_)); |
| } |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnCryptographerStateChanged(cryptographer)); |
| + for (auto& observer : observers_) { |
| + observer.OnCryptographerStateChanged(cryptographer); |
| + } |
| if (*passphrase_type != new_passphrase_type) { |
| *passphrase_type = new_passphrase_type; |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseTypeChanged(*passphrase_type, |
| - GetExplicitPassphraseTime(*passphrase_type))); |
| + for (auto& observer : observers_) { |
| + observer.OnPassphraseTypeChanged( |
| + *passphrase_type, GetExplicitPassphraseTime(*passphrase_type)); |
| + } |
| } |
| if (new_encrypt_everything && !encrypt_everything_) { |
| @@ -1582,9 +1595,9 @@ void SyncEncryptionHandlerImpl::EnableEncryptEverythingImpl( |
| } |
| encrypt_everything_ = true; |
| *encrypted_types = EncryptableUserTypes(); |
| - FOR_EACH_OBSERVER( |
| - Observer, observers_, |
| - OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
| + for (auto& observer : observers_) { |
| + observer.OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_); |
| + } |
| } |
| bool SyncEncryptionHandlerImpl::DecryptPendingKeysWithKeystoreKey( |
| @@ -1644,13 +1657,16 @@ bool SyncEncryptionHandlerImpl::DecryptPendingKeysWithKeystoreKey( |
| std::string bootstrap_token; |
| cryptographer->GetBootstrapToken(&bootstrap_token); |
| DVLOG(1) << "Keystore decryptor token decrypted pending keys."; |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnPassphraseAccepted()); |
| - FOR_EACH_OBSERVER( |
| - SyncEncryptionHandler::Observer, observers_, |
| - OnBootstrapTokenUpdated(bootstrap_token, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| - FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnCryptographerStateChanged(cryptographer)); |
| + for (auto& observer : observers_) { |
|
skym
2016/10/14 18:42:14
Can you throw in a comment noting that these 3 loo
maxbogue
2016/10/14 20:25:00
Done.
|
| + observer.OnPassphraseAccepted(); |
| + } |
| + for (auto& observer : observers_) { |
| + observer.OnBootstrapTokenUpdated(bootstrap_token, |
| + PASSPHRASE_BOOTSTRAP_TOKEN); |
| + } |
| + for (auto& observer : observers_) { |
| + observer.OnCryptographerStateChanged(cryptographer); |
| + } |
| return true; |
| } |
| } |