| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/cryptohome_client.h" | 5 #include "chromeos/dbus/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/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 cryptohome::kCryptohomeAsyncRemove); | 103 cryptohome::kCryptohomeAsyncRemove); |
| 104 dbus::MessageWriter writer(&method_call); | 104 dbus::MessageWriter writer(&method_call); |
| 105 writer.AppendString(username); | 105 writer.AppendString(username); |
| 106 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 106 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 107 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 107 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 108 weak_ptr_factory_.GetWeakPtr(), | 108 weak_ptr_factory_.GetWeakPtr(), |
| 109 callback)); | 109 callback)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // CryptohomeClient override. | 112 // CryptohomeClient override. |
| 113 virtual bool GetSystemSalt(std::vector<uint8>* salt) OVERRIDE { | 113 virtual void GetSystemSalt(const GetSystemSaltCallback& callback) OVERRIDE { |
| 114 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 114 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
| 115 cryptohome::kCryptohomeGetSystemSalt); | 115 cryptohome::kCryptohomeGetSystemSalt); |
| 116 scoped_ptr<dbus::Response> response( | 116 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 117 blocking_method_caller_->CallMethodAndBlock(&method_call)); | 117 base::Bind(&CryptohomeClientImpl::OnGetSystemSalt, |
| 118 if (!response.get()) | 118 weak_ptr_factory_.GetWeakPtr(), |
| 119 return false; | 119 callback)); |
| 120 dbus::MessageReader reader(response.get()); | |
| 121 uint8* bytes = NULL; | |
| 122 size_t length = 0; | |
| 123 if (!reader.PopArrayOfBytes(&bytes, &length)) | |
| 124 return false; | |
| 125 salt->assign(bytes, bytes + length); | |
| 126 return true; | |
| 127 } | 120 } |
| 128 | 121 |
| 129 // CryptohomeClient override, | 122 // CryptohomeClient override, |
| 130 virtual void GetSanitizedUsername( | 123 virtual void GetSanitizedUsername( |
| 131 const std::string& username, | 124 const std::string& username, |
| 132 const StringDBusMethodCallback& callback) OVERRIDE { | 125 const StringDBusMethodCallback& callback) OVERRIDE { |
| 133 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 126 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
| 134 cryptohome::kCryptohomeGetSanitizedUsername); | 127 cryptohome::kCryptohomeGetSanitizedUsername); |
| 135 dbus::MessageWriter writer(&method_call); | 128 dbus::MessageWriter writer(&method_call); |
| 136 writer.AppendString(username); | 129 writer.AppendString(username); |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 return; | 706 return; |
| 714 dbus::MessageReader reader(response); | 707 dbus::MessageReader reader(response); |
| 715 int async_id = 0; | 708 int async_id = 0; |
| 716 if (!reader.PopInt32(&async_id)) { | 709 if (!reader.PopInt32(&async_id)) { |
| 717 LOG(ERROR) << "Invalid response: " << response->ToString(); | 710 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 718 return; | 711 return; |
| 719 } | 712 } |
| 720 callback.Run(async_id); | 713 callback.Run(async_id); |
| 721 } | 714 } |
| 722 | 715 |
| 716 // Handles the result of GetSystemSalt(). |
| 717 void OnGetSystemSalt(const GetSystemSaltCallback& callback, |
| 718 dbus::Response* response) { |
| 719 if (!response) { |
| 720 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); |
| 721 return; |
| 722 } |
| 723 dbus::MessageReader reader(response); |
| 724 uint8* bytes = NULL; |
| 725 size_t length = 0; |
| 726 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 727 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); |
| 728 return; |
| 729 } |
| 730 callback.Run(DBUS_METHOD_CALL_SUCCESS, |
| 731 std::vector<uint8>(bytes, bytes + length)); |
| 732 } |
| 733 |
| 723 // Calls a method without result values. | 734 // Calls a method without result values. |
| 724 void CallVoidMethod(dbus::MethodCall* method_call, | 735 void CallVoidMethod(dbus::MethodCall* method_call, |
| 725 const VoidDBusMethodCallback& callback) { | 736 const VoidDBusMethodCallback& callback) { |
| 726 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 737 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 727 base::Bind(&CryptohomeClientImpl::OnVoidMethod, | 738 base::Bind(&CryptohomeClientImpl::OnVoidMethod, |
| 728 weak_ptr_factory_.GetWeakPtr(), | 739 weak_ptr_factory_.GetWeakPtr(), |
| 729 callback)); | 740 callback)); |
| 730 } | 741 } |
| 731 | 742 |
| 732 void OnVoidMethod(const VoidDBusMethodCallback& callback, | 743 void OnVoidMethod(const VoidDBusMethodCallback& callback, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 return new FakeCryptohomeClient(); | 936 return new FakeCryptohomeClient(); |
| 926 } | 937 } |
| 927 | 938 |
| 928 // static | 939 // static |
| 929 std::string CryptohomeClient::GetStubSanitizedUsername( | 940 std::string CryptohomeClient::GetStubSanitizedUsername( |
| 930 const std::string& username) { | 941 const std::string& username) { |
| 931 return username + kUserIdStubHashSuffix; | 942 return username + kUserIdStubHashSuffix; |
| 932 } | 943 } |
| 933 | 944 |
| 934 } // namespace chromeos | 945 } // namespace chromeos |
| OLD | NEW |