Revert 217860 "Implement per-browser crash throttling for NaCl p..." which broke...
[chromium-blink-merge.git] / chromeos / dbus / fake_cryptohome_client.cc
blobc5df786fac99195a204a1a8710f5c079f5d0cb05
1 // Copyright (c) 2013 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 #include "chromeos/dbus/fake_cryptohome_client.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "third_party/cros_system_api/dbus/service_constants.h"
11 namespace chromeos {
13 namespace {
15 // A fake system salt. GetSystemSalt copies it to the given buffer.
16 const char kStubSystemSalt[] = "stub_system_salt";
18 } // namespace
20 FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) {
23 FakeCryptohomeClient::~FakeCryptohomeClient() {
26 void FakeCryptohomeClient::TpmIsBeingOwned(
27 const BoolDBusMethodCallback& callback) {
30 bool FakeCryptohomeClient::Unmount(bool* success) {
31 *success = unmount_result_;
32 return true;
35 void FakeCryptohomeClient::AsyncCheckKey(const std::string& username,
36 const std::string& key,
37 const AsyncMethodCallback& callback) {
40 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
41 return false;
44 void FakeCryptohomeClient::TpmAttestationGetKeyPayload(
45 attestation::AttestationKeyType key_type,
46 const std::string& key_name,
47 const DataMethodCallback& callback) {
50 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest(
51 const std::string& pca_response,
52 attestation::AttestationKeyType key_type,
53 const std::string& key_name,
54 const AsyncMethodCallback& callback) {
57 void FakeCryptohomeClient::TpmIsEnabled(
58 const BoolDBusMethodCallback& callback) {
61 void FakeCryptohomeClient::AsyncTpmAttestationEnroll(
62 const std::string& pca_response,
63 const AsyncMethodCallback& callback) {
66 void FakeCryptohomeClient::AsyncMigrateKey(
67 const std::string& username,
68 const std::string& from_key,
69 const std::string& to_key,
70 const AsyncMethodCallback& callback) {
73 void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback& callback) {
74 base::MessageLoop::current()->PostTask(FROM_HERE,
75 base::Bind(callback,
76 DBUS_METHOD_CALL_SUCCESS, true));
79 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name,
80 std::vector<uint8>* value,
81 bool* successful) {
82 return false;
85 void FakeCryptohomeClient::AsyncMount(const std::string& username,
86 const std::string& key, int flags,
87 const AsyncMethodCallback& callback) {
88 DCHECK(!callback.is_null());
90 base::MessageLoop::current()->PostTask(FROM_HERE,
91 base::Bind(callback, 1 /* async_id */));
92 if (!handler_.is_null())
93 base::MessageLoop::current()->PostTask(FROM_HERE,
94 base::Bind(handler_,
95 1, // async_id
96 true, // return_status
97 cryptohome::MOUNT_ERROR_NONE));
100 void FakeCryptohomeClient::AsyncAddKey(const std::string& username,
101 const std::string& key,
102 const std::string& new_key,
103 const AsyncMethodCallback& callback) {
104 DCHECK(!callback.is_null());
106 base::MessageLoop::current()->PostTask(FROM_HERE,
107 base::Bind(callback, 1 /* async_id */));
108 if (!handler_.is_null())
109 base::MessageLoop::current()->PostTask(FROM_HERE,
110 base::Bind(handler_,
111 1, // async_id
112 true, // return_status
113 cryptohome::MOUNT_ERROR_NONE));
116 void FakeCryptohomeClient::AsyncMountGuest(
117 const AsyncMethodCallback& callback) {
120 void FakeCryptohomeClient::AsyncMountPublic(
121 const std::string& public_mount_id,
122 int flags,
123 const AsyncMethodCallback& callback) {
126 bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) {
127 return false;
130 void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
131 const BoolDBusMethodCallback& callback) {
134 void FakeCryptohomeClient::TpmClearStoredPassword(
135 const VoidDBusMethodCallback& callback) {
138 void FakeCryptohomeClient::TpmCanAttemptOwnership(
139 const VoidDBusMethodCallback& callback) {
142 bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) {
143 salt->assign(kStubSystemSalt,
144 kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
145 return true;
148 void FakeCryptohomeClient::TpmGetPassword(
149 const StringDBusMethodCallback& callback) {
152 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
153 return false;
156 void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
157 const AsyncCallStatusHandler& handler,
158 const AsyncCallStatusWithDataHandler& data_handler) {
159 handler_ = handler;
160 data_handler_ = data_handler;
163 bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) {
164 return false;
167 bool FakeCryptohomeClient::InstallAttributesSet(
168 const std::string& name,
169 const std::vector<uint8>& value,
170 bool* successful) {
171 return false;
174 bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
175 bool* is_first_install) {
176 return false;
179 void FakeCryptohomeClient::TpmAttestationGetCertificate(
180 attestation::AttestationKeyType key_type,
181 const std::string& key_name,
182 const DataMethodCallback& callback) {
185 void FakeCryptohomeClient::InstallAttributesIsReady(
186 const BoolDBusMethodCallback& callback) {
187 base::MessageLoop::current()->PostTask(FROM_HERE,
188 base::Bind(callback,
189 DBUS_METHOD_CALL_SUCCESS, true));
192 void FakeCryptohomeClient::TpmAttestationGetPublicKey(
193 attestation::AttestationKeyType key_type,
194 const std::string& key_name,
195 const DataMethodCallback& callback) {
198 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
199 attestation::AttestationKeyType key_type,
200 const std::string& key_name,
201 const std::string& challenge,
202 const AsyncMethodCallback& callback) {
205 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
206 const Pkcs11GetTpmTokenInfoCallback& callback) {
209 void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) {
212 void FakeCryptohomeClient::TpmAttestationIsPrepared(
213 const BoolDBusMethodCallback& callback) {
216 void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) {
219 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
220 const AsyncMethodCallback& callback) {
223 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
224 handler_.Reset();
225 data_handler_.Reset();
228 void FakeCryptohomeClient::TpmAttestationDoesKeyExist(
229 attestation::AttestationKeyType key_type,
230 const std::string& key_name,
231 const BoolDBusMethodCallback& callback) {
234 bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) {
235 return false;
238 void FakeCryptohomeClient::AsyncRemove(const std::string& username,
239 const AsyncMethodCallback& callback) {
242 void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
243 attestation::AttestationKeyType key_type,
244 const std::string& key_name,
245 const std::string& payload,
246 const BoolDBusMethodCallback& callback) {
249 void FakeCryptohomeClient::GetSanitizedUsername(
250 const std::string& username,
251 const StringDBusMethodCallback& callback) {
252 DCHECK(!callback.is_null());
254 base::MessageLoop::current()->PostTask(
255 FROM_HERE,
256 base::Bind(callback,
257 chromeos::DBUS_METHOD_CALL_SUCCESS,
258 username));
259 if (!data_handler_.is_null())
260 base::MessageLoop::current()->PostTask(
261 FROM_HERE,
262 base::Bind(data_handler_,
263 1, // async_id
264 true, // return_status
265 username));
268 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername(
269 const std::string& username) {
270 return username;
273 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
274 attestation::AttestationKeyType key_type,
275 const std::string& key_name,
276 const std::string& domain,
277 const std::string& device_id,
278 attestation::AttestationChallengeOptions options,
279 const std::string& challenge,
280 const AsyncMethodCallback& callback) {
283 void FakeCryptohomeClient::TpmAttestationIsEnrolled(
284 const BoolDBusMethodCallback& callback) {
287 void FakeCryptohomeClient::TpmAttestationRegisterKey(
288 attestation::AttestationKeyType key_type,
289 const std::string& key_name,
290 const AsyncMethodCallback& callback) {
293 bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
294 return false;
297 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
298 attestation::AttestationCertificateProfile certificate_profile,
299 const std::string& user_email,
300 const std::string& request_origin,
301 const AsyncMethodCallback& callback) {
304 } // namespace chromeos