Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1111)

Side by Side Diff: chromeos/components/tether/local_device_data_provider.cc

Issue 2587963003: [CrOS Tether]: Add LocalDeviceDataProvider, which fetches device data for the local device. (Closed)
Patch Set: Rebased. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/proto/cryptauth_api.pb.h"
10
11 namespace chromeos {
12
13 namespace tether {
14
15 LocalDeviceDataProvider::LocalDeviceDataProvider(
16 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager,
17 const cryptauth::CryptAuthEnrollmentManager* cryptauth_enrollment_manager)
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
27 LocalDeviceDataProvider::~LocalDeviceDataProvider() {}
28
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(
53 std::string* public_key_out,
54 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const {
55 DCHECK(public_key_out || beacon_seeds_out);
56
57 std::string public_key = delegate_->GetUserPublicKey();
58 if (public_key.empty()) {
59 return false;
60 }
61
62 std::vector<cryptauth::ExternalDeviceInfo> synced_devices =
63 delegate_->GetSyncedDevices();
64 for (const auto& device : synced_devices) {
65 if (device.has_public_key() && device.public_key() == public_key &&
66 device.beacon_seeds_size() > 0) {
67 if (public_key_out) {
68 public_key_out->assign(public_key);
69 }
70
71 if (beacon_seeds_out) {
72 beacon_seeds_out->clear();
73 for (int i = 0; i < device.beacon_seeds_size(); i++) {
74 beacon_seeds_out->push_back(device.beacon_seeds(i));
75 }
76 }
77
78 return true;
79 }
80 }
81
82 return false;
83 }
84
85 } // namespace tether
86
87 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698