| 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 #ifndef COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_ | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_ | 6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_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/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 | 15 |
| 16 namespace cryptauth { | 16 namespace cryptauth { |
| 17 class CryptAuthClient; |
| 18 class CryptAuthClientFactory; |
| 17 class ExternalDeviceInfo; | 19 class ExternalDeviceInfo; |
| 18 class FindEligibleUnlockDevicesResponse; | 20 class FindEligibleUnlockDevicesResponse; |
| 19 class SendDeviceSyncTickleResponse; | 21 class SendDeviceSyncTickleResponse; |
| 20 }; | 22 }; |
| 21 | 23 |
| 22 namespace proximity_auth { | 24 namespace proximity_auth { |
| 23 | 25 |
| 24 class CryptAuthClient; | |
| 25 class CryptAuthClientFactory; | |
| 26 | |
| 27 // Run this flow to find the user's phones that actively respond to a CryptAuth | 26 // Run this flow to find the user's phones that actively respond to a CryptAuth |
| 28 // ping. We are confident that phones responding to the ping are currently | 27 // ping. We are confident that phones responding to the ping are currently |
| 29 // online and immediately reachable. | 28 // online and immediately reachable. |
| 30 class ReachablePhoneFlow { | 29 class ReachablePhoneFlow { |
| 31 public: | 30 public: |
| 32 // Creates the ReachablePhoneFlow instance: | 31 // Creates the ReachablePhoneFlow instance: |
| 33 // |client_factory|: Factory for creating CryptAuthClient instances. Not owned | 32 // |client_factory|: Factory for creating CryptAuthClient instances. Not owned |
| 34 // and must outlive |this| instance. | 33 // and must outlive |this| instance. |
| 35 explicit ReachablePhoneFlow(CryptAuthClientFactory* client_factory); | 34 explicit ReachablePhoneFlow( |
| 35 cryptauth::CryptAuthClientFactory* client_factory); |
| 36 | 36 |
| 37 ~ReachablePhoneFlow(); | 37 ~ReachablePhoneFlow(); |
| 38 | 38 |
| 39 // Starts the flow and invokes |callback| with the reachable devices upon | 39 // Starts the flow and invokes |callback| with the reachable devices upon |
| 40 // completion. If the flow fails, |callback| will be invoked with an empty | 40 // completion. If the flow fails, |callback| will be invoked with an empty |
| 41 // vector. Do not reuse this class after calling |Run()|, but instead create a | 41 // vector. Do not reuse this class after calling |Run()|, but instead create a |
| 42 // new instance. | 42 // new instance. |
| 43 typedef base::Callback<void( | 43 typedef base::Callback<void( |
| 44 const std::vector<cryptauth::ExternalDeviceInfo>&)> | 44 const std::vector<cryptauth::ExternalDeviceInfo>&)> |
| 45 ReachablePhonesCallback; | 45 ReachablePhonesCallback; |
| 46 void Run(const ReachablePhonesCallback& callback); | 46 void Run(const ReachablePhonesCallback& callback); |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // Callback when a CryptAuth API fails. | 49 // Callback when a CryptAuth API fails. |
| 50 void OnApiCallError(const std::string& error); | 50 void OnApiCallError(const std::string& error); |
| 51 | 51 |
| 52 // Callback for the SyncTickle CryptAuth request. | 52 // Callback for the SyncTickle CryptAuth request. |
| 53 void OnSyncTickleSuccess( | 53 void OnSyncTickleSuccess( |
| 54 const cryptauth::SendDeviceSyncTickleResponse& response); | 54 const cryptauth::SendDeviceSyncTickleResponse& response); |
| 55 | 55 |
| 56 // Makes the CryptAuth request to get the phones that responded to the ping. | 56 // Makes the CryptAuth request to get the phones that responded to the ping. |
| 57 void QueryReachablePhones(); | 57 void QueryReachablePhones(); |
| 58 | 58 |
| 59 // Callback for the FindEligibleUnlockDevicesResponse CryptAuth request. | 59 // Callback for the FindEligibleUnlockDevicesResponse CryptAuth request. |
| 60 void OnFindEligibleUnlockDevicesSuccess( | 60 void OnFindEligibleUnlockDevicesSuccess( |
| 61 const cryptauth::FindEligibleUnlockDevicesResponse& response); | 61 const cryptauth::FindEligibleUnlockDevicesResponse& response); |
| 62 | 62 |
| 63 // Factory for creating CryptAuthClient instances. Not owned and must outlive | 63 // Factory for creating CryptAuthClient instances. Not owned and must outlive |
| 64 // |this| instance. | 64 // |this| instance. |
| 65 CryptAuthClientFactory* client_factory_; | 65 cryptauth::CryptAuthClientFactory* client_factory_; |
| 66 | 66 |
| 67 // Callback invoked when the flow completes. | 67 // Callback invoked when the flow completes. |
| 68 ReachablePhonesCallback callback_; | 68 ReachablePhonesCallback callback_; |
| 69 | 69 |
| 70 // The client making the current CryptAuth API call. | 70 // The client making the current CryptAuth API call. |
| 71 std::unique_ptr<CryptAuthClient> client_; | 71 std::unique_ptr<cryptauth::CryptAuthClient> client_; |
| 72 | 72 |
| 73 base::WeakPtrFactory<ReachablePhoneFlow> weak_ptr_factory_; | 73 base::WeakPtrFactory<ReachablePhoneFlow> weak_ptr_factory_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(ReachablePhoneFlow); | 75 DISALLOW_COPY_AND_ASSIGN(ReachablePhoneFlow); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 } // namespace proximity_auth | 78 } // namespace proximity_auth |
| 79 | 79 |
| 80 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_ | 80 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_ |
| OLD | NEW |