Chromium Code Reviews| 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/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const char kKeyBluetoothAddress[] = "bluetoothAddress"; | 17 const char kKeyBluetoothAddress[] = "bluetoothAddress"; |
| 18 const char kKeyPermitRecord[] = "permitRecord"; | 18 const char kKeyPermitRecord[] = "permitRecord"; |
| 19 const char kKeyId[] = "id"; | |
| 20 const char kKeyPermitId[] = "permitRecord.id"; | 19 const char kKeyPermitId[] = "permitRecord.id"; |
| 20 const char kKeyPermitPermitId[] = "permitRecord.permitId"; | |
| 21 const char kKeyPermitData[] = "permitRecord.data"; | |
| 22 const char kKeyPermitType[] = "permitRecord.type"; | |
| 21 const char kKeyPsk[] = "psk"; | 23 const char kKeyPsk[] = "psk"; |
| 22 | 24 |
| 23 const char kKeyLabelPrefix[] = "easy-unlock-"; | 25 const char kKeyLabelPrefix[] = "easy-unlock-"; |
| 24 | 26 |
| 27 const char kPermitPermitIdFormat[] = "permit://google.com/easyunlock/v1/%s"; | |
| 28 const char kPermitTypeValue[] = "licence"; | |
|
xiyuan
2014/09/19 22:26:48
nit: kPermitTypeValue -> kPermitTypeLicense
tbarzic
2014/09/19 23:59:18
Done.
| |
| 29 | |
| 25 } // namespace | 30 } // namespace |
| 26 | 31 |
| 27 EasyUnlockKeyManager::EasyUnlockKeyManager() | 32 EasyUnlockKeyManager::EasyUnlockKeyManager() |
| 28 : operation_id_(0), | 33 : operation_id_(0), |
| 29 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 30 } | 35 } |
| 31 | 36 |
| 32 EasyUnlockKeyManager::~EasyUnlockKeyManager() { | 37 EasyUnlockKeyManager::~EasyUnlockKeyManager() { |
| 33 STLDeleteContainerPairSecondPointers(get_keys_ops_.begin(), | 38 STLDeleteContainerPairSecondPointers(get_keys_ops_.begin(), |
| 34 get_keys_ops_.end()); | 39 get_keys_ops_.end()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 base::Bind(&EasyUnlockKeyManager::OnKeysFetched, | 92 base::Bind(&EasyUnlockKeyManager::OnKeysFetched, |
| 88 weak_ptr_factory_.GetWeakPtr(), | 93 weak_ptr_factory_.GetWeakPtr(), |
| 89 op_id, | 94 op_id, |
| 90 callback))); | 95 callback))); |
| 91 op->Start(); | 96 op->Start(); |
| 92 get_keys_ops_[op_id] = op.release(); | 97 get_keys_ops_[op_id] = op.release(); |
| 93 } | 98 } |
| 94 | 99 |
| 95 // static | 100 // static |
| 96 void EasyUnlockKeyManager::DeviceDataToRemoteDeviceDictionary( | 101 void EasyUnlockKeyManager::DeviceDataToRemoteDeviceDictionary( |
| 102 const std::string& user_id, | |
| 97 const EasyUnlockDeviceKeyData& data, | 103 const EasyUnlockDeviceKeyData& data, |
| 98 base::DictionaryValue* dict) { | 104 base::DictionaryValue* dict) { |
| 99 dict->SetString(kKeyBluetoothAddress, data.bluetooth_address); | 105 dict->SetString(kKeyBluetoothAddress, data.bluetooth_address); |
| 100 dict->SetString(kKeyPsk, data.psk); | 106 dict->SetString(kKeyPsk, data.psk); |
| 101 scoped_ptr<base::DictionaryValue> permit_record(new base::DictionaryValue); | 107 scoped_ptr<base::DictionaryValue> permit_record(new base::DictionaryValue); |
| 102 permit_record->SetString(kKeyId, data.public_key); | |
| 103 dict->Set(kKeyPermitRecord, permit_record.release()); | 108 dict->Set(kKeyPermitRecord, permit_record.release()); |
| 109 dict->SetString(kKeyPermitId, data.public_key); | |
| 110 dict->SetString(kKeyPermitData, data.public_key); | |
| 111 dict->SetString(kKeyPermitType, kPermitTypeValue); | |
| 112 dict->SetString(kKeyPermitPermitId, | |
| 113 base::StringPrintf(kPermitPermitIdFormat, | |
| 114 user_id.c_str())); | |
| 104 } | 115 } |
| 105 | 116 |
| 106 // static | 117 // static |
| 107 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( | 118 bool EasyUnlockKeyManager::RemoteDeviceDictionaryToDeviceData( |
| 108 const base::DictionaryValue& dict, | 119 const base::DictionaryValue& dict, |
| 109 EasyUnlockDeviceKeyData* data) { | 120 EasyUnlockDeviceKeyData* data) { |
| 110 std::string bluetooth_address; | 121 std::string bluetooth_address; |
| 111 std::string public_key; | 122 std::string public_key; |
| 112 std::string psk; | 123 std::string psk; |
| 113 | 124 |
| 114 if (!dict.GetString(kKeyBluetoothAddress, &bluetooth_address) || | 125 if (!dict.GetString(kKeyBluetoothAddress, &bluetooth_address) || |
| 115 !dict.GetString(kKeyPermitId, &public_key) || | 126 !dict.GetString(kKeyPermitId, &public_key) || |
| 116 !dict.GetString(kKeyPsk, &psk)) { | 127 !dict.GetString(kKeyPsk, &psk)) { |
| 117 return false; | 128 return false; |
| 118 } | 129 } |
| 119 | 130 |
| 120 data->bluetooth_address.swap(bluetooth_address); | 131 data->bluetooth_address.swap(bluetooth_address); |
| 121 data->public_key.swap(public_key); | 132 data->public_key.swap(public_key); |
| 122 data->psk.swap(psk); | 133 data->psk.swap(psk); |
| 123 return true; | 134 return true; |
| 124 } | 135 } |
| 125 | 136 |
| 126 // static | 137 // static |
| 127 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 138 void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
| 139 const std::string& user_id, | |
| 128 const EasyUnlockDeviceKeyDataList& data_list, | 140 const EasyUnlockDeviceKeyDataList& data_list, |
| 129 base::ListValue* device_list) { | 141 base::ListValue* device_list) { |
| 130 device_list->Clear(); | 142 device_list->Clear(); |
| 131 for (size_t i = 0; i < data_list.size(); ++i) { | 143 for (size_t i = 0; i < data_list.size(); ++i) { |
| 132 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue); | 144 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue); |
| 133 DeviceDataToRemoteDeviceDictionary(data_list[i], device_dict.get()); | 145 DeviceDataToRemoteDeviceDictionary( |
| 146 user_id, data_list[i], device_dict.get()); | |
| 134 device_list->Append(device_dict.release()); | 147 device_list->Append(device_dict.release()); |
| 135 } | 148 } |
| 136 } | 149 } |
| 137 | 150 |
| 138 // static | 151 // static |
| 139 bool EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList( | 152 bool EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList( |
| 140 const base::ListValue& device_list, | 153 const base::ListValue& device_list, |
| 141 EasyUnlockDeviceKeyDataList* data_list) { | 154 EasyUnlockDeviceKeyDataList* data_list) { |
| 142 EasyUnlockDeviceKeyDataList parsed_devices; | 155 EasyUnlockDeviceKeyDataList parsed_devices; |
| 143 for (base::ListValue::const_iterator it = device_list.begin(); | 156 for (base::ListValue::const_iterator it = device_list.begin(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 get_keys_ops_.erase(it); | 217 get_keys_ops_.erase(it); |
| 205 } else { | 218 } else { |
| 206 NOTREACHED(); | 219 NOTREACHED(); |
| 207 } | 220 } |
| 208 | 221 |
| 209 if (!callback.is_null()) | 222 if (!callback.is_null()) |
| 210 callback.Run(fetch_success, fetched_data); | 223 callback.Run(fetch_success, fetched_data); |
| 211 } | 224 } |
| 212 | 225 |
| 213 } // namespace chromeos | 226 } // namespace chromeos |
| OLD | NEW |