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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 bool* successful) OVERRIDE { | 350 bool* successful) OVERRIDE { |
351 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 351 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
352 cryptohome::kCryptohomeInstallAttributesGet); | 352 cryptohome::kCryptohomeInstallAttributesGet); |
353 dbus::MessageWriter writer(&method_call); | 353 dbus::MessageWriter writer(&method_call); |
354 writer.AppendString(name); | 354 writer.AppendString(name); |
355 scoped_ptr<dbus::Response> response( | 355 scoped_ptr<dbus::Response> response( |
356 blocking_method_caller_->CallMethodAndBlock(&method_call)); | 356 blocking_method_caller_->CallMethodAndBlock(&method_call)); |
357 if (!response.get()) | 357 if (!response.get()) |
358 return false; | 358 return false; |
359 dbus::MessageReader reader(response.get()); | 359 dbus::MessageReader reader(response.get()); |
360 uint8* bytes = NULL; | 360 const uint8* bytes = NULL; |
361 size_t length = 0; | 361 size_t length = 0; |
362 if (!reader.PopArrayOfBytes(&bytes, &length) || | 362 if (!reader.PopArrayOfBytes(&bytes, &length) || |
363 !reader.PopBool(successful)) | 363 !reader.PopBool(successful)) |
364 return false; | 364 return false; |
365 value->assign(bytes, bytes + length); | 365 value->assign(bytes, bytes + length); |
366 return true; | 366 return true; |
367 } | 367 } |
368 | 368 |
369 // CryptohomeClient override. | 369 // CryptohomeClient override. |
370 virtual bool InstallAttributesSet(const std::string& name, | 370 virtual bool InstallAttributesSet(const std::string& name, |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 } | 730 } |
731 | 731 |
732 // Handles the result of GetSystemSalt(). | 732 // Handles the result of GetSystemSalt(). |
733 void OnGetSystemSalt(const GetSystemSaltCallback& callback, | 733 void OnGetSystemSalt(const GetSystemSaltCallback& callback, |
734 dbus::Response* response) { | 734 dbus::Response* response) { |
735 if (!response) { | 735 if (!response) { |
736 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); | 736 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); |
737 return; | 737 return; |
738 } | 738 } |
739 dbus::MessageReader reader(response); | 739 dbus::MessageReader reader(response); |
740 uint8* bytes = NULL; | 740 const uint8* bytes = NULL; |
741 size_t length = 0; | 741 size_t length = 0; |
742 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 742 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
743 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); | 743 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); |
744 return; | 744 return; |
745 } | 745 } |
746 callback.Run(DBUS_METHOD_CALL_SUCCESS, | 746 callback.Run(DBUS_METHOD_CALL_SUCCESS, |
747 std::vector<uint8>(bytes, bytes + length)); | 747 std::vector<uint8>(bytes, bytes + length)); |
748 } | 748 } |
749 | 749 |
750 // Calls a method without result values. | 750 // Calls a method without result values. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 } | 820 } |
821 | 821 |
822 // Handles responses for methods with a bool result and data. | 822 // Handles responses for methods with a bool result and data. |
823 void OnDataMethod(const DataMethodCallback& callback, | 823 void OnDataMethod(const DataMethodCallback& callback, |
824 dbus::Response* response) { | 824 dbus::Response* response) { |
825 if (!response) { | 825 if (!response) { |
826 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); | 826 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); |
827 return; | 827 return; |
828 } | 828 } |
829 dbus::MessageReader reader(response); | 829 dbus::MessageReader reader(response); |
830 uint8* data_buffer = NULL; | 830 const uint8* data_buffer = NULL; |
831 size_t data_length = 0; | 831 size_t data_length = 0; |
832 bool result = false; | 832 bool result = false; |
833 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || | 833 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || |
834 !reader.PopBool(&result)) { | 834 !reader.PopBool(&result)) { |
835 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); | 835 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); |
836 return; | 836 return; |
837 } | 837 } |
838 std::string data(reinterpret_cast<char*>(data_buffer), data_length); | 838 std::string data(reinterpret_cast<const char*>(data_buffer), data_length); |
839 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); | 839 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); |
840 } | 840 } |
841 | 841 |
842 // Handles responses for Pkcs11GetTpmTokenInfo. | 842 // Handles responses for Pkcs11GetTpmTokenInfo. |
843 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, | 843 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, |
844 dbus::Response* response) { | 844 dbus::Response* response) { |
845 if (!response) { | 845 if (!response) { |
846 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); | 846 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); |
847 return; | 847 return; |
848 } | 848 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } | 893 } |
894 if (!async_call_status_handler_.is_null()) | 894 if (!async_call_status_handler_.is_null()) |
895 async_call_status_handler_.Run(async_id, return_status, return_code); | 895 async_call_status_handler_.Run(async_id, return_status, return_code); |
896 } | 896 } |
897 | 897 |
898 // Handles AsyncCallStatusWithData signal. | 898 // Handles AsyncCallStatusWithData signal. |
899 void OnAsyncCallStatusWithData(dbus::Signal* signal) { | 899 void OnAsyncCallStatusWithData(dbus::Signal* signal) { |
900 dbus::MessageReader reader(signal); | 900 dbus::MessageReader reader(signal); |
901 int async_id = 0; | 901 int async_id = 0; |
902 bool return_status = false; | 902 bool return_status = false; |
903 uint8* return_data_buffer = NULL; | 903 const uint8* return_data_buffer = NULL; |
904 size_t return_data_length = 0; | 904 size_t return_data_length = 0; |
905 if (!reader.PopInt32(&async_id) || | 905 if (!reader.PopInt32(&async_id) || |
906 !reader.PopBool(&return_status) || | 906 !reader.PopBool(&return_status) || |
907 !reader.PopArrayOfBytes(&return_data_buffer, &return_data_length)) { | 907 !reader.PopArrayOfBytes(&return_data_buffer, &return_data_length)) { |
908 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 908 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
909 return; | 909 return; |
910 } | 910 } |
911 if (!async_call_status_data_handler_.is_null()) { | 911 if (!async_call_status_data_handler_.is_null()) { |
912 std::string return_data(reinterpret_cast<char*>(return_data_buffer), | 912 std::string return_data(reinterpret_cast<const char*>(return_data_buffer), |
913 return_data_length); | 913 return_data_length); |
914 async_call_status_data_handler_.Run(async_id, return_status, return_data); | 914 async_call_status_data_handler_.Run(async_id, return_status, return_data); |
915 } | 915 } |
916 } | 916 } |
917 | 917 |
918 // Handles the result of signal connection setup. | 918 // Handles the result of signal connection setup. |
919 void OnSignalConnected(const std::string& interface, | 919 void OnSignalConnected(const std::string& interface, |
920 const std::string& signal, | 920 const std::string& signal, |
921 bool succeeded) { | 921 bool succeeded) { |
922 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << | 922 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << |
(...skipping 26 matching lines...) Expand all Loading... |
949 return new CryptohomeClientImpl(); | 949 return new CryptohomeClientImpl(); |
950 } | 950 } |
951 | 951 |
952 // static | 952 // static |
953 std::string CryptohomeClient::GetStubSanitizedUsername( | 953 std::string CryptohomeClient::GetStubSanitizedUsername( |
954 const std::string& username) { | 954 const std::string& username) { |
955 return username + kUserIdStubHashSuffix; | 955 return username + kUserIdStubHashSuffix; |
956 } | 956 } |
957 | 957 |
958 } // namespace chromeos | 958 } // namespace chromeos |
OLD | NEW |