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