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" |
11 #include "chromeos/cryptohome/async_method_caller.h" | 11 #include "chromeos/cryptohome/async_method_caller.h" |
12 #include "chromeos/dbus/blocking_method_caller.h" | 12 #include "chromeos/dbus/blocking_method_caller.h" |
13 #include "chromeos/dbus/cryptohome/key.pb.h" | 13 #include "chromeos/dbus/cryptohome/key.pb.h" |
14 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 14 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
15 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 16 #include "dbus/message.h" |
17 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
| 23 const int CryptohomeClient::kNotReadyAsyncId = -1; |
| 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // This suffix is appended to user_id to get hash in stub implementation: | 27 // This suffix is appended to user_id to get hash in stub implementation: |
26 // stub_hash = "[user_id]-hash"; | 28 // stub_hash = "[user_id]-hash"; |
27 static const char kUserIdStubHashSuffix[] = "-hash"; | 29 static const char kUserIdStubHashSuffix[] = "-hash"; |
28 | 30 |
29 // Timeout for TPM operations. On slow machines it should be larger, than | 31 // Timeout for TPM operations. On slow machines it should be larger, than |
30 // default DBus timeout. TPM operations can take up to 80 seconds, so limit | 32 // default DBus timeout. TPM operations can take up to 80 seconds, so limit |
31 // is 2 minutes. | 33 // is 2 minutes. |
32 const int kTpmDBusTimeoutMs = 2 * 60 * 1000; | 34 const int kTpmDBusTimeoutMs = 2 * 60 * 1000; |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, | 877 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, |
876 weak_ptr_factory_.GetWeakPtr()), | 878 weak_ptr_factory_.GetWeakPtr()), |
877 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 879 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
878 weak_ptr_factory_.GetWeakPtr())); | 880 weak_ptr_factory_.GetWeakPtr())); |
879 } | 881 } |
880 | 882 |
881 private: | 883 private: |
882 // Handles the result of AsyncXXX methods. | 884 // Handles the result of AsyncXXX methods. |
883 void OnAsyncMethodCall(const AsyncMethodCallback& callback, | 885 void OnAsyncMethodCall(const AsyncMethodCallback& callback, |
884 dbus::Response* response) { | 886 dbus::Response* response) { |
885 if (!response) | 887 if (!response) { |
| 888 callback.Run(kNotReadyAsyncId); |
886 return; | 889 return; |
| 890 } |
887 dbus::MessageReader reader(response); | 891 dbus::MessageReader reader(response); |
888 int async_id = 0; | 892 int async_id = 0; |
889 if (!reader.PopInt32(&async_id)) { | 893 if (!reader.PopInt32(&async_id)) { |
890 LOG(ERROR) << "Invalid response: " << response->ToString(); | 894 LOG(ERROR) << "Invalid response: " << response->ToString(); |
891 return; | 895 return; |
892 } | 896 } |
893 callback.Run(async_id); | 897 callback.Run(async_id); |
894 } | 898 } |
895 | 899 |
896 // Handles the result of GetSystemSalt(). | 900 // Handles the result of GetSystemSalt(). |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 return new CryptohomeClientImpl(); | 1133 return new CryptohomeClientImpl(); |
1130 } | 1134 } |
1131 | 1135 |
1132 // static | 1136 // static |
1133 std::string CryptohomeClient::GetStubSanitizedUsername( | 1137 std::string CryptohomeClient::GetStubSanitizedUsername( |
1134 const std::string& username) { | 1138 const std::string& username) { |
1135 return username + kUserIdStubHashSuffix; | 1139 return username + kUserIdStubHashSuffix; |
1136 } | 1140 } |
1137 | 1141 |
1138 } // namespace chromeos | 1142 } // namespace chromeos |
OLD | NEW |