Fix crash on app list start page keyboard navigation with <4 apps.
[chromium-blink-merge.git] / sync / test / fake_sync_encryption_handler.h
blobc3180a684dd4d13796e017430d15eb597d173d18
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_
8 #include <string>
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"
17 namespace syncer {
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();
29 ~FakeSyncEncryptionHandler() override;
31 // SyncEncryptionHandler implementation.
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;
42 // NigoriHandler implemenation.
43 void ApplyNigoriUpdate(const sync_pb::NigoriSpecifics& nigori,
44 syncable::BaseTransaction* const trans) override;
45 void UpdateNigoriFromEncryptedTypes(
46 sync_pb::NigoriSpecifics* nigori,
47 syncable::BaseTransaction* const trans) const override;
48 bool NeedKeystoreKey(syncable::BaseTransaction* const trans) const override;
49 bool SetKeystoreKeys(
50 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys,
51 syncable::BaseTransaction* const trans) override;
52 ModelTypeSet GetEncryptedTypes(
53 syncable::BaseTransaction* const trans) const override;
55 Cryptographer* cryptographer() { return &cryptographer_; }
57 private:
58 ObserverList<SyncEncryptionHandler::Observer> observers_;
59 ModelTypeSet encrypted_types_;
60 bool encrypt_everything_;
61 PassphraseType passphrase_type_;
63 FakeEncryptor encryptor_;
64 Cryptographer cryptographer_;
65 std::string keystore_key_;
68 } // namespace syncer
70 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_