Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H | 6 #define CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 | 14 |
| 15 namespace cryptauth { | 15 namespace cryptauth { |
| 16 class BeaconSeed; | 16 class BeaconSeed; |
| 17 class ExternalDeviceInfo; | |
| 18 class CryptAuthDeviceManager; | 17 class CryptAuthDeviceManager; |
| 19 class CryptAuthEnrollmentManager; | 18 class CryptAuthEnrollmentManager; |
| 19 class CryptAuthService; | |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 namespace tether { | 24 namespace tether { |
| 25 | 25 |
| 26 // Fetches CryptAuth data about the local device (i.e., the device on which this | 26 // Fetches CryptAuth data about the local device (i.e., the device on which this |
| 27 // code is running) for the current user (i.e., the one which is logged-in). | 27 // code is running) for the current user (i.e., the one which is logged-in). |
| 28 class LocalDeviceDataProvider { | 28 class LocalDeviceDataProvider { |
| 29 public: | 29 public: |
| 30 LocalDeviceDataProvider( | 30 explicit LocalDeviceDataProvider( |
| 31 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager, | 31 cryptauth::CryptAuthService* cryptauth_service); |
| 32 const cryptauth::CryptAuthEnrollmentManager* | |
| 33 cryptauth_enrollment_manager); | |
| 34 virtual ~LocalDeviceDataProvider(); | 32 virtual ~LocalDeviceDataProvider(); |
| 35 | 33 |
| 36 // Fetches the public key and/or the beacon seeds for the local device. | 34 // Fetches the public key and/or the beacon seeds for the local device. |
| 37 // Returns whether the operation succeeded. If |nullptr| is passed as a | 35 // Returns whether the operation succeeded. If |nullptr| is passed as a |
| 38 // parameter, the associated data will not be fetched. | 36 // parameter, the associated data will not be fetched. |
| 39 virtual bool GetLocalDeviceData( | 37 virtual bool GetLocalDeviceData( |
| 40 std::string* public_key_out, | 38 std::string* public_key_out, |
| 41 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const; | 39 std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const; |
| 42 | 40 |
| 41 protected: | |
| 42 LocalDeviceDataProvider( | |
| 43 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager, | |
| 44 const cryptauth::CryptAuthEnrollmentManager* | |
| 45 cryptauth_enrollment_manager); | |
| 46 | |
| 43 private: | 47 private: |
| 44 friend class LocalDeviceDataProviderTest; | 48 friend class LocalDeviceDataProviderTest; |
| 45 | 49 |
| 46 class LocalDeviceDataProviderDelegate { | 50 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager_; |
| 47 public: | 51 const cryptauth::CryptAuthEnrollmentManager* cryptauth_enrollment_manager_; |
|
Ryan Hansberry
2017/04/07 18:53:40
Woo so much simpler :D
Kyle Horimoto
2017/04/07 23:33:10
Yep! This refactor is especially awesome for this
| |
| 48 virtual ~LocalDeviceDataProviderDelegate() {} | |
| 49 virtual std::string GetUserPublicKey() const = 0; | |
| 50 virtual std::vector<cryptauth::ExternalDeviceInfo> GetSyncedDevices() | |
| 51 const = 0; | |
| 52 }; | |
| 53 | |
| 54 class LocalDeviceDataProviderDelegateImpl | |
| 55 : public LocalDeviceDataProviderDelegate { | |
| 56 public: | |
| 57 LocalDeviceDataProviderDelegateImpl( | |
| 58 const cryptauth::CryptAuthDeviceManager* cryptauth_device_manager, | |
| 59 const cryptauth::CryptAuthEnrollmentManager* | |
| 60 cryptauth_enrollment_manager); | |
| 61 ~LocalDeviceDataProviderDelegateImpl() override; | |
| 62 | |
| 63 std::string GetUserPublicKey() const override; | |
| 64 std::vector<cryptauth::ExternalDeviceInfo> GetSyncedDevices() | |
| 65 const override; | |
| 66 | |
| 67 private: | |
| 68 // Not owned and must outlive this instance. | |
| 69 const cryptauth::CryptAuthDeviceManager* const cryptauth_device_manager_; | |
| 70 | |
| 71 // Not owned and must outlive this instance. | |
| 72 const cryptauth::CryptAuthEnrollmentManager* const | |
| 73 cryptauth_enrollment_manager_; | |
| 74 }; | |
| 75 | |
| 76 LocalDeviceDataProvider( | |
| 77 std::unique_ptr<LocalDeviceDataProviderDelegate> delegate); | |
| 78 | |
| 79 std::unique_ptr<LocalDeviceDataProviderDelegate> delegate_; | |
| 80 | 52 |
| 81 DISALLOW_COPY_AND_ASSIGN(LocalDeviceDataProvider); | 53 DISALLOW_COPY_AND_ASSIGN(LocalDeviceDataProvider); |
| 82 }; | 54 }; |
| 83 | 55 |
| 84 } // namespace tether | 56 } // namespace tether |
| 85 | 57 |
| 86 } // namespace chromeos | 58 } // namespace chromeos |
| 87 | 59 |
| 88 #endif // CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H | 60 #endif // CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ |
| OLD | NEW |