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

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

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 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') | sync/util/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/test/fake_sync_encryption_handler.h"
6
7 #include "sync/protocol/nigori_specifics.pb.h"
8 #include "sync/syncable/nigori_util.h"
9 #include "sync/util/cryptographer.h"
10
11 namespace syncer {
12
13 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler()
14 : encrypted_types_(SensitiveTypes()),
15 encrypt_everything_(false),
16 explicit_passphrase_(false),
17 cryptographer_(NULL) {
18 }
19 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
20
21 void FakeSyncEncryptionHandler::Init() {
22 // Do nothing.
23 }
24
25 void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
26 const sync_pb::NigoriSpecifics& nigori,
27 syncable::BaseTransaction* const trans) {
28 if (nigori.encrypt_everything())
29 EnableEncryptEverything();
30 if (nigori.using_explicit_passphrase())
31 explicit_passphrase_ = true;
32
33 if (!cryptographer_)
34 return;
35
36 if (cryptographer_->CanDecrypt(nigori.encrypted()))
37 cryptographer_->InstallKeys(nigori.encrypted());
38 else
39 cryptographer_->SetPendingKeys(nigori.encrypted());
40
41 if (cryptographer_->has_pending_keys()) {
42 DVLOG(1) << "OnPassPhraseRequired Sent";
43 sync_pb::EncryptedData pending_keys = cryptographer_->GetPendingKeys();
44 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
45 OnPassphraseRequired(REASON_DECRYPTION,
46 pending_keys));
47 } else if (!cryptographer_->is_ready()) {
48 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
49 << "ready";
50 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
51 OnPassphraseRequired(REASON_ENCRYPTION,
52 sync_pb::EncryptedData()));
53 }
54 }
55
56 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes(
57 sync_pb::NigoriSpecifics* nigori,
58 syncable::BaseTransaction* const trans) const {
59 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_,
60 encrypt_everything_,
61 nigori);
62 }
63
64 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) {
65 observers_.AddObserver(observer);
66 }
67
68 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) {
69 observers_.RemoveObserver(observer);
70 }
71
72 void FakeSyncEncryptionHandler::SetEncryptionPassphrase(
73 const std::string& passphrase,
74 bool is_explicit) {
75 if (is_explicit)
76 explicit_passphrase_ = true;
77 }
78
79 void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
80 const std::string& passphrase) {
81 // Do nothing.
82 }
83
84 void FakeSyncEncryptionHandler::EnableEncryptEverything() {
85 if (encrypt_everything_)
86 return;
87 encrypt_everything_ = true;
88 encrypted_types_ = ModelTypeSet::All();
89 FOR_EACH_OBSERVER(
90 Observer, observers_,
91 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
92 }
93
94 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const {
95 return encrypt_everything_;
96 }
97
98 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes() const {
99 return encrypted_types_;
100 }
101
102 bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const {
103 return explicit_passphrase_;
104 }
105
106 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | sync/util/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698