[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 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 | #ifndef SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ | ||||
6 | #define SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ | ||||
7 | |||||
8 | #include <string> | ||||
9 | |||||
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" | ||||
[email protected] | 69b3b8f | 2012-08-24 22:54:19 | [diff] [blame] | 14 | #include "sync/test/fake_encryptor.h" |
15 | #include "sync/util/cryptographer.h" | ||||
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 16 | |
17 | namespace syncer { | ||||
18 | |||||
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 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 { | ||||
27 | public: | ||||
28 | FakeSyncEncryptionHandler(); | ||||
dcheng | 393acf28 | 2014-10-21 16:44:46 | [diff] [blame] | 29 | ~FakeSyncEncryptionHandler() override; |
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 30 | |
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 31 | // SyncEncryptionHandler implementation. |
dcheng | 393acf28 | 2014-10-21 16:44:46 | [diff] [blame] | 32 | void AddObserver(Observer* observer) override; |
33 | void RemoveObserver(Observer* observer) override; | ||||
34 | void Init() override; | ||||
35 | void SetEncryptionPassphrase(const std::string& passphrase, | ||||
36 | bool is_explicit) override; | ||||
37 | void SetDecryptionPassphrase(const std::string& passphrase) override; | ||||
38 | void EnableEncryptEverything() override; | ||||
39 | bool EncryptEverythingEnabled() const override; | ||||
40 | PassphraseType GetPassphraseType() const override; | ||||
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 41 | |
42 | // NigoriHandler implemenation. | ||||
dcheng | 393acf28 | 2014-10-21 16:44:46 | [diff] [blame] | 43 | void ApplyNigoriUpdate(const sync_pb::NigoriSpecifics& nigori, |
44 | syncable::BaseTransaction* const trans) override; | ||||
45 | void UpdateNigoriFromEncryptedTypes( | ||||
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 46 | sync_pb::NigoriSpecifics* nigori, |
mostynb | 44fdf5d0 | 2014-10-06 20:30:50 | [diff] [blame] | 47 | syncable::BaseTransaction* const trans) const override; |
dcheng | 393acf28 | 2014-10-21 16:44:46 | [diff] [blame] | 48 | bool NeedKeystoreKey(syncable::BaseTransaction* const trans) const override; |
49 | bool SetKeystoreKeys( | ||||
[email protected] | 9a3072c | 2012-12-19 01:56:52 | [diff] [blame] | 50 | const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys, |
mostynb | 44fdf5d0 | 2014-10-06 20:30:50 | [diff] [blame] | 51 | syncable::BaseTransaction* const trans) override; |
dcheng | 393acf28 | 2014-10-21 16:44:46 | [diff] [blame] | 52 | ModelTypeSet GetEncryptedTypes( |
mostynb | 44fdf5d0 | 2014-10-06 20:30:50 | [diff] [blame] | 53 | syncable::BaseTransaction* const trans) const override; |
[email protected] | 69b3b8f | 2012-08-24 22:54:19 | [diff] [blame] | 54 | |
55 | Cryptographer* cryptographer() { return &cryptographer_; } | ||||
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 56 | |
57 | private: | ||||
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 58 | base::ObserverList<SyncEncryptionHandler::Observer> observers_; |
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 59 | ModelTypeSet encrypted_types_; |
60 | bool encrypt_everything_; | ||||
[email protected] | 19fb909 | 2012-09-13 21:52:28 | [diff] [blame] | 61 | PassphraseType passphrase_type_; |
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 62 | |
[email protected] | 69b3b8f | 2012-08-24 22:54:19 | [diff] [blame] | 63 | FakeEncryptor encryptor_; |
64 | Cryptographer cryptographer_; | ||||
[email protected] | de71c08 | 2012-08-29 23:48:12 | [diff] [blame] | 65 | std::string keystore_key_; |
[email protected] | 4cda7888 | 2012-08-16 02:34:16 | [diff] [blame] | 66 | }; |
67 | |||||
68 | } // namespace syncer | ||||
69 | |||||
70 | #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ |