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/signin/easy_unlock_service_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base64url.h" | 11 #include "base/base64url.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/json/json_string_value_serializer.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
17 #include "base/time/default_clock.h" | 18 #include "base/time/default_clock.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" | 22 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" |
22 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 23 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 &b64_psk); | 129 &b64_psk); |
129 | 130 |
130 dict->SetString("name", device.name); | 131 dict->SetString("name", device.name); |
131 dict->SetString("psk", b64_psk); | 132 dict->SetString("psk", b64_psk); |
132 dict->SetString("bluetoothAddress", device.bluetooth_address); | 133 dict->SetString("bluetoothAddress", device.bluetooth_address); |
133 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" + | 134 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" + |
134 proximity_auth_client()->GetAccountId()); | 135 proximity_auth_client()->GetAccountId()); |
135 dict->SetString("permitRecord.id", b64_public_key); | 136 dict->SetString("permitRecord.id", b64_public_key); |
136 dict->SetString("permitRecord.type", "license"); | 137 dict->SetString("permitRecord.type", "license"); |
137 dict->SetString("permitRecord.data", b64_public_key); | 138 dict->SetString("permitRecord.data", b64_public_key); |
| 139 |
| 140 // TODO(tengs): Retrieve the actual BeaconSeeds from the RemoteDevice. |
| 141 std::vector<cryptauth::BeaconSeed> beacon_seeds; |
| 142 std::unique_ptr<base::ListValue> beacon_seed_list(new base::ListValue()); |
| 143 for (const auto& beacon_seed : beacon_seeds) { |
| 144 std::string b64_beacon_seed; |
| 145 base::Base64UrlEncode(beacon_seed.SerializeAsString(), |
| 146 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
| 147 &b64_beacon_seed); |
| 148 beacon_seed_list->AppendString(b64_beacon_seed); |
| 149 } |
| 150 |
| 151 std::string serialized_beacon_seeds; |
| 152 JSONStringValueSerializer serializer(&serialized_beacon_seeds); |
| 153 serializer.Serialize(*beacon_seed_list); |
| 154 dict->SetString("serializedBeaconSeeds", serialized_beacon_seeds); |
| 155 |
138 device_list->Append(std::move(dict)); | 156 device_list->Append(std::move(dict)); |
139 } | 157 } |
140 | 158 |
141 // TODO(tengs): Rename this function after the easy_unlock app is replaced. | 159 // TODO(tengs): Rename this function after the easy_unlock app is replaced. |
142 SetRemoteDevices(*device_list); | 160 SetRemoteDevices(*device_list); |
143 #endif | 161 #endif |
144 } | 162 } |
145 | 163 |
146 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 164 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
147 return EasyUnlockService::TYPE_REGULAR; | 165 return EasyUnlockService::TYPE_REGULAR; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const base::DictionaryValue* pairing_dict = | 266 const base::DictionaryValue* pairing_dict = |
249 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | 267 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); |
250 const base::ListValue* devices = NULL; | 268 const base::ListValue* devices = NULL; |
251 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) | 269 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) |
252 return devices; | 270 return devices; |
253 return NULL; | 271 return NULL; |
254 } | 272 } |
255 | 273 |
256 void EasyUnlockServiceRegular::SetRemoteDevices( | 274 void EasyUnlockServiceRegular::SetRemoteDevices( |
257 const base::ListValue& devices) { | 275 const base::ListValue& devices) { |
| 276 std::string remote_devices_json; |
| 277 JSONStringValueSerializer serializer(&remote_devices_json); |
| 278 serializer.Serialize(devices); |
| 279 PA_LOG(INFO) << "Setting RemoteDevices:\n " << remote_devices_json; |
| 280 |
258 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), | 281 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), |
259 prefs::kEasyUnlockPairing); | 282 prefs::kEasyUnlockPairing); |
260 if (devices.empty()) | 283 if (devices.empty()) |
261 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); | 284 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); |
262 else | 285 else |
263 pairing_update->SetWithoutPathExpansion( | 286 pairing_update->SetWithoutPathExpansion( |
264 kKeyDevices, base::MakeUnique<base::Value>(devices)); | 287 kKeyDevices, base::MakeUnique<base::Value>(devices)); |
265 | 288 |
266 #if defined(OS_CHROMEOS) | 289 #if defined(OS_CHROMEOS) |
267 // TODO(tengs): Investigate if we can determine if the remote devices were set | 290 // TODO(tengs): Investigate if we can determine if the remote devices were set |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 | 616 |
594 cryptauth::CryptAuthDeviceManager* | 617 cryptauth::CryptAuthDeviceManager* |
595 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { | 618 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { |
596 cryptauth::CryptAuthDeviceManager* manager = | 619 cryptauth::CryptAuthDeviceManager* manager = |
597 ChromeCryptAuthServiceFactory::GetInstance() | 620 ChromeCryptAuthServiceFactory::GetInstance() |
598 ->GetForBrowserContext(profile()) | 621 ->GetForBrowserContext(profile()) |
599 ->GetCryptAuthDeviceManager(); | 622 ->GetCryptAuthDeviceManager(); |
600 DCHECK(manager); | 623 DCHECK(manager); |
601 return manager; | 624 return manager; |
602 } | 625 } |
OLD | NEW |