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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_
6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
17 class ExternalDeviceInfo
;
18 class FindEligibleUnlockDevicesResponse
;
19 class SendDeviceSyncTickleResponse
;
22 namespace proximity_auth
{
24 class CryptAuthClient
;
25 class CryptAuthClientFactory
;
27 // 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
29 // online and immediately reachable.
30 class ReachablePhoneFlow
{
32 // Creates the ReachablePhoneFlow instance:
33 // |client_factory|: Factory for creating CryptAuthClient instances. Not owned
34 // and must outlive |this| instance.
35 explicit ReachablePhoneFlow(CryptAuthClientFactory
* client_factory
);
37 ~ReachablePhoneFlow();
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
41 // vector. Do not reuse this class after calling |Run()|, but instead create a
43 typedef base::Callback
<void(
44 const std::vector
<cryptauth::ExternalDeviceInfo
>&)>
45 ReachablePhonesCallback
;
46 void Run(const ReachablePhonesCallback
& callback
);
49 // Callback when a CryptAuth API fails.
50 void OnApiCallError(const std::string
& error
);
52 // Callback for the SyncTickle CryptAuth request.
53 void OnSyncTickleSuccess(
54 const cryptauth::SendDeviceSyncTickleResponse
& response
);
56 // Makes the CryptAuth request to get the phones that responded to the ping.
57 void QueryReachablePhones();
59 // Callback for the FindEligibleUnlockDevicesResponse CryptAuth request.
60 void OnFindEligibleUnlockDevicesSuccess(
61 const cryptauth::FindEligibleUnlockDevicesResponse
& response
);
63 // Factory for creating CryptAuthClient instances. Not owned and must outlive
65 CryptAuthClientFactory
* client_factory_
;
67 // Callback invoked when the flow completes.
68 ReachablePhonesCallback callback_
;
70 // The client making the current CryptAuth API call.
71 scoped_ptr
<CryptAuthClient
> client_
;
73 base::WeakPtrFactory
<ReachablePhoneFlow
> weak_ptr_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(ReachablePhoneFlow
);
78 } // namespace proximity_auth
80 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_REACHABLE_PHONE_FLOW_H_