OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ |
6 #define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ | 6 #define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <map> |
9 | 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/weak_ptr.h" |
10 #include "chromeos/dbus/cryptohome_client.h" | 12 #include "chromeos/dbus/cryptohome_client.h" |
11 | 13 |
12 namespace chromeos { | 14 namespace chromeos { |
13 | 15 |
14 // A fake implementation of CryptohomeClient. This only calls callbacks given | 16 class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient { |
15 // as parameters. | |
16 class FakeCryptohomeClient : public CryptohomeClient { | |
17 public: | 17 public: |
18 FakeCryptohomeClient(); | 18 FakeCryptohomeClient(); |
19 virtual ~FakeCryptohomeClient(); | 19 virtual ~FakeCryptohomeClient(); |
20 | 20 |
21 // CryptohomeClient overrides | |
22 virtual void Init(dbus::Bus* bus) OVERRIDE; | 21 virtual void Init(dbus::Bus* bus) OVERRIDE; |
23 virtual void SetAsyncCallStatusHandlers( | 22 virtual void SetAsyncCallStatusHandlers( |
24 const AsyncCallStatusHandler& handler, | 23 const AsyncCallStatusHandler& handler, |
25 const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE; | 24 const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE; |
26 virtual void ResetAsyncCallStatusHandlers() OVERRIDE; | 25 virtual void ResetAsyncCallStatusHandlers() OVERRIDE; |
27 virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE; | 26 virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE; |
28 virtual bool Unmount(bool* success) OVERRIDE; | 27 virtual bool Unmount(bool* success) OVERRIDE; |
29 virtual void AsyncCheckKey(const std::string& username, | 28 virtual void AsyncCheckKey(const std::string& username, |
30 const std::string& key, | 29 const std::string& key, |
31 const AsyncMethodCallback& callback) OVERRIDE; | 30 const AsyncMethodCallback& callback) OVERRIDE; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 bool* successful) OVERRIDE; | 75 bool* successful) OVERRIDE; |
77 virtual bool InstallAttributesSet(const std::string& name, | 76 virtual bool InstallAttributesSet(const std::string& name, |
78 const std::vector<uint8>& value, | 77 const std::vector<uint8>& value, |
79 bool* successful) OVERRIDE; | 78 bool* successful) OVERRIDE; |
80 virtual bool InstallAttributesFinalize(bool* successful) OVERRIDE; | 79 virtual bool InstallAttributesFinalize(bool* successful) OVERRIDE; |
81 virtual void InstallAttributesIsReady( | 80 virtual void InstallAttributesIsReady( |
82 const BoolDBusMethodCallback& callback) OVERRIDE; | 81 const BoolDBusMethodCallback& callback) OVERRIDE; |
83 virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE; | 82 virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE; |
84 virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE; | 83 virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE; |
85 virtual void TpmAttestationIsPrepared( | 84 virtual void TpmAttestationIsPrepared( |
86 const BoolDBusMethodCallback& callback) OVERRIDE; | 85 const BoolDBusMethodCallback& callback) OVERRIDE; |
87 virtual void TpmAttestationIsEnrolled( | 86 virtual void TpmAttestationIsEnrolled( |
88 const BoolDBusMethodCallback& callback) OVERRIDE; | 87 const BoolDBusMethodCallback& callback) OVERRIDE; |
89 virtual void AsyncTpmAttestationCreateEnrollRequest( | 88 virtual void AsyncTpmAttestationCreateEnrollRequest( |
90 const AsyncMethodCallback& callback) OVERRIDE; | 89 const AsyncMethodCallback& callback) OVERRIDE; |
91 virtual void AsyncTpmAttestationEnroll( | 90 virtual void AsyncTpmAttestationEnroll( |
92 const std::string& pca_response, | 91 const std::string& pca_response, |
93 const AsyncMethodCallback& callback) OVERRIDE; | 92 const AsyncMethodCallback& callback) OVERRIDE; |
94 virtual void AsyncTpmAttestationCreateCertRequest( | 93 virtual void AsyncTpmAttestationCreateCertRequest( |
95 attestation::AttestationCertificateProfile certificate_profile, | 94 attestation::AttestationCertificateProfile certificate_profile, |
96 const std::string& user_email, | 95 const std::string& user_email, |
97 const std::string& request_origin, | 96 const std::string& request_origin, |
98 const AsyncMethodCallback& callback) OVERRIDE; | 97 const AsyncMethodCallback& callback) OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 virtual void TpmAttestationGetKeyPayload( | 132 virtual void TpmAttestationGetKeyPayload( |
134 attestation::AttestationKeyType key_type, | 133 attestation::AttestationKeyType key_type, |
135 const std::string& key_name, | 134 const std::string& key_name, |
136 const DataMethodCallback& callback) OVERRIDE; | 135 const DataMethodCallback& callback) OVERRIDE; |
137 virtual void TpmAttestationSetKeyPayload( | 136 virtual void TpmAttestationSetKeyPayload( |
138 attestation::AttestationKeyType key_type, | 137 attestation::AttestationKeyType key_type, |
139 const std::string& key_name, | 138 const std::string& key_name, |
140 const std::string& payload, | 139 const std::string& payload, |
141 const BoolDBusMethodCallback& callback) OVERRIDE; | 140 const BoolDBusMethodCallback& callback) OVERRIDE; |
142 | 141 |
143 // Sets the unmount result of Unmount() call. Unmount() always sets the result | 142 // Sets the unmount result of Unmount() call. |
144 // and pretends that the underlying method call succeeds. | |
145 void set_unmount_result(bool result) { | 143 void set_unmount_result(bool result) { |
146 unmount_result_= result; | 144 unmount_result_= result; |
147 } | 145 } |
148 | 146 |
149 private: | 147 private: |
150 AsyncCallStatusHandler handler_; | 148 // Posts tasks which return fake results to the UI thread. |
151 AsyncCallStatusWithDataHandler data_handler_; | 149 void ReturnAsyncMethodResult(const AsyncMethodCallback& callback, |
| 150 bool returns_data); |
152 | 151 |
| 152 // This method is used to implement ReturnAsyncMethodResult. |
| 153 void ReturnAsyncMethodResultInternal(const AsyncMethodCallback& callback, |
| 154 bool returns_data); |
| 155 |
| 156 int async_call_id_; |
| 157 AsyncCallStatusHandler async_call_status_handler_; |
| 158 AsyncCallStatusWithDataHandler async_call_status_data_handler_; |
| 159 int tpm_is_ready_counter_; |
153 bool unmount_result_; | 160 bool unmount_result_; |
154 | 161 |
| 162 // A stub store for InstallAttributes, mapping an attribute name to the |
| 163 // associated data blob. Used to implement InstallAttributesSet and -Get. |
| 164 std::map<std::string, std::vector<uint8> > install_attrs_; |
| 165 bool locked_; |
| 166 base::WeakPtrFactory<FakeCryptohomeClient> weak_ptr_factory_; |
| 167 |
155 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient); | 168 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient); |
156 }; | 169 }; |
157 | 170 |
158 } // namespace chromeos | 171 } // namespace chromeos |
159 | 172 |
160 #endif // CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ | 173 #endif // CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ |
OLD | NEW |