| 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 "chromeos/components/tether/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/proto/cryptauth_api.pb.h" | 10 #include "components/cryptauth/proto/cryptauth_api.pb.h" |
| 10 | 11 |
| 11 namespace chromeos { | 12 namespace chromeos { |
| 12 | 13 |
| 13 namespace tether { | 14 namespace tether { |
| 14 | 15 |
| 15 LocalDeviceDataProvider::LocalDeviceDataProvider( | 16 LocalDeviceDataProvider::LocalDeviceDataProvider( |
| 16 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager, | 17 cryptauth::CryptAuthService* cryptauth_service) |
| 17 const cryptauth::CryptAuthEnrollmentManager* cryptauth_enrollment_manager) | 18 : cryptauth_service_(cryptauth_service) {} |
| 18 : LocalDeviceDataProvider( | |
| 19 base::MakeUnique<LocalDeviceDataProviderDelegateImpl>( | |
| 20 cryptauth_device_manager, | |
| 21 cryptauth_enrollment_manager)) {} | |
| 22 | |
| 23 LocalDeviceDataProvider::LocalDeviceDataProvider( | |
| 24 std::unique_ptr<LocalDeviceDataProviderDelegate> delegate) | |
| 25 : delegate_(std::move(delegate)) {} | |
| 26 | 19 |
| 27 LocalDeviceDataProvider::~LocalDeviceDataProvider() {} | 20 LocalDeviceDataProvider::~LocalDeviceDataProvider() {} |
| 28 | 21 |
| 29 LocalDeviceDataProvider::LocalDeviceDataProviderDelegateImpl:: | |
| 30 LocalDeviceDataProviderDelegateImpl( | |
| 31 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager, | |
| 32 const cryptauth::CryptAuthEnrollmentManager* | |
| 33 cryptauth_enrollment_manager) | |
| 34 : cryptauth_device_manager_(cryptauth_device_manager), | |
| 35 cryptauth_enrollment_manager_(cryptauth_enrollment_manager) {} | |
| 36 | |
| 37 LocalDeviceDataProvider::LocalDeviceDataProviderDelegateImpl:: | |
| 38 ~LocalDeviceDataProviderDelegateImpl() {} | |
| 39 | |
| 40 std::string | |
| 41 LocalDeviceDataProvider::LocalDeviceDataProviderDelegateImpl::GetUserPublicKey() | |
| 42 const { | |
| 43 return cryptauth_enrollment_manager_->GetUserPublicKey(); | |
| 44 } | |
| 45 | |
| 46 std::vector<cryptauth::ExternalDeviceInfo> | |
| 47 LocalDeviceDataProvider::LocalDeviceDataProviderDelegateImpl::GetSyncedDevices() | |
| 48 const { | |
| 49 return cryptauth_device_manager_->GetSyncedDevices(); | |
| 50 } | |
| 51 | |
| 52 bool LocalDeviceDataProvider::GetLocalDeviceData( | 22 bool LocalDeviceDataProvider::GetLocalDeviceData( |
| 53 std::string* public_key_out, | 23 std::string* public_key_out, |
| 54 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const { | 24 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const { |
| 55 DCHECK(public_key_out || beacon_seeds_out); | 25 DCHECK(public_key_out || beacon_seeds_out); |
| 56 | 26 |
| 57 std::string public_key = delegate_->GetUserPublicKey(); | 27 std::string public_key = |
| 28 cryptauth_service_->GetCryptAuthEnrollmentManager()->GetUserPublicKey(); |
| 58 if (public_key.empty()) { | 29 if (public_key.empty()) { |
| 59 return false; | 30 return false; |
| 60 } | 31 } |
| 61 | 32 |
| 62 std::vector<cryptauth::ExternalDeviceInfo> synced_devices = | 33 std::vector<cryptauth::ExternalDeviceInfo> synced_devices = |
| 63 delegate_->GetSyncedDevices(); | 34 cryptauth_service_->GetCryptAuthDeviceManager()->GetSyncedDevices(); |
| 64 for (const auto& device : synced_devices) { | 35 for (const auto& device : synced_devices) { |
| 65 if (device.has_public_key() && device.public_key() == public_key && | 36 if (device.has_public_key() && device.public_key() == public_key && |
| 66 device.beacon_seeds_size() > 0) { | 37 device.beacon_seeds_size() > 0) { |
| 67 if (public_key_out) { | 38 if (public_key_out) { |
| 68 public_key_out->assign(public_key); | 39 public_key_out->assign(public_key); |
| 69 } | 40 } |
| 70 | 41 |
| 71 if (beacon_seeds_out) { | 42 if (beacon_seeds_out) { |
| 72 beacon_seeds_out->clear(); | 43 beacon_seeds_out->clear(); |
| 73 for (int i = 0; i < device.beacon_seeds_size(); i++) { | 44 for (int i = 0; i < device.beacon_seeds_size(); i++) { |
| 74 beacon_seeds_out->push_back(device.beacon_seeds(i)); | 45 beacon_seeds_out->push_back(device.beacon_seeds(i)); |
| 75 } | 46 } |
| 76 } | 47 } |
| 77 | 48 |
| 78 return true; | 49 return true; |
| 79 } | 50 } |
| 80 } | 51 } |
| 81 | 52 |
| 82 return false; | 53 return false; |
| 83 } | 54 } |
| 84 | 55 |
| 85 } // namespace tether | 56 } // namespace tether |
| 86 | 57 |
| 87 } // namespace cryptauth | 58 } // namespace chromeos |
| OLD | NEW |