OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ |
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/local_discovery/gcd_api_flow.h" | 12 #include "chrome/browser/local_discovery/gcd_api_flow.h" |
13 #include "chrome/browser/local_discovery/privet_http.h" | 13 #include "chrome/browser/local_discovery/privet_http.h" |
14 #include "chrome/browser/local_discovery/privetv3_session.h" | 14 #include "chrome/browser/local_discovery/privetv3_session.h" |
15 | 15 |
16 namespace local_discovery { | 16 namespace local_discovery { |
17 | 17 |
18 // Provides complete flow for Privet v3 device setup. | 18 // Provides complete flow for Privet v3 device setup. |
19 class PrivetV3SetupFlow : public PrivetV3Session::Delegate { | 19 class PrivetV3SetupFlow { |
20 public: | 20 public: |
21 // Delegate to be implemented by client code. | 21 // Delegate to be implemented by client code. |
22 class Delegate { | 22 class Delegate { |
23 public: | 23 public: |
24 typedef base::Callback<void(bool success)> ResultCallback; | 24 typedef base::Callback<void(bool success)> ResultCallback; |
25 // If |ssid| is empty, call failed to get credentials. | 25 // If |ssid| is empty, call failed to get credentials. |
26 // If |key| is empty, network is open. | 26 // If |key| is empty, network is open. |
27 typedef base::Callback<void(const std::string& ssid, | 27 typedef base::Callback<void(const std::string& ssid, |
28 const std::string& key)> CredentialsCallback; | 28 const std::string& key)> CredentialsCallback; |
29 | 29 |
(...skipping 10 matching lines...) Expand all Loading... |
40 | 40 |
41 // Switches to setup WiFi network. | 41 // Switches to setup WiFi network. |
42 // If switch was successfully |RestoreWifi| should be called later. | 42 // If switch was successfully |RestoreWifi| should be called later. |
43 virtual void SwitchToSetupWiFi(const ResultCallback& callback) = 0; | 43 virtual void SwitchToSetupWiFi(const ResultCallback& callback) = 0; |
44 | 44 |
45 // Starts device resolution that should callback with ready | 45 // Starts device resolution that should callback with ready |
46 // |PrivetV3HTTPClient|. | 46 // |PrivetV3HTTPClient|. |
47 virtual void CreatePrivetV3Client(const std::string& service_name, | 47 virtual void CreatePrivetV3Client(const std::string& service_name, |
48 const PrivetClientCallback& callback) = 0; | 48 const PrivetClientCallback& callback) = 0; |
49 | 49 |
50 // Requests client to prompt user to check |confirmation_code|. | 50 // Requests client to prompt user to check pairing code. |
51 virtual void ConfirmSecurityCode(const std::string& confirmation_code, | 51 virtual void ConfirmSecurityCode(const ResultCallback& callback) = 0; |
52 const ResultCallback& callback) = 0; | |
53 | 52 |
54 // Restores WiFi network. | 53 // Restores WiFi network. |
55 virtual void RestoreWifi(const ResultCallback& callback) = 0; | 54 virtual void RestoreWifi(const ResultCallback& callback) = 0; |
56 | 55 |
57 // Notifies client that device is set up. | 56 // Notifies client that device is set up. |
58 virtual void OnSetupDone() = 0; | 57 virtual void OnSetupDone() = 0; |
59 | 58 |
60 // Notifies client setup failed. | 59 // Notifies client setup failed. |
61 virtual void OnSetupError() = 0; | 60 virtual void OnSetupError() = 0; |
62 }; | 61 }; |
63 | 62 |
64 explicit PrivetV3SetupFlow(Delegate* delegate); | 63 explicit PrivetV3SetupFlow(Delegate* delegate); |
65 ~PrivetV3SetupFlow() override; | 64 virtual ~PrivetV3SetupFlow(); |
66 | 65 |
67 // Starts registration. | 66 // Starts registration. |
68 void Register(const std::string& service_name); | 67 void Register(const std::string& service_name); |
69 | 68 |
70 #if defined(ENABLE_WIFI_BOOTSTRAPPING) | 69 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
71 void SetupWifiAndRegister(const std::string& device_ssid); | 70 void SetupWifiAndRegister(const std::string& device_ssid); |
72 #endif // ENABLE_WIFI_BOOTSTRAPPING | 71 #endif // ENABLE_WIFI_BOOTSTRAPPING |
73 | 72 |
74 // PrivetV3Session::Delegate implementation. | |
75 void OnSetupConfirmationNeeded(const std::string& confirmation_code, | |
76 extensions::api::gcd_private::ConfirmationType | |
77 confirmation_type) override; | |
78 void OnSessionStatus(extensions::api::gcd_private::Status status) override; | |
79 | |
80 void OnSetupError(); | 73 void OnSetupError(); |
81 void OnDeviceRegistered(); | |
82 | 74 |
83 const std::string& service_name() const { return service_name_; } | 75 const std::string& service_name() const { return service_name_; } |
84 | 76 |
85 private: | 77 private: |
86 void OnTicketCreated(const std::string& ticket_id, | 78 void OnTicketCreated(const std::string& ticket_id, |
87 const std::string& device_id); | 79 const std::string& device_id); |
88 void OnPrivetClientCreated(scoped_ptr<PrivetHTTPClient> privet_http_client); | 80 void OnPrivetClientCreated(scoped_ptr<PrivetHTTPClient> privet_http_client); |
89 void OnCodeConfirmed(const std::string& code, bool success); | 81 void OnCodeConfirmed(bool success); |
| 82 |
| 83 void OnSessionInitialized( |
| 84 PrivetV3Session::Result result, |
| 85 const std::vector<PrivetV3Session::PairingType>& types); |
| 86 void OnPairingStarted(PrivetV3Session::Result result); |
| 87 void OnPairingDone(PrivetV3Session::Result result); |
| 88 void OnSetupMessageSent(PrivetV3Session::Result result, |
| 89 const base::DictionaryValue& responce); |
90 | 90 |
91 Delegate* delegate_; | 91 Delegate* delegate_; |
92 std::string service_name_; | 92 std::string service_name_; |
93 std::string device_id_; | 93 std::string device_id_; |
| 94 std::string ticket_id_; |
94 scoped_ptr<GCDApiFlow> ticket_request_; | 95 scoped_ptr<GCDApiFlow> ticket_request_; |
95 scoped_ptr<PrivetV3Session> session_; | 96 scoped_ptr<PrivetV3Session> session_; |
96 scoped_ptr<PrivetV3Session::Request> setup_request_; | |
97 base::WeakPtrFactory<PrivetV3SetupFlow> weak_ptr_factory_; | 97 base::WeakPtrFactory<PrivetV3SetupFlow> weak_ptr_factory_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(PrivetV3SetupFlow); | 99 DISALLOW_COPY_AND_ASSIGN(PrivetV3SetupFlow); |
100 }; | 100 }; |
101 | 101 |
102 } // namespace local_discovery | 102 } // namespace local_discovery |
103 | 103 |
104 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ | 104 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SETUP_FLOW_H_ |
OLD | NEW |