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

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

Issue 2748743004: cryptohome: Add dbus method and signal name for encryption migration. (Closed)
Patch Set: Roll DEPS Created 3 years, 9 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
« no previous file with comments | « chromeos/dbus/cryptohome_client.h ('k') | chromeos/dbus/fake_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 (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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 { 66 void SetLowDiskSpaceHandler(const LowDiskSpaceHandler& handler) override {
67 low_disk_space_handler_ = handler; 67 low_disk_space_handler_ = handler;
68 } 68 }
69 69
70 // CryptohomeClient override. 70 // CryptohomeClient override.
71 void SetDircryptoMigrationProgressHandler(
72 const DircryptoMigrationProgessHandler& handler) override {
73 dircrypto_migration_progress_handler_ = handler;
74 }
75
76 // CryptohomeClient override.
71 void WaitForServiceToBeAvailable( 77 void WaitForServiceToBeAvailable(
72 const WaitForServiceToBeAvailableCallback& callback) override { 78 const WaitForServiceToBeAvailableCallback& callback) override {
73 proxy_->WaitForServiceToBeAvailable(callback); 79 proxy_->WaitForServiceToBeAvailable(callback);
74 } 80 }
75 81
76 // CryptohomeClient override. 82 // CryptohomeClient override.
77 void IsMounted(const BoolDBusMethodCallback& callback) override { 83 void IsMounted(const BoolDBusMethodCallback& callback) override {
78 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, 84 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface,
79 cryptohome::kCryptohomeIsMounted); 85 cryptohome::kCryptohomeIsMounted);
80 CallBoolMethod(&method_call, callback); 86 CallBoolMethod(&method_call, callback);
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 dbus::MessageWriter writer(&method_call); 926 dbus::MessageWriter writer(&method_call);
921 writer.AppendProtoAsArrayOfBytes(request); 927 writer.AppendProtoAsArrayOfBytes(request);
922 928
923 proxy_->CallMethod(&method_call, 929 proxy_->CallMethod(&method_call,
924 kTpmDBusTimeoutMs , 930 kTpmDBusTimeoutMs ,
925 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, 931 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod,
926 weak_ptr_factory_.GetWeakPtr(), 932 weak_ptr_factory_.GetWeakPtr(),
927 callback)); 933 callback));
928 } 934 }
929 935
936 void MigrateToDircrypto(const cryptohome::Identification& cryptohome_id,
937 const cryptohome::AuthorizationRequest& auth,
938 const VoidDBusMethodCallback& callback) override {
939 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface,
940 cryptohome::kCryptohomeMigrateToDircrypto);
941
942 cryptohome::AccountIdentifier id_proto;
943 FillIdentificationProtobuf(cryptohome_id, &id_proto);
944
945 dbus::MessageWriter writer(&method_call);
946 writer.AppendProtoAsArrayOfBytes(id_proto);
947 writer.AppendProtoAsArrayOfBytes(auth);
948
949 // The migration progress takes unpredicatable time depending on the
950 // user file size and the number. Setting the time limit to infinite.
951 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
952 base::Bind(&CryptohomeClientImpl::OnVoidMethod,
953 weak_ptr_factory_.GetWeakPtr(), callback));
954 }
955
930 protected: 956 protected:
931 void Init(dbus::Bus* bus) override { 957 void Init(dbus::Bus* bus) override {
932 proxy_ = bus->GetObjectProxy( 958 proxy_ = bus->GetObjectProxy(
933 cryptohome::kCryptohomeServiceName, 959 cryptohome::kCryptohomeServiceName,
934 dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); 960 dbus::ObjectPath(cryptohome::kCryptohomeServicePath));
935 961
936 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); 962 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_));
937 963
938 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, 964 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface,
939 cryptohome::kSignalAsyncCallStatus, 965 cryptohome::kSignalAsyncCallStatus,
940 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus, 966 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus,
941 weak_ptr_factory_.GetWeakPtr()), 967 weak_ptr_factory_.GetWeakPtr()),
942 base::Bind(&CryptohomeClientImpl::OnSignalConnected, 968 base::Bind(&CryptohomeClientImpl::OnSignalConnected,
943 weak_ptr_factory_.GetWeakPtr())); 969 weak_ptr_factory_.GetWeakPtr()));
944 proxy_->ConnectToSignal( 970 proxy_->ConnectToSignal(
945 cryptohome::kCryptohomeInterface, 971 cryptohome::kCryptohomeInterface,
946 cryptohome::kSignalAsyncCallStatusWithData, 972 cryptohome::kSignalAsyncCallStatusWithData,
947 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, 973 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData,
948 weak_ptr_factory_.GetWeakPtr()), 974 weak_ptr_factory_.GetWeakPtr()),
949 base::Bind(&CryptohomeClientImpl::OnSignalConnected, 975 base::Bind(&CryptohomeClientImpl::OnSignalConnected,
950 weak_ptr_factory_.GetWeakPtr())); 976 weak_ptr_factory_.GetWeakPtr()));
951 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, 977 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface,
952 cryptohome::kSignalLowDiskSpace, 978 cryptohome::kSignalLowDiskSpace,
953 base::Bind(&CryptohomeClientImpl::OnLowDiskSpace, 979 base::Bind(&CryptohomeClientImpl::OnLowDiskSpace,
954 weak_ptr_factory_.GetWeakPtr()), 980 weak_ptr_factory_.GetWeakPtr()),
955 base::Bind(&CryptohomeClientImpl::OnSignalConnected, 981 base::Bind(&CryptohomeClientImpl::OnSignalConnected,
956 weak_ptr_factory_.GetWeakPtr())); 982 weak_ptr_factory_.GetWeakPtr()));
983 proxy_->ConnectToSignal(
984 cryptohome::kCryptohomeInterface,
985 cryptohome::kSignalDircryptoMigrationProgress,
986 base::Bind(&CryptohomeClientImpl::OnDircryptoMigrationProgress,
987 weak_ptr_factory_.GetWeakPtr()),
988 base::Bind(&CryptohomeClientImpl::OnSignalConnected,
989 weak_ptr_factory_.GetWeakPtr()));
957 } 990 }
958 991
959 private: 992 private:
960 // Handles the result of AsyncXXX methods. 993 // Handles the result of AsyncXXX methods.
961 void OnAsyncMethodCall(const AsyncMethodCallback& callback, 994 void OnAsyncMethodCall(const AsyncMethodCallback& callback,
962 dbus::Response* response) { 995 dbus::Response* response) {
963 if (!response) { 996 if (!response) {
964 callback.Run(kNotReadyAsyncId); 997 callback.Run(kNotReadyAsyncId);
965 return; 998 return;
966 } 999 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 dbus::MessageReader reader(signal); 1213 dbus::MessageReader reader(signal);
1181 uint64_t disk_free_bytes = 0; 1214 uint64_t disk_free_bytes = 0;
1182 if (!reader.PopUint64(&disk_free_bytes)) { 1215 if (!reader.PopUint64(&disk_free_bytes)) {
1183 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 1216 LOG(ERROR) << "Invalid signal: " << signal->ToString();
1184 return; 1217 return;
1185 } 1218 }
1186 if (!low_disk_space_handler_.is_null()) 1219 if (!low_disk_space_handler_.is_null())
1187 low_disk_space_handler_.Run(disk_free_bytes); 1220 low_disk_space_handler_.Run(disk_free_bytes);
1188 } 1221 }
1189 1222
1223 // Handles DircryptoMigrationProgess signal.
1224 void OnDircryptoMigrationProgress(dbus::Signal* signal) {
1225 if (dircrypto_migration_progress_handler_.is_null())
1226 return;
1227
1228 dbus::MessageReader reader(signal);
1229 int status = 0;
1230 uint64_t current_bytes = 0, total_bytes = 0;
1231 if (!reader.PopInt32(&status) || !reader.PopUint64(&current_bytes) ||
1232 !reader.PopUint64(&total_bytes)) {
1233 LOG(ERROR) << "Invalid signal: " << signal->ToString();
1234 return;
1235 }
1236 dircrypto_migration_progress_handler_.Run(
1237 static_cast<cryptohome::DircryptoMigrationStatus>(status),
1238 current_bytes, total_bytes);
1239 }
1240
1190 // Handles the result of signal connection setup. 1241 // Handles the result of signal connection setup.
1191 void OnSignalConnected(const std::string& interface, 1242 void OnSignalConnected(const std::string& interface,
1192 const std::string& signal, 1243 const std::string& signal,
1193 bool succeeded) { 1244 bool succeeded) {
1194 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << 1245 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " <<
1195 signal << " failed."; 1246 signal << " failed.";
1196 } 1247 }
1197 1248
1198 dbus::ObjectProxy* proxy_; 1249 dbus::ObjectProxy* proxy_;
1199 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; 1250 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_;
1200 AsyncCallStatusHandler async_call_status_handler_; 1251 AsyncCallStatusHandler async_call_status_handler_;
1201 AsyncCallStatusWithDataHandler async_call_status_data_handler_; 1252 AsyncCallStatusWithDataHandler async_call_status_data_handler_;
1202 LowDiskSpaceHandler low_disk_space_handler_; 1253 LowDiskSpaceHandler low_disk_space_handler_;
1254 DircryptoMigrationProgessHandler dircrypto_migration_progress_handler_;
1203 1255
1204 // Note: This should remain the last member so it'll be destroyed and 1256 // Note: This should remain the last member so it'll be destroyed and
1205 // invalidate its weak pointers before any other members are destroyed. 1257 // invalidate its weak pointers before any other members are destroyed.
1206 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; 1258 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_;
1207 1259
1208 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl); 1260 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl);
1209 }; 1261 };
1210 1262
1211 } // namespace 1263 } // namespace
1212 1264
1213 //////////////////////////////////////////////////////////////////////////////// 1265 ////////////////////////////////////////////////////////////////////////////////
1214 // CryptohomeClient 1266 // CryptohomeClient
1215 1267
1216 CryptohomeClient::CryptohomeClient() {} 1268 CryptohomeClient::CryptohomeClient() {}
1217 1269
1218 CryptohomeClient::~CryptohomeClient() {} 1270 CryptohomeClient::~CryptohomeClient() {}
1219 1271
1220 // static 1272 // static
1221 CryptohomeClient* CryptohomeClient::Create() { 1273 CryptohomeClient* CryptohomeClient::Create() {
1222 return new CryptohomeClientImpl(); 1274 return new CryptohomeClientImpl();
1223 } 1275 }
1224 1276
1225 // static 1277 // static
1226 std::string CryptohomeClient::GetStubSanitizedUsername( 1278 std::string CryptohomeClient::GetStubSanitizedUsername(
1227 const cryptohome::Identification& cryptohome_id) { 1279 const cryptohome::Identification& cryptohome_id) {
1228 return cryptohome_id.id() + kUserIdStubHashSuffix; 1280 return cryptohome_id.id() + kUserIdStubHashSuffix;
1229 } 1281 }
1230 1282
1231 } // namespace chromeos 1283 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cryptohome_client.h ('k') | chromeos/dbus/fake_cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698