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

Side by Side Diff: components/sync/test/fake_sync_encryption_handler.cc

Issue 2424673002: Remove usage of FOR_EACH_OBSERVER macro in components/sync (Closed)
Patch Set: tidy Created 4 years, 2 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
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 "components/sync/test/fake_sync_encryption_handler.h" 5 #include "components/sync/test/fake_sync_encryption_handler.h"
6 6
7 #include "components/sync/base/passphrase_type.h" 7 #include "components/sync/base/passphrase_type.h"
8 #include "components/sync/protocol/nigori_specifics.pb.h" 8 #include "components/sync/protocol/nigori_specifics.pb.h"
9 #include "components/sync/syncable/nigori_util.h" 9 #include "components/sync/syncable/nigori_util.h"
10 10
(...skipping 22 matching lines...) Expand all
33 33
34 // TODO(zea): consider adding fake support for migration. 34 // TODO(zea): consider adding fake support for migration.
35 if (cryptographer_.CanDecrypt(nigori.encryption_keybag())) 35 if (cryptographer_.CanDecrypt(nigori.encryption_keybag()))
36 cryptographer_.InstallKeys(nigori.encryption_keybag()); 36 cryptographer_.InstallKeys(nigori.encryption_keybag());
37 else if (nigori.has_encryption_keybag()) 37 else if (nigori.has_encryption_keybag())
38 cryptographer_.SetPendingKeys(nigori.encryption_keybag()); 38 cryptographer_.SetPendingKeys(nigori.encryption_keybag());
39 39
40 if (cryptographer_.has_pending_keys()) { 40 if (cryptographer_.has_pending_keys()) {
41 DVLOG(1) << "OnPassPhraseRequired Sent"; 41 DVLOG(1) << "OnPassPhraseRequired Sent";
42 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys(); 42 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys();
43 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 43 for (auto& observer : observers_)
44 OnPassphraseRequired(REASON_DECRYPTION, pending_keys)); 44 observer.OnPassphraseRequired(REASON_DECRYPTION, pending_keys);
45 } else if (!cryptographer_.is_ready()) { 45 } else if (!cryptographer_.is_ready()) {
46 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " 46 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
47 << "ready"; 47 << "ready";
48 FOR_EACH_OBSERVER( 48 for (auto& observer : observers_) {
49 SyncEncryptionHandler::Observer, observers_, 49 observer.OnPassphraseRequired(REASON_ENCRYPTION,
50 OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData())); 50 sync_pb::EncryptedData());
51 }
51 } 52 }
52 } 53 }
53 54
54 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes( 55 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes(
55 sync_pb::NigoriSpecifics* nigori, 56 sync_pb::NigoriSpecifics* nigori,
56 syncable::BaseTransaction* const trans) const { 57 syncable::BaseTransaction* const trans) const {
57 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_, 58 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_,
58 encrypt_everything_, nigori); 59 encrypt_everything_, nigori);
59 } 60 }
60 61
61 bool FakeSyncEncryptionHandler::NeedKeystoreKey( 62 bool FakeSyncEncryptionHandler::NeedKeystoreKey(
62 syncable::BaseTransaction* const trans) const { 63 syncable::BaseTransaction* const trans) const {
63 return keystore_key_.empty(); 64 return keystore_key_.empty();
64 } 65 }
65 66
66 bool FakeSyncEncryptionHandler::SetKeystoreKeys( 67 bool FakeSyncEncryptionHandler::SetKeystoreKeys(
67 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys, 68 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys,
68 syncable::BaseTransaction* const trans) { 69 syncable::BaseTransaction* const trans) {
69 if (keys.size() == 0) 70 if (keys.size() == 0)
70 return false; 71 return false;
71 std::string new_key = keys.Get(keys.size() - 1); 72 std::string new_key = keys.Get(keys.size() - 1);
72 if (new_key.empty()) 73 if (new_key.empty())
73 return false; 74 return false;
74 keystore_key_ = new_key; 75 keystore_key_ = new_key;
75 76
76 DVLOG(1) << "Keystore bootstrap token updated."; 77 DVLOG(1) << "Keystore bootstrap token updated.";
77 FOR_EACH_OBSERVER( 78 for (auto& observer : observers_)
78 SyncEncryptionHandler::Observer, observers_, 79 observer.OnBootstrapTokenUpdated(keystore_key_, KEYSTORE_BOOTSTRAP_TOKEN);
79 OnBootstrapTokenUpdated(keystore_key_, KEYSTORE_BOOTSTRAP_TOKEN));
80 return true; 80 return true;
81 } 81 }
82 82
83 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes( 83 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes(
84 syncable::BaseTransaction* const trans) const { 84 syncable::BaseTransaction* const trans) const {
85 return encrypted_types_; 85 return encrypted_types_;
86 } 86 }
87 87
88 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) { 88 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) {
89 observers_.AddObserver(observer); 89 observers_.AddObserver(observer);
(...skipping 13 matching lines...) Expand all
103 void FakeSyncEncryptionHandler::SetDecryptionPassphrase( 103 void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
104 const std::string& passphrase) { 104 const std::string& passphrase) {
105 // Do nothing. 105 // Do nothing.
106 } 106 }
107 107
108 void FakeSyncEncryptionHandler::EnableEncryptEverything() { 108 void FakeSyncEncryptionHandler::EnableEncryptEverything() {
109 if (encrypt_everything_) 109 if (encrypt_everything_)
110 return; 110 return;
111 encrypt_everything_ = true; 111 encrypt_everything_ = true;
112 encrypted_types_ = ModelTypeSet::All(); 112 encrypted_types_ = ModelTypeSet::All();
113 FOR_EACH_OBSERVER( 113 for (auto& observer : observers_)
114 Observer, observers_, 114 observer.OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_);
115 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
116 } 115 }
117 116
118 bool FakeSyncEncryptionHandler::IsEncryptEverythingEnabled() const { 117 bool FakeSyncEncryptionHandler::IsEncryptEverythingEnabled() const {
119 return encrypt_everything_; 118 return encrypt_everything_;
120 } 119 }
121 120
122 PassphraseType FakeSyncEncryptionHandler::GetPassphraseType( 121 PassphraseType FakeSyncEncryptionHandler::GetPassphraseType(
123 syncable::BaseTransaction* const trans) const { 122 syncable::BaseTransaction* const trans) const {
124 return passphrase_type_; 123 return passphrase_type_;
125 } 124 }
126 125
127 } // namespace syncer 126 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698