OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( | 81 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( |
82 const UserContext& user_context, | 82 const UserContext& user_context, |
83 base::ListValue* remote_devices, | 83 base::ListValue* remote_devices, |
84 const RefreshKeysCallback& callback) { | 84 const RefreshKeysCallback& callback) { |
85 EasyUnlockTpmKeyManager* tpm_key_manager = | 85 EasyUnlockTpmKeyManager* tpm_key_manager = |
86 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( | 86 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
87 user_context.GetAccountId().GetUserEmail()); | 87 user_context.GetAccountId().GetUserEmail()); |
88 const std::string tpm_public_key = tpm_key_manager->GetPublicTpmKey( | 88 const std::string tpm_public_key = |
89 user_context.GetAccountId().GetUserEmail()); | 89 tpm_key_manager->GetPublicTpmKey(user_context.GetAccountId()); |
90 | 90 |
91 EasyUnlockDeviceKeyDataList devices; | 91 EasyUnlockDeviceKeyDataList devices; |
92 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) | 92 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) |
93 devices.clear(); | 93 devices.clear(); |
94 | 94 |
95 write_operation_queue_.push_back(new EasyUnlockRefreshKeysOperation( | 95 write_operation_queue_.push_back(new EasyUnlockRefreshKeysOperation( |
96 user_context, tpm_public_key, devices, | 96 user_context, tpm_public_key, devices, |
97 base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed, | 97 base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed, |
98 weak_ptr_factory_.GetWeakPtr(), callback))); | 98 weak_ptr_factory_.GetWeakPtr(), callback))); |
99 RunNextOperation(); | 99 RunNextOperation(); |
100 } | 100 } |
101 | 101 |
102 void EasyUnlockKeyManager::GetDeviceDataList( | 102 void EasyUnlockKeyManager::GetDeviceDataList( |
103 const UserContext& user_context, | 103 const UserContext& user_context, |
104 const GetDeviceDataListCallback& callback) { | 104 const GetDeviceDataListCallback& callback) { |
105 read_operation_queue_.push_back(new EasyUnlockGetKeysOperation( | 105 read_operation_queue_.push_back(new EasyUnlockGetKeysOperation( |
106 user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched, | 106 user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched, |
107 weak_ptr_factory_.GetWeakPtr(), callback))); | 107 weak_ptr_factory_.GetWeakPtr(), callback))); |
108 RunNextOperation(); | 108 RunNextOperation(); |
109 } | 109 } |
110 | 110 |
111 // static | 111 // static |
112 void EasyUnlockKeyManager::DeviceDataToRemoteDeviceDictionary( | 112 void EasyUnlockKeyManager::DeviceDataToRemoteDeviceDictionary( |
113 const std::string& user_id, | 113 const AccountId& account_id, |
114 const EasyUnlockDeviceKeyData& data, | 114 const EasyUnlockDeviceKeyData& data, |
115 base::DictionaryValue* dict) { | 115 base::DictionaryValue* dict) { |
116 dict->SetString(kKeyBluetoothAddress, data.bluetooth_address); | 116 dict->SetString(kKeyBluetoothAddress, data.bluetooth_address); |
117 dict->SetInteger(kKeyBluetoothType, static_cast<int>(data.bluetooth_type)); | 117 dict->SetInteger(kKeyBluetoothType, static_cast<int>(data.bluetooth_type)); |
118 dict->SetString(kKeyPsk, data.psk); | 118 dict->SetString(kKeyPsk, data.psk); |
119 scoped_ptr<base::DictionaryValue> permit_record(new base::DictionaryValue); | 119 scoped_ptr<base::DictionaryValue> permit_record(new base::DictionaryValue); |
120 dict->Set(kKeyPermitRecord, permit_record.release()); | 120 dict->Set(kKeyPermitRecord, permit_record.release()); |
121 dict->SetString(kKeyPermitId, data.public_key); | 121 dict->SetString(kKeyPermitId, data.public_key); |
122 dict->SetString(kKeyPermitData, data.public_key); | 122 dict->SetString(kKeyPermitData, data.public_key); |
123 dict->SetString(kKeyPermitType, kPermitTypeLicence); | 123 dict->SetString(kKeyPermitType, kPermitTypeLicence); |
124 dict->SetString(kKeyPermitPermitId, | 124 dict->SetString(kKeyPermitPermitId, |
125 base::StringPrintf(kPermitPermitIdFormat, | 125 base::StringPrintf(kPermitPermitIdFormat, |
126 user_id.c_str())); | 126 account_id.GetUserEmail().c_str())); |
127 } | 127 } |
128 | 128 |
129 // static | 129 // static |
130 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( | 130 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( |
131 const base::DictionaryValue& dict, | 131 const base::DictionaryValue& dict, |
132 EasyUnlockDeviceKeyData* data) { | 132 EasyUnlockDeviceKeyData* data) { |
133 std::string bluetooth_address; | 133 std::string bluetooth_address; |
134 std::string public_key; | 134 std::string public_key; |
135 std::string psk; | 135 std::string psk; |
136 | 136 |
(...skipping 17 matching lines...) Expand all Loading... |
154 } | 154 } |
155 | 155 |
156 data->bluetooth_address.swap(bluetooth_address); | 156 data->bluetooth_address.swap(bluetooth_address); |
157 data->public_key.swap(public_key); | 157 data->public_key.swap(public_key); |
158 data->psk.swap(psk); | 158 data->psk.swap(psk); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 // static | 162 // static |
163 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 163 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
164 const std::string& user_id, | 164 const AccountId& account_id, |
165 const EasyUnlockDeviceKeyDataList& data_list, | 165 const EasyUnlockDeviceKeyDataList& data_list, |
166 base::ListValue* device_list) { | 166 base::ListValue* device_list) { |
167 device_list->Clear(); | 167 device_list->Clear(); |
168 for (size_t i = 0; i < data_list.size(); ++i) { | 168 for (size_t i = 0; i < data_list.size(); ++i) { |
169 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue); | 169 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue); |
170 DeviceDataToRemoteDeviceDictionary( | 170 DeviceDataToRemoteDeviceDictionary(account_id, data_list[i], |
171 user_id, data_list[i], device_dict.get()); | 171 device_dict.get()); |
172 device_list->Append(device_dict.release()); | 172 device_list->Append(device_dict.release()); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 // static | 176 // static |
177 bool EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList( | 177 bool EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList( |
178 const base::ListValue& device_list, | 178 const base::ListValue& device_list, |
179 EasyUnlockDeviceKeyDataList* data_list) { | 179 EasyUnlockDeviceKeyDataList* data_list) { |
180 EasyUnlockDeviceKeyDataList parsed_devices; | 180 EasyUnlockDeviceKeyDataList parsed_devices; |
181 for (base::ListValue::const_iterator it = device_list.begin(); | 181 for (base::ListValue::const_iterator it = device_list.begin(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 const EasyUnlockDeviceKeyDataList& fetched_data) { | 232 const EasyUnlockDeviceKeyDataList& fetched_data) { |
233 if (!callback.is_null()) | 233 if (!callback.is_null()) |
234 callback.Run(fetch_success, fetched_data); | 234 callback.Run(fetch_success, fetched_data); |
235 | 235 |
236 DCHECK(pending_read_operation_); | 236 DCHECK(pending_read_operation_); |
237 pending_read_operation_.reset(); | 237 pending_read_operation_.reset(); |
238 RunNextOperation(); | 238 RunNextOperation(); |
239 } | 239 } |
240 | 240 |
241 } // namespace chromeos | 241 } // namespace chromeos |
OLD | NEW |