OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/cancelable_callback.h" |
12 #include "chrome/browser/local_discovery/cloud_print_account_manager.h" | 13 #include "chrome/browser/local_discovery/cloud_print_account_manager.h" |
| 14 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" |
13 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" | 15 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" |
14 #include "chrome/browser/local_discovery/privet_constants.h" | 16 #include "chrome/browser/local_discovery/privet_constants.h" |
15 #include "chrome/browser/local_discovery/privet_device_lister.h" | 17 #include "chrome/browser/local_discovery/privet_device_lister.h" |
16 #include "chrome/browser/local_discovery/privet_http.h" | 18 #include "chrome/browser/local_discovery/privet_http.h" |
17 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" | 19 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
18 #include "chrome/browser/local_discovery/service_discovery_host_client.h" | 20 #include "chrome/browser/local_discovery/service_discovery_host_client.h" |
19 #include "chrome/common/local_discovery/service_discovery_client.h" | 21 #include "chrome/common/local_discovery/service_discovery_client.h" |
20 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
21 #include "content/public/browser/web_ui_message_handler.h" | 23 #include "content/public/browser/web_ui_message_handler.h" |
22 | 24 |
23 // TODO(noamsml): Factor out full registration flow into single class | 25 // TODO(noamsml): Factor out full registration flow into single class |
24 namespace local_discovery { | 26 namespace local_discovery { |
25 | 27 |
26 // UI Handler for chrome://devices/ | 28 // UI Handler for chrome://devices/ |
27 // It listens to local discovery notifications and passes those notifications | 29 // It listens to local discovery notifications and passes those notifications |
28 // into the Javascript to update the page. | 30 // into the Javascript to update the page. |
29 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, | 31 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, |
30 public PrivetRegisterOperation::Delegate, | 32 public PrivetRegisterOperation::Delegate, |
31 public PrivetDeviceLister::Delegate { | 33 public PrivetDeviceLister::Delegate, |
| 34 public CloudPrintPrinterList::Delegate { |
32 public: | 35 public: |
33 class Factory { | 36 class Factory { |
34 public: | 37 public: |
35 virtual ~Factory() {} | 38 virtual ~Factory() {} |
36 virtual LocalDiscoveryUIHandler* CreateLocalDiscoveryUIHandler() = 0; | 39 virtual LocalDiscoveryUIHandler* CreateLocalDiscoveryUIHandler() = 0; |
37 }; | 40 }; |
38 | 41 |
39 LocalDiscoveryUIHandler(); | 42 LocalDiscoveryUIHandler(); |
40 // This constructor should only used by tests. | 43 // This constructor should only used by tests. |
41 explicit LocalDiscoveryUIHandler( | 44 explicit LocalDiscoveryUIHandler( |
(...skipping 24 matching lines...) Expand all Loading... |
66 PrivetRegisterOperation* operation, | 69 PrivetRegisterOperation* operation, |
67 const std::string& device_id) OVERRIDE; | 70 const std::string& device_id) OVERRIDE; |
68 | 71 |
69 // PrivetDeviceLister::Delegate implementation. | 72 // PrivetDeviceLister::Delegate implementation. |
70 virtual void DeviceChanged( | 73 virtual void DeviceChanged( |
71 bool added, | 74 bool added, |
72 const std::string& name, | 75 const std::string& name, |
73 const DeviceDescription& description) OVERRIDE; | 76 const DeviceDescription& description) OVERRIDE; |
74 virtual void DeviceRemoved(const std::string& name) OVERRIDE; | 77 virtual void DeviceRemoved(const std::string& name) OVERRIDE; |
75 | 78 |
| 79 // CloudPrintPrinterList::Delegate implementation. |
| 80 virtual void OnCloudPrintPrinterListReady() OVERRIDE; |
| 81 |
| 82 virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE; |
| 83 |
76 private: | 84 private: |
| 85 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; |
| 86 |
77 // Message handlers: | 87 // Message handlers: |
78 // For registering a device. | |
79 void HandleRegisterDevice(const base::ListValue* args); | |
80 | |
81 // For when the page is ready to recieve device notifications. | 88 // For when the page is ready to recieve device notifications. |
82 void HandleStart(const base::ListValue* args); | 89 void HandleStart(const base::ListValue* args); |
83 | 90 |
84 // For when a visibility change occurs. | 91 // For when a visibility change occurs. |
85 void HandleIsVisible(const base::ListValue* args); | 92 void HandleIsVisible(const base::ListValue* args); |
86 | 93 |
87 // For when a user choice is made. | 94 // For when a user choice is made. |
88 void HandleChooseUser(const base::ListValue* args); | 95 void HandleRegisterDevice(const base::ListValue* args); |
89 | 96 |
90 // For when a cancelation is made. | 97 // For when a cancelation is made. |
91 void HandleCancelRegistration(const base::ListValue* args); | 98 void HandleCancelRegistration(const base::ListValue* args); |
92 | 99 |
| 100 // For requesting the printer list. |
| 101 void HandleRequestPrinterList(const base::ListValue* args); |
| 102 |
| 103 // For opening URLs (relative to the Google Cloud Print base URL) in a new |
| 104 // tab. |
| 105 void HandleOpenCloudPrintURL(const base::ListValue* args); |
| 106 |
93 // For when the IP address of the printer has been resolved for registration. | 107 // For when the IP address of the printer has been resolved for registration. |
94 void StartRegisterHTTP( | 108 void StartRegisterHTTP( |
95 const std::string& user, | |
96 scoped_ptr<PrivetHTTPClient> http_client); | 109 scoped_ptr<PrivetHTTPClient> http_client); |
97 | 110 |
98 // For when the confirm operation on the cloudprint server has finished | 111 // For when the confirm operation on the cloudprint server has finished |
99 // executing. | 112 // executing. |
100 void OnConfirmDone(CloudPrintBaseApiFlow::Status status); | 113 void OnConfirmDone(CloudPrintBaseApiFlow::Status status); |
101 | 114 |
102 // For when the cloud print account list is resolved. | |
103 void OnCloudPrintAccountsResolved(const std::vector<std::string>& accounts, | |
104 const std::string& xsrf_token); | |
105 | |
106 // For when XSRF token is received for a secondary account. | |
107 void OnXSRFTokenForSecondaryAccount( | |
108 const GURL& automated_claim_url, | |
109 const std::vector<std::string>& accounts, | |
110 const std::string& xsrf_token); | |
111 | |
112 // Signal to the web interface an error has ocurred while registering. | 115 // Signal to the web interface an error has ocurred while registering. |
113 void SendRegisterError(); | 116 void SendRegisterError(); |
114 | 117 |
115 // Singal to the web interface that registration has finished. | 118 // Singal to the web interface that registration has finished. |
116 void SendRegisterDone(); | 119 void SendRegisterDone(); |
117 | 120 |
118 // Set the visibility of the page. | 121 // Set the visibility of the page. |
119 void SetIsVisible(bool visible); | 122 void SetIsVisible(bool visible); |
120 | 123 |
121 // Get the sync account email. | 124 // Get the sync account email. |
122 std::string GetSyncAccount(); | 125 std::string GetSyncAccount(); |
123 | 126 |
124 // Get the base cloud print URL for a given device. | 127 // Get the base cloud print URL. |
125 const std::string& GetCloudPrintBaseUrl(const std::string& device_name); | 128 std::string GetCloudPrintBaseUrl(); |
126 | |
127 // Start the confirm flow for a cookie based authentication. | |
128 void StartCookieConfirmFlow( | |
129 int user_index, | |
130 const std::string& xsrf_token, | |
131 const GURL& automatic_claim_url); | |
132 | 129 |
133 // Reset and cancel the current registration. | 130 // Reset and cancel the current registration. |
134 void ResetCurrentRegistration(); | 131 void ResetCurrentRegistration(); |
135 | 132 |
| 133 scoped_ptr<base::DictionaryValue> CreatePrinterInfo( |
| 134 const CloudPrintPrinterList::PrinterDetails& description); |
| 135 |
| 136 // Announcement hasn't been sent for a certain time after registration |
| 137 // finished. Consider it failed. |
| 138 // TODO(noamsml): Re-resolve service first. |
| 139 void OnAnnouncementTimeoutReached(); |
| 140 |
136 // The current HTTP client (used for the current operation). | 141 // The current HTTP client (used for the current operation). |
137 scoped_ptr<PrivetHTTPClient> current_http_client_; | 142 scoped_ptr<PrivetHTTPClient> current_http_client_; |
138 | 143 |
139 // Device currently registering. | |
140 std::string current_register_device_; | |
141 | |
142 // The current register operation. Only one allowed at any time. | 144 // The current register operation. Only one allowed at any time. |
143 scoped_ptr<PrivetRegisterOperation> current_register_operation_; | 145 scoped_ptr<PrivetRegisterOperation> current_register_operation_; |
144 | 146 |
145 // The current confirm call used during the registration flow. | 147 // The current confirm call used during the registration flow. |
146 scoped_ptr<PrivetConfirmApiCallFlow> confirm_api_call_flow_; | 148 scoped_ptr<PrivetConfirmApiCallFlow> confirm_api_call_flow_; |
147 | 149 |
148 // The device lister used to list devices on the local network. | 150 // The device lister used to list devices on the local network. |
149 scoped_ptr<PrivetDeviceLister> privet_lister_; | 151 scoped_ptr<PrivetDeviceLister> privet_lister_; |
150 | 152 |
151 // The service discovery client used listen for devices on the local network. | 153 // The service discovery client used listen for devices on the local network. |
152 scoped_refptr<ServiceDiscoveryHostClient> service_discovery_client_; | 154 scoped_refptr<ServiceDiscoveryHostClient> service_discovery_client_; |
153 | 155 |
154 // A factory for creating the privet HTTP Client. | 156 // A factory for creating the privet HTTP Client. |
155 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory_; | 157 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory_; |
156 | 158 |
157 // An object representing the resolution process for the privet_http_factory. | 159 // An object representing the resolution process for the privet_http_factory. |
158 scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> privet_resolution_; | 160 scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> privet_resolution_; |
159 | 161 |
160 // A map of current device descriptions provided by the PrivetDeviceLister. | 162 // A map of current device descriptions provided by the PrivetDeviceLister. |
161 std::map<std::string, DeviceDescription> device_descriptions_; | 163 DeviceDescriptionMap device_descriptions_; |
162 | 164 |
163 // Whether or not the page is marked as visible. | 165 // Whether or not the page is marked as visible. |
164 bool is_visible_; | 166 bool is_visible_; |
165 | 167 |
166 // Cloud print account manager to enumerate accounts and get XSRF token. | 168 // Device whose state must be updated to "registered" to complete |
167 scoped_ptr<CloudPrintAccountManager> cloud_print_account_manager_; | 169 // registration. |
| 170 std::string new_register_device_; |
168 | 171 |
169 // XSRF token. | 172 // List of printers from cloud print. |
170 std::string xsrf_token_for_primary_user_; | 173 scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_; |
171 | 174 |
172 // Current user index (for multi-login), or kAccountIndexUseOAuth2 for sync | 175 // Announcement timeout for registration. |
173 // credentials. | 176 base::CancelableCallback<void()> registration_announce_timeout_; |
174 int current_register_user_index_; | |
175 | 177 |
176 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); | 178 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); |
177 }; | 179 }; |
178 | 180 |
179 } // namespace local_discovery | 181 } // namespace local_discovery |
180 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 182 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
OLD | NEW |