| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_TETHER_HOST_FETCHER_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_FETCHER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_FETCHER_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } // namespace cryptauth | 21 } // namespace cryptauth |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 | 24 |
| 25 namespace tether { | 25 namespace tether { |
| 26 | 26 |
| 27 // Fetches RemoteDevice objects corresponding to tether hosts which have been | 27 // Fetches RemoteDevice objects corresponding to tether hosts which have been |
| 28 // synced via CryptAuth. | 28 // synced via CryptAuth. |
| 29 class TetherHostFetcher { | 29 class TetherHostFetcher { |
| 30 public: | 30 public: |
| 31 TetherHostFetcher(const std::string& user_id, | 31 explicit TetherHostFetcher(cryptauth::CryptAuthService* cryptauth_service); |
| 32 const std::string& user_private_key, | |
| 33 cryptauth::CryptAuthService* cryptauth_service, | |
| 34 cryptauth::CryptAuthDeviceManager* device_manager); | |
| 35 virtual ~TetherHostFetcher(); | 32 virtual ~TetherHostFetcher(); |
| 36 | 33 |
| 37 // Fetches all tether hosts. | 34 // Fetches all tether hosts. |
| 38 using TetherHostListCallback = | 35 using TetherHostListCallback = |
| 39 base::Callback<void(const cryptauth::RemoteDeviceList&)>; | 36 base::Callback<void(const cryptauth::RemoteDeviceList&)>; |
| 40 virtual void FetchAllTetherHosts(const TetherHostListCallback& callback); | 37 virtual void FetchAllTetherHosts(const TetherHostListCallback& callback); |
| 41 | 38 |
| 42 // Fetches the tether host with the ID |device_id|. | 39 // Fetches the tether host with the ID |device_id|. |
| 43 using TetherHostCallback = | 40 using TetherHostCallback = |
| 44 base::Callback<void(std::unique_ptr<cryptauth::RemoteDevice>)>; | 41 base::Callback<void(std::unique_ptr<cryptauth::RemoteDevice>)>; |
| 45 virtual void FetchTetherHost(const std::string& device_id, | 42 virtual void FetchTetherHost(const std::string& device_id, |
| 46 const TetherHostCallback& callback); | 43 const TetherHostCallback& callback); |
| 47 | 44 |
| 48 protected: | 45 protected: |
| 49 struct TetherHostFetchRequest { | 46 struct TetherHostFetchRequest { |
| 50 TetherHostFetchRequest(const TetherHostListCallback& list_callback); | 47 explicit TetherHostFetchRequest( |
| 48 const TetherHostListCallback& list_callback); |
| 51 TetherHostFetchRequest(const std::string& device_id, | 49 TetherHostFetchRequest(const std::string& device_id, |
| 52 const TetherHostCallback& single_callback); | 50 const TetherHostCallback& single_callback); |
| 53 TetherHostFetchRequest(const TetherHostFetchRequest& other); | 51 TetherHostFetchRequest(const TetherHostFetchRequest& other); |
| 54 ~TetherHostFetchRequest(); | 52 ~TetherHostFetchRequest(); |
| 55 | 53 |
| 56 std::string device_id; | 54 std::string device_id; |
| 57 | 55 |
| 58 // Only one of the two callbacks is actually used depending on which | 56 // Only one of the two callbacks is actually used depending on which |
| 59 // constructor is used. If a device ID is provided, then the request is for | 57 // constructor is used. If a device ID is provided, then the request is for |
| 60 // a single device, and |single_callback| is used; otherwise, the request is | 58 // a single device, and |single_callback| is used; otherwise, the request is |
| 61 // for all devices, so |list_callback| is used. | 59 // for all devices, so |list_callback| is used. |
| 62 TetherHostListCallback list_callback; | 60 TetherHostListCallback list_callback; |
| 63 TetherHostCallback single_callback; | 61 TetherHostCallback single_callback; |
| 64 }; | 62 }; |
| 65 | 63 |
| 64 TetherHostFetcher(const std::string& user_id, |
| 65 const std::string& user_private_key, |
| 66 cryptauth::CryptAuthService* cryptauth_service, |
| 67 cryptauth::CryptAuthDeviceManager* device_manager); |
| 68 |
| 66 void OnRemoteDevicesLoaded(const cryptauth::RemoteDeviceList& remote_devices); | 69 void OnRemoteDevicesLoaded(const cryptauth::RemoteDeviceList& remote_devices); |
| 67 | 70 |
| 68 std::vector<TetherHostFetchRequest> requests_; | 71 std::vector<TetherHostFetchRequest> requests_; |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 void StartLoadingDevicesIfNeeded(); | 74 void StartLoadingDevicesIfNeeded(); |
| 72 | 75 |
| 73 const std::string user_id_; | |
| 74 const std::string user_private_key_; | |
| 75 | |
| 76 cryptauth::CryptAuthService* cryptauth_service_; | 76 cryptauth::CryptAuthService* cryptauth_service_; |
| 77 cryptauth::CryptAuthDeviceManager* device_manager_; | |
| 78 | 77 |
| 79 std::unique_ptr<cryptauth::RemoteDeviceLoader> remote_device_loader_; | 78 std::unique_ptr<cryptauth::RemoteDeviceLoader> remote_device_loader_; |
| 80 | 79 |
| 81 base::WeakPtrFactory<TetherHostFetcher> weak_ptr_factory_; | 80 base::WeakPtrFactory<TetherHostFetcher> weak_ptr_factory_; |
| 82 | 81 |
| 83 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcher); | 82 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcher); |
| 84 }; | 83 }; |
| 85 | 84 |
| 86 } // namespace tether | 85 } // namespace tether |
| 87 | 86 |
| 88 } // namespace chromeos | 87 } // namespace chromeos |
| 89 | 88 |
| 90 #endif // CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_FETCHER_H_ | 89 #endif // CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_FETCHER_H_ |
| OLD | NEW |