Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chromeos/dbus/fake_cryptohome_client.cc

Issue 34303002: chromeos: Wait for service to be available when getting system salt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/fake_cryptohome_client.h ('k') | chromeos/dbus/mock_cryptohome_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 #include "chromeos/dbus/fake_cryptohome_client.h" 5 #include "chromeos/dbus/fake_cryptohome_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "crypto/nss_util.h" 10 #include "crypto/nss_util.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h" 11 #include "third_party/cros_system_api/dbus/service_constants.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 FakeCryptohomeClient::FakeCryptohomeClient() 15 FakeCryptohomeClient::FakeCryptohomeClient()
16 : async_call_id_(1), 16 : service_is_available_(true),
17 async_call_id_(1),
17 tpm_is_ready_counter_(0), 18 tpm_is_ready_counter_(0),
18 unmount_result_(true), 19 unmount_result_(true),
19 locked_(false), 20 locked_(false),
20 weak_ptr_factory_(this) {} 21 weak_ptr_factory_(this) {}
21 22
22 FakeCryptohomeClient::~FakeCryptohomeClient() {} 23 FakeCryptohomeClient::~FakeCryptohomeClient() {}
23 24
24 void FakeCryptohomeClient::Init(dbus::Bus* bus) { 25 void FakeCryptohomeClient::Init(dbus::Bus* bus) {
25 } 26 }
26 27
27 void FakeCryptohomeClient::SetAsyncCallStatusHandlers( 28 void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
28 const AsyncCallStatusHandler& handler, 29 const AsyncCallStatusHandler& handler,
29 const AsyncCallStatusWithDataHandler& data_handler) { 30 const AsyncCallStatusWithDataHandler& data_handler) {
30 async_call_status_handler_ = handler; 31 async_call_status_handler_ = handler;
31 async_call_status_data_handler_ = data_handler; 32 async_call_status_data_handler_ = data_handler;
32 } 33 }
33 34
34 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() { 35 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
35 async_call_status_handler_.Reset(); 36 async_call_status_handler_.Reset();
36 async_call_status_data_handler_.Reset(); 37 async_call_status_data_handler_.Reset();
37 } 38 }
38 39
40 void FakeCryptohomeClient::WaitForServiceToBeAvailable(
41 const WaitForServiceToBeAvailableCallback& callback) {
42 if (service_is_available_) {
43 base::MessageLoop::current()->PostTask(FROM_HERE,
44 base::Bind(callback, true));
45 } else {
46 pending_wait_for_service_to_be_available_callbacks_.push_back(callback);
47 }
48 }
49
39 void FakeCryptohomeClient::IsMounted( 50 void FakeCryptohomeClient::IsMounted(
40 const BoolDBusMethodCallback& callback) { 51 const BoolDBusMethodCallback& callback) {
41 base::MessageLoop::current()->PostTask( 52 base::MessageLoop::current()->PostTask(
42 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); 53 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
43 } 54 }
44 55
45 bool FakeCryptohomeClient::Unmount(bool* success) { 56 bool FakeCryptohomeClient::Unmount(bool* success) {
46 *success = unmount_result_; 57 *success = unmount_result_;
47 return true; 58 return true;
48 } 59 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 void FakeCryptohomeClient::TpmAttestationSetKeyPayload( 372 void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
362 attestation::AttestationKeyType key_type, 373 attestation::AttestationKeyType key_type,
363 const std::string& user_id, 374 const std::string& user_id,
364 const std::string& key_name, 375 const std::string& key_name,
365 const std::string& payload, 376 const std::string& payload,
366 const BoolDBusMethodCallback& callback) { 377 const BoolDBusMethodCallback& callback) {
367 base::MessageLoop::current()->PostTask( 378 base::MessageLoop::current()->PostTask(
368 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); 379 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
369 } 380 }
370 381
382 void FakeCryptohomeClient::SetServiceIsAvailable(bool is_available) {
383 service_is_available_ = is_available;
384 if (is_available) {
385 std::vector<WaitForServiceToBeAvailableCallback> callbacks;
386 callbacks.swap(pending_wait_for_service_to_be_available_callbacks_);
387 for (size_t i = 0; i < callbacks.size(); ++i)
388 callbacks[i].Run(is_available);
389 }
390 }
391
371 // static 392 // static
372 std::vector<uint8> FakeCryptohomeClient::GetStubSystemSalt() { 393 std::vector<uint8> FakeCryptohomeClient::GetStubSystemSalt() {
373 const char kStubSystemSalt[] = "stub_system_salt"; 394 const char kStubSystemSalt[] = "stub_system_salt";
374 return std::vector<uint8>(kStubSystemSalt, 395 return std::vector<uint8>(kStubSystemSalt,
375 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); 396 kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
376 } 397 }
377 398
378 void FakeCryptohomeClient::ReturnAsyncMethodResult( 399 void FakeCryptohomeClient::ReturnAsyncMethodResult(
379 const AsyncMethodCallback& callback, 400 const AsyncMethodCallback& callback,
380 bool returns_data) { 401 bool returns_data) {
(...skipping 21 matching lines...) Expand all
402 FROM_HERE, 423 FROM_HERE,
403 base::Bind(async_call_status_data_handler_, 424 base::Bind(async_call_status_data_handler_,
404 async_call_id_, 425 async_call_id_,
405 true, 426 true,
406 std::string())); 427 std::string()));
407 } 428 }
408 ++async_call_id_; 429 ++async_call_id_;
409 } 430 }
410 431
411 } // namespace chromeos 432 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_cryptohome_client.h ('k') | chromeos/dbus/mock_cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698