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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 async_call_status_data_handler_ = data_handler; | 56 async_call_status_data_handler_ = data_handler; |
57 } | 57 } |
58 | 58 |
59 // CryptohomeClient override. | 59 // CryptohomeClient override. |
60 void ResetAsyncCallStatusHandlers() override { | 60 void ResetAsyncCallStatusHandlers() override { |
61 async_call_status_handler_.Reset(); | 61 async_call_status_handler_.Reset(); |
62 async_call_status_data_handler_.Reset(); | 62 async_call_status_data_handler_.Reset(); |
63 } | 63 } |
64 | 64 |
65 // CryptohomeClient override. | 65 // CryptohomeClient override. |
66 void SetLowDiskSpaceHandler(const LowDiskSpaceHandler& handler) override { | |
67 low_disk_space_handler_ = handler; | |
68 } | |
69 | |
70 // CryptohomeClient override. | |
71 void ResetLowDiskSpaceHandler() override { low_disk_space_handler_.Reset(); } | |
72 | |
73 // CryptohomeClient override. | |
66 void WaitForServiceToBeAvailable( | 74 void WaitForServiceToBeAvailable( |
67 const WaitForServiceToBeAvailableCallback& callback) override { | 75 const WaitForServiceToBeAvailableCallback& callback) override { |
68 proxy_->WaitForServiceToBeAvailable(callback); | 76 proxy_->WaitForServiceToBeAvailable(callback); |
69 } | 77 } |
70 | 78 |
71 // CryptohomeClient override. | 79 // CryptohomeClient override. |
72 void IsMounted(const BoolDBusMethodCallback& callback) override { | 80 void IsMounted(const BoolDBusMethodCallback& callback) override { |
73 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 81 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
74 cryptohome::kCryptohomeIsMounted); | 82 cryptohome::kCryptohomeIsMounted); |
75 CallBoolMethod(&method_call, callback); | 83 CallBoolMethod(&method_call, callback); |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 weak_ptr_factory_.GetWeakPtr()), | 929 weak_ptr_factory_.GetWeakPtr()), |
922 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 930 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
923 weak_ptr_factory_.GetWeakPtr())); | 931 weak_ptr_factory_.GetWeakPtr())); |
924 proxy_->ConnectToSignal( | 932 proxy_->ConnectToSignal( |
925 cryptohome::kCryptohomeInterface, | 933 cryptohome::kCryptohomeInterface, |
926 cryptohome::kSignalAsyncCallStatusWithData, | 934 cryptohome::kSignalAsyncCallStatusWithData, |
927 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, | 935 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, |
928 weak_ptr_factory_.GetWeakPtr()), | 936 weak_ptr_factory_.GetWeakPtr()), |
929 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 937 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
930 weak_ptr_factory_.GetWeakPtr())); | 938 weak_ptr_factory_.GetWeakPtr())); |
939 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, | |
940 cryptohome::kSignalLowDiskSpace, | |
941 base::Bind(&CryptohomeClientImpl::OnLowDiskSpace, | |
942 weak_ptr_factory_.GetWeakPtr()), | |
943 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | |
944 weak_ptr_factory_.GetWeakPtr())); | |
931 } | 945 } |
932 | 946 |
933 private: | 947 private: |
934 // Handles the result of AsyncXXX methods. | 948 // Handles the result of AsyncXXX methods. |
935 void OnAsyncMethodCall(const AsyncMethodCallback& callback, | 949 void OnAsyncMethodCall(const AsyncMethodCallback& callback, |
936 dbus::Response* response) { | 950 dbus::Response* response) { |
937 if (!response) { | 951 if (!response) { |
938 callback.Run(kNotReadyAsyncId); | 952 callback.Run(kNotReadyAsyncId); |
939 return; | 953 return; |
940 } | 954 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1142 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 1156 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
1143 return; | 1157 return; |
1144 } | 1158 } |
1145 if (!async_call_status_data_handler_.is_null()) { | 1159 if (!async_call_status_data_handler_.is_null()) { |
1146 std::string return_data(reinterpret_cast<const char*>(return_data_buffer), | 1160 std::string return_data(reinterpret_cast<const char*>(return_data_buffer), |
1147 return_data_length); | 1161 return_data_length); |
1148 async_call_status_data_handler_.Run(async_id, return_status, return_data); | 1162 async_call_status_data_handler_.Run(async_id, return_status, return_data); |
1149 } | 1163 } |
1150 } | 1164 } |
1151 | 1165 |
1166 // Handles LowDiskSpace signal. | |
1167 void OnLowDiskSpace(dbus::Signal* signal) { | |
1168 dbus::MessageReader reader(signal); | |
1169 uint64_t disk_free_bytes = 0; | |
1170 if (!reader.PopUint64(&disk_free_bytes)) { | |
1171 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | |
1172 return; | |
1173 } | |
1174 low_disk_space_handler_.Run(disk_free_bytes); | |
yoshiki
2016/06/23 08:00:45
low_disk_space_handler_ may be null so null check
dspaid
2016/06/27 05:40:04
Using WeakPtr now, which will result in a no-op if
| |
1175 } | |
1176 | |
1152 // Handles the result of signal connection setup. | 1177 // Handles the result of signal connection setup. |
1153 void OnSignalConnected(const std::string& interface, | 1178 void OnSignalConnected(const std::string& interface, |
1154 const std::string& signal, | 1179 const std::string& signal, |
1155 bool succeeded) { | 1180 bool succeeded) { |
1156 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << | 1181 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << |
1157 signal << " failed."; | 1182 signal << " failed."; |
1158 } | 1183 } |
1159 | 1184 |
1160 dbus::ObjectProxy* proxy_; | 1185 dbus::ObjectProxy* proxy_; |
1161 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 1186 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
1162 AsyncCallStatusHandler async_call_status_handler_; | 1187 AsyncCallStatusHandler async_call_status_handler_; |
1163 AsyncCallStatusWithDataHandler async_call_status_data_handler_; | 1188 AsyncCallStatusWithDataHandler async_call_status_data_handler_; |
1189 LowDiskSpaceHandler low_disk_space_handler_; | |
1164 | 1190 |
1165 // Note: This should remain the last member so it'll be destroyed and | 1191 // Note: This should remain the last member so it'll be destroyed and |
1166 // invalidate its weak pointers before any other members are destroyed. | 1192 // invalidate its weak pointers before any other members are destroyed. |
1167 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; | 1193 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; |
1168 | 1194 |
1169 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl); | 1195 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl); |
1170 }; | 1196 }; |
1171 | 1197 |
1172 } // namespace | 1198 } // namespace |
1173 | 1199 |
1174 //////////////////////////////////////////////////////////////////////////////// | 1200 //////////////////////////////////////////////////////////////////////////////// |
1175 // CryptohomeClient | 1201 // CryptohomeClient |
1176 | 1202 |
1177 CryptohomeClient::CryptohomeClient() {} | 1203 CryptohomeClient::CryptohomeClient() {} |
1178 | 1204 |
1179 CryptohomeClient::~CryptohomeClient() {} | 1205 CryptohomeClient::~CryptohomeClient() {} |
1180 | 1206 |
1181 // static | 1207 // static |
1182 CryptohomeClient* CryptohomeClient::Create() { | 1208 CryptohomeClient* CryptohomeClient::Create() { |
1183 return new CryptohomeClientImpl(); | 1209 return new CryptohomeClientImpl(); |
1184 } | 1210 } |
1185 | 1211 |
1186 // static | 1212 // static |
1187 std::string CryptohomeClient::GetStubSanitizedUsername( | 1213 std::string CryptohomeClient::GetStubSanitizedUsername( |
1188 const cryptohome::Identification& cryptohome_id) { | 1214 const cryptohome::Identification& cryptohome_id) { |
1189 return cryptohome_id.id() + kUserIdStubHashSuffix; | 1215 return cryptohome_id.id() + kUserIdStubHashSuffix; |
1190 } | 1216 } |
1191 | 1217 |
1192 } // namespace chromeos | 1218 } // namespace chromeos |
OLD | NEW |