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

Side by Side Diff: sync/test/fake_sync_encryption_handler.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
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | no next file » | 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 "sync/test/fake_sync_encryption_handler.h" 5 #include "sync/test/fake_sync_encryption_handler.h"
6 6
7 #include "sync/protocol/nigori_specifics.pb.h" 7 #include "sync/protocol/nigori_specifics.pb.h"
8 #include "sync/syncable/nigori_util.h" 8 #include "sync/syncable/nigori_util.h"
9 9
10 namespace syncer { 10 namespace syncer {
11 11
12 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler() 12 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler()
13 : encrypted_types_(SensitiveTypes()), 13 : encrypted_types_(SensitiveTypes()),
14 encrypt_everything_(false), 14 encrypt_everything_(false),
15 explicit_passphrase_(false), 15 passphrase_state_(IMPLICIT_PASSPHRASE),
16 cryptographer_(&encryptor_) { 16 cryptographer_(&encryptor_) {
17 } 17 }
18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} 18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
19 19
20 void FakeSyncEncryptionHandler::Init() { 20 void FakeSyncEncryptionHandler::Init() {
21 // Do nothing. 21 // Do nothing.
22 } 22 }
23 23
24 void FakeSyncEncryptionHandler::ApplyNigoriUpdate( 24 void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
25 const sync_pb::NigoriSpecifics& nigori, 25 const sync_pb::NigoriSpecifics& nigori,
26 syncable::BaseTransaction* const trans) { 26 syncable::BaseTransaction* const trans) {
27 if (nigori.encrypt_everything()) 27 if (nigori.encrypt_everything())
28 EnableEncryptEverything(); 28 EnableEncryptEverything();
29 if (nigori.using_explicit_passphrase()) 29 if (nigori.using_explicit_passphrase())
30 explicit_passphrase_ = true; 30 passphrase_state_ = CUSTOM_PASSPHRASE;
31 31
32 if (cryptographer_.CanDecrypt(nigori.encrypted())) 32 if (cryptographer_.CanDecrypt(nigori.encrypted()))
33 cryptographer_.InstallKeys(nigori.encrypted()); 33 cryptographer_.InstallKeys(nigori.encrypted());
34 else if (nigori.has_encrypted()) 34 else if (nigori.has_encrypted())
35 cryptographer_.SetPendingKeys(nigori.encrypted()); 35 cryptographer_.SetPendingKeys(nigori.encrypted());
36 36
37 if (cryptographer_.has_pending_keys()) { 37 if (cryptographer_.has_pending_keys()) {
38 DVLOG(1) << "OnPassPhraseRequired Sent"; 38 DVLOG(1) << "OnPassPhraseRequired Sent";
39 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys(); 39 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys();
40 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 40 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
(...skipping 26 matching lines...) Expand all
67 } 67 }
68 68
69 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) { 69 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) {
70 observers_.RemoveObserver(observer); 70 observers_.RemoveObserver(observer);
71 } 71 }
72 72
73 void FakeSyncEncryptionHandler::SetEncryptionPassphrase( 73 void FakeSyncEncryptionHandler::SetEncryptionPassphrase(
74 const std::string& passphrase, 74 const std::string& passphrase,
75 bool is_explicit) { 75 bool is_explicit) {
76 if (is_explicit) 76 if (is_explicit)
77 explicit_passphrase_ = true; 77 passphrase_state_ = CUSTOM_PASSPHRASE;
78 } 78 }
79 79
80 void FakeSyncEncryptionHandler::SetDecryptionPassphrase( 80 void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
81 const std::string& passphrase) { 81 const std::string& passphrase) {
82 // Do nothing. 82 // Do nothing.
83 } 83 }
84 84
85 void FakeSyncEncryptionHandler::EnableEncryptEverything() { 85 void FakeSyncEncryptionHandler::EnableEncryptEverything() {
86 if (encrypt_everything_) 86 if (encrypt_everything_)
87 return; 87 return;
88 encrypt_everything_ = true; 88 encrypt_everything_ = true;
89 encrypted_types_ = ModelTypeSet::All(); 89 encrypted_types_ = ModelTypeSet::All();
90 FOR_EACH_OBSERVER( 90 FOR_EACH_OBSERVER(
91 Observer, observers_, 91 Observer, observers_,
92 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); 92 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
93 } 93 }
94 94
95 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const { 95 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const {
96 return encrypt_everything_; 96 return encrypt_everything_;
97 } 97 }
98 98
99 bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const { 99 PassphraseState FakeSyncEncryptionHandler::GetPassphraseState() const {
100 return explicit_passphrase_; 100 return passphrase_state_;
101 } 101 }
102 102
103 } // namespace syncer 103 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698