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.
5 #ifndef SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_
6 #define SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_
10 #include "base/compiler_specific.h"
11 #include "base/observer_list.h"
12 #include "sync/internal_api/public/sync_encryption_handler.h"
13 #include "sync/syncable/nigori_handler.h"
14 #include "sync/test/fake_encryptor.h"
15 #include "sync/util/cryptographer.h"
19 // A fake sync encryption handler capable of keeping track of the encryption
20 // state without opening any transactions or interacting with the nigori node.
21 // Note that this only performs basic interactions with the cryptographer
22 // (setting pending keys, installing keys).
23 // Note: NOT thread safe. If threads attempt to check encryption state
24 // while another thread is modifying it, races can occur.
25 class FakeSyncEncryptionHandler
: public SyncEncryptionHandler
,
26 public syncable::NigoriHandler
{
28 FakeSyncEncryptionHandler();
29 virtual ~FakeSyncEncryptionHandler();
31 // SyncEncryptionHandler implementation.
32 virtual void AddObserver(Observer
* observer
) OVERRIDE
;
33 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
;
34 virtual void Init() OVERRIDE
;
35 virtual void SetEncryptionPassphrase(const std::string
& passphrase
,
36 bool is_explicit
) OVERRIDE
;
37 virtual void SetDecryptionPassphrase(const std::string
& passphrase
) OVERRIDE
;
38 virtual void EnableEncryptEverything() OVERRIDE
;
39 virtual bool EncryptEverythingEnabled() const OVERRIDE
;
40 virtual PassphraseType
GetPassphraseType() const OVERRIDE
;
42 // NigoriHandler implemenation.
43 virtual void ApplyNigoriUpdate(
44 const sync_pb::NigoriSpecifics
& nigori
,
45 syncable::BaseTransaction
* const trans
) OVERRIDE
;
46 virtual void UpdateNigoriFromEncryptedTypes(
47 sync_pb::NigoriSpecifics
* nigori
,
48 syncable::BaseTransaction
* const trans
) const OVERRIDE
;
49 virtual bool NeedKeystoreKey(
50 syncable::BaseTransaction
* const trans
) const OVERRIDE
;
51 virtual bool SetKeystoreKeys(
52 const google::protobuf::RepeatedPtrField
<google::protobuf::string
>& keys
,
53 syncable::BaseTransaction
* const trans
) OVERRIDE
;
54 virtual ModelTypeSet
GetEncryptedTypes(
55 syncable::BaseTransaction
* const trans
) const OVERRIDE
;
57 Cryptographer
* cryptographer() { return &cryptographer_
; }
60 ObserverList
<SyncEncryptionHandler::Observer
> observers_
;
61 ModelTypeSet encrypted_types_
;
62 bool encrypt_everything_
;
63 PassphraseType passphrase_type_
;
65 FakeEncryptor encryptor_
;
66 Cryptographer cryptographer_
;
67 std::string keystore_key_
;
72 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_