1 // Copyright 2014 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 CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/local_discovery/gcd_api_flow.h"
13 #include "chrome/browser/local_discovery/privet_http.h"
14 #include "chrome/browser/local_discovery/privetv3_session.h"
16 namespace local_discovery
{
18 // Provides complete flow for Privet v3 device setup.
19 class PrivetV3SetupFlow
: public PrivetV3Session::Delegate
{
21 // Delegate to be implemented by client code.
24 typedef base::Callback
<void(bool success
)> ResultCallback
;
25 // If |ssid| is empty, call failed to get credentials.
26 // If |key| is empty, network is open.
27 typedef base::Callback
<void(const std::string
& ssid
,
28 const std::string
& key
)> CredentialsCallback
;
30 typedef base::Callback
<void(scoped_ptr
<PrivetHTTPClient
>)>
35 // Creates |GCDApiFlowImpl| for making requests to GCD server.
36 virtual scoped_ptr
<GCDApiFlow
> CreateApiFlow() = 0;
38 // Requests WiFi credentials.
39 virtual void GetWiFiCredentials(const CredentialsCallback
& callback
) = 0;
41 // Switches to setup WiFi network.
42 // If switch was successfully |RestoreWifi| should be called later.
43 virtual void SwitchToSetupWiFi(const ResultCallback
& callback
) = 0;
45 // Starts device resolution that should callback with ready
46 // |PrivetV3HTTPClient|.
47 virtual void CreatePrivetV3Client(const std::string
& service_name
,
48 const PrivetClientCallback
& callback
) = 0;
50 // Requests client to prompt user to check |confirmation_code|.
51 virtual void ConfirmSecurityCode(const std::string
& confirmation_code
,
52 const ResultCallback
& callback
) = 0;
54 // Restores WiFi network.
55 virtual void RestoreWifi(const ResultCallback
& callback
) = 0;
57 // Notifies client that device is set up.
58 virtual void OnSetupDone() = 0;
60 // Notifies client setup failed.
61 virtual void OnSetupError() = 0;
64 explicit PrivetV3SetupFlow(Delegate
* delegate
);
65 virtual ~PrivetV3SetupFlow();
67 // Starts registration.
68 void Register(const std::string
& service_name
);
70 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
71 void SetupWifiAndRegister(const std::string
& device_ssid
);
72 #endif // ENABLE_WIFI_BOOTSTRAPPING
74 // PrivetV3Session::Delegate implementation.
75 virtual void OnSetupConfirmationNeeded(
76 const std::string
& confirmation_code
) OVERRIDE
;
77 virtual void OnSessionEstablished() OVERRIDE
;
78 virtual void OnCannotEstablishSession() OVERRIDE
;
81 void OnDeviceRegistered();
83 const std::string
& service_name() const { return service_name_
; }
86 void OnTicketCreated(const std::string
& ticket_id
,
87 const std::string
& device_id
);
88 void OnPrivetClientCreated(scoped_ptr
<PrivetHTTPClient
> privet_http_client
);
89 void OnCodeConfirmed(bool success
);
92 std::string service_name_
;
93 std::string device_id_
;
94 scoped_ptr
<GCDApiFlow
> ticket_request_
;
95 scoped_ptr
<PrivetV3Session
> session_
;
96 scoped_ptr
<PrivetV3Session::Request
> setup_request_
;
97 base::WeakPtrFactory
<PrivetV3SetupFlow
> weak_ptr_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(PrivetV3SetupFlow
);
102 } // namespace local_discovery
104 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_