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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kKeyBluetoothAddress[] = "bluetoothAddress"; | 24 const char kKeyBluetoothAddress[] = "bluetoothAddress"; |
25 const char kKeyBluetoothType[] = "bluetoothType"; | 25 const char kKeyBluetoothType[] = "bluetoothType"; |
26 const char kKeyPermitRecord[] = "permitRecord"; | 26 const char kKeyPermitRecord[] = "permitRecord"; |
27 const char kKeyPermitId[] = "permitRecord.id"; | 27 const char kKeyPermitId[] = "permitRecord.id"; |
28 const char kKeyPermitPermitId[] = "permitRecord.permitId"; | 28 const char kKeyPermitPermitId[] = "permitRecord.permitId"; |
29 const char kKeyPermitData[] = "permitRecord.data"; | 29 const char kKeyPermitData[] = "permitRecord.data"; |
30 const char kKeyPermitType[] = "permitRecord.type"; | 30 const char kKeyPermitType[] = "permitRecord.type"; |
31 const char kKeyPsk[] = "psk"; | 31 const char kKeyPsk[] = "psk"; |
32 const char kKeySerializedBeaconSeeds[] = "serializedBeaconSeeds"; | |
32 | 33 |
33 const char kKeyLabelPrefix[] = "easy-unlock-"; | 34 const char kKeyLabelPrefix[] = "easy-unlock-"; |
34 | 35 |
35 const char kPermitPermitIdFormat[] = "permit://google.com/easyunlock/v1/%s"; | 36 const char kPermitPermitIdFormat[] = "permit://google.com/easyunlock/v1/%s"; |
36 const char kPermitTypeLicence[] = "licence"; | 37 const char kPermitTypeLicence[] = "licence"; |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 EasyUnlockKeyManager::EasyUnlockKeyManager() : weak_ptr_factory_(this) {} | 41 EasyUnlockKeyManager::EasyUnlockKeyManager() : weak_ptr_factory_(this) {} |
41 | 42 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 dict->SetString(kKeyPsk, data.psk); | 119 dict->SetString(kKeyPsk, data.psk); |
119 std::unique_ptr<base::DictionaryValue> permit_record( | 120 std::unique_ptr<base::DictionaryValue> permit_record( |
120 new base::DictionaryValue); | 121 new base::DictionaryValue); |
121 dict->Set(kKeyPermitRecord, std::move(permit_record)); | 122 dict->Set(kKeyPermitRecord, std::move(permit_record)); |
122 dict->SetString(kKeyPermitId, data.public_key); | 123 dict->SetString(kKeyPermitId, data.public_key); |
123 dict->SetString(kKeyPermitData, data.public_key); | 124 dict->SetString(kKeyPermitData, data.public_key); |
124 dict->SetString(kKeyPermitType, kPermitTypeLicence); | 125 dict->SetString(kKeyPermitType, kPermitTypeLicence); |
125 dict->SetString(kKeyPermitPermitId, | 126 dict->SetString(kKeyPermitPermitId, |
126 base::StringPrintf(kPermitPermitIdFormat, | 127 base::StringPrintf(kPermitPermitIdFormat, |
127 account_id.GetUserEmail().c_str())); | 128 account_id.GetUserEmail().c_str())); |
129 dict->SetString(kKeySerializedBeaconSeeds, data.serialized_beacon_seeds); | |
128 } | 130 } |
129 | 131 |
130 // static | 132 // static |
131 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( | 133 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( |
132 const base::DictionaryValue& dict, | 134 const base::DictionaryValue& dict, |
133 EasyUnlockDeviceKeyData* data) { | 135 EasyUnlockDeviceKeyData* data) { |
134 std::string bluetooth_address; | 136 std::string bluetooth_address; |
135 std::string public_key; | 137 std::string public_key; |
136 std::string psk; | 138 std::string psk; |
137 | 139 |
138 if (!dict.GetString(kKeyBluetoothAddress, &bluetooth_address) || | 140 if (!dict.GetString(kKeyBluetoothAddress, &bluetooth_address) || |
139 !dict.GetString(kKeyPermitId, &public_key) || | 141 !dict.GetString(kKeyPermitId, &public_key) || |
140 !dict.GetString(kKeyPsk, &psk)) { | 142 !dict.GetString(kKeyPsk, &psk)) { |
141 return false; | 143 return false; |
142 } | 144 } |
143 | 145 |
144 // TODO(tengs): Move this conditional up once we can be certain that the | 146 // TODO(tengs): Move this conditional up once we can be certain that the |
145 // dictionary will contain the Bluetooth type key. | 147 // dictionary will contain the Bluetooth type key. |
146 int bluetooth_type_as_int; | 148 int bluetooth_type_as_int; |
147 if (dict.GetInteger(kKeyBluetoothType, &bluetooth_type_as_int)) { | 149 if (dict.GetInteger(kKeyBluetoothType, &bluetooth_type_as_int)) { |
148 if (bluetooth_type_as_int >= EasyUnlockDeviceKeyData::NUM_BLUETOOTH_TYPES) { | 150 if (bluetooth_type_as_int >= EasyUnlockDeviceKeyData::NUM_BLUETOOTH_TYPES) { |
149 PA_LOG(ERROR) << "Invalid Bluetooth type: " << bluetooth_type_as_int; | 151 PA_LOG(ERROR) << "Invalid Bluetooth type: " << bluetooth_type_as_int; |
150 } else { | 152 } else { |
151 data->bluetooth_type = | 153 data->bluetooth_type = |
152 static_cast<EasyUnlockDeviceKeyData::BluetoothType>( | 154 static_cast<EasyUnlockDeviceKeyData::BluetoothType>( |
153 bluetooth_type_as_int); | 155 bluetooth_type_as_int); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
159 std::string serialized_beacon_seeds; | |
160 if (dict.GetString(kKeySerializedBeaconSeeds, &serialized_beacon_seeds)) { | |
161 data->serialized_beacon_seeds = serialized_beacon_seeds; | |
162 } else { | |
163 PA_LOG(ERROR) << "Expected serialized_beacon_seeds..."; | |
Ryan Hansberry
2017/05/09 02:44:08
Nit: use a period, not ellipses, and make this err
Tim Song
2017/05/10 18:23:26
Done.
| |
164 } | |
165 | |
157 data->bluetooth_address.swap(bluetooth_address); | 166 data->bluetooth_address.swap(bluetooth_address); |
158 data->public_key.swap(public_key); | 167 data->public_key.swap(public_key); |
159 data->psk.swap(psk); | 168 data->psk.swap(psk); |
160 return true; | 169 return true; |
161 } | 170 } |
162 | 171 |
163 // static | 172 // static |
164 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 173 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
165 const AccountId& account_id, | 174 const AccountId& account_id, |
166 const EasyUnlockDeviceKeyDataList& data_list, | 175 const EasyUnlockDeviceKeyDataList& data_list, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 const EasyUnlockDeviceKeyDataList& fetched_data) { | 243 const EasyUnlockDeviceKeyDataList& fetched_data) { |
235 if (!callback.is_null()) | 244 if (!callback.is_null()) |
236 callback.Run(fetch_success, fetched_data); | 245 callback.Run(fetch_success, fetched_data); |
237 | 246 |
238 DCHECK(pending_read_operation_); | 247 DCHECK(pending_read_operation_); |
239 pending_read_operation_.reset(); | 248 pending_read_operation_.reset(); |
240 RunNextOperation(); | 249 RunNextOperation(); |
241 } | 250 } |
242 | 251 |
243 } // namespace chromeos | 252 } // namespace chromeos |
OLD | NEW |