| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/components/tether/local_device_data_provider.h" | 5 #include "components/cryptauth/local_device_data_provider.h" |
| 6 | 6 |
| 7 #include "components/cryptauth/cryptauth_device_manager.h" | 7 #include "components/cryptauth/cryptauth_device_manager.h" |
| 8 #include "components/cryptauth/cryptauth_enrollment_manager.h" | 8 #include "components/cryptauth/cryptauth_enrollment_manager.h" |
| 9 #include "components/cryptauth/cryptauth_service.h" | 9 #include "components/cryptauth/cryptauth_service.h" |
| 10 #include "components/cryptauth/proto/cryptauth_api.pb.h" | 10 #include "components/cryptauth/proto/cryptauth_api.pb.h" |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace cryptauth { |
| 13 | |
| 14 namespace tether { | |
| 15 | 13 |
| 16 LocalDeviceDataProvider::LocalDeviceDataProvider( | 14 LocalDeviceDataProvider::LocalDeviceDataProvider( |
| 17 cryptauth::CryptAuthService* cryptauth_service) | 15 CryptAuthService* cryptauth_service) |
| 18 : cryptauth_service_(cryptauth_service) {} | 16 : cryptauth_service_(cryptauth_service) {} |
| 19 | 17 |
| 20 LocalDeviceDataProvider::~LocalDeviceDataProvider() {} | 18 LocalDeviceDataProvider::~LocalDeviceDataProvider() {} |
| 21 | 19 |
| 22 bool LocalDeviceDataProvider::GetLocalDeviceData( | 20 bool LocalDeviceDataProvider::GetLocalDeviceData( |
| 23 std::string* public_key_out, | 21 std::string* public_key_out, |
| 24 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const { | 22 std::vector<BeaconSeed>* beacon_seeds_out) const { |
| 25 DCHECK(public_key_out || beacon_seeds_out); | 23 DCHECK(public_key_out || beacon_seeds_out); |
| 26 | 24 |
| 27 std::string public_key = | 25 std::string public_key = |
| 28 cryptauth_service_->GetCryptAuthEnrollmentManager()->GetUserPublicKey(); | 26 cryptauth_service_->GetCryptAuthEnrollmentManager()->GetUserPublicKey(); |
| 29 if (public_key.empty()) { | 27 if (public_key.empty()) { |
| 30 return false; | 28 return false; |
| 31 } | 29 } |
| 32 | 30 |
| 33 std::vector<cryptauth::ExternalDeviceInfo> synced_devices = | 31 std::vector<ExternalDeviceInfo> synced_devices = |
| 34 cryptauth_service_->GetCryptAuthDeviceManager()->GetSyncedDevices(); | 32 cryptauth_service_->GetCryptAuthDeviceManager()->GetSyncedDevices(); |
| 35 for (const auto& device : synced_devices) { | 33 for (const auto& device : synced_devices) { |
| 36 if (device.has_public_key() && device.public_key() == public_key && | 34 if (device.has_public_key() && device.public_key() == public_key && |
| 37 device.beacon_seeds_size() > 0) { | 35 device.beacon_seeds_size() > 0) { |
| 38 if (public_key_out) { | 36 if (public_key_out) { |
| 39 public_key_out->assign(public_key); | 37 public_key_out->assign(public_key); |
| 40 } | 38 } |
| 41 | 39 |
| 42 if (beacon_seeds_out) { | 40 if (beacon_seeds_out) { |
| 43 beacon_seeds_out->clear(); | 41 beacon_seeds_out->clear(); |
| 44 for (int i = 0; i < device.beacon_seeds_size(); i++) { | 42 for (int i = 0; i < device.beacon_seeds_size(); i++) { |
| 45 beacon_seeds_out->push_back(device.beacon_seeds(i)); | 43 beacon_seeds_out->push_back(device.beacon_seeds(i)); |
| 46 } | 44 } |
| 47 } | 45 } |
| 48 | 46 |
| 49 return true; | 47 return true; |
| 50 } | 48 } |
| 51 } | 49 } |
| 52 | 50 |
| 53 return false; | 51 return false; |
| 54 } | 52 } |
| 55 | 53 |
| 56 } // namespace tether | 54 } // namespace cryptauth |
| 57 | |
| 58 } // namespace chromeos | |
| OLD | NEW |