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> |
| 9 #include <string> |
| 10 |
| 11 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" |
| 12 #include "chrome/browser/local_discovery/privet_device_lister.h" |
| 13 #include "chrome/browser/local_discovery/privet_http.h" |
| 14 #include "chrome/browser/local_discovery/service_discovery_host_client.h" |
| 15 #include "chrome/common/local_discovery/service_discovery_client.h" |
8 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
9 #include "content/public/browser/web_ui_message_handler.h" | 17 #include "content/public/browser/web_ui_message_handler.h" |
10 | 18 |
| 19 namespace local_discovery { |
| 20 |
11 // UI Handler for chrome://devices/ | 21 // UI Handler for chrome://devices/ |
12 // It listens to local discovery notifications and passes those notifications | 22 // It listens to local discovery notifications and passes those notifications |
13 // into the Javascript to update the page. | 23 // into the Javascript to update the page. |
14 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler { | 24 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, |
| 25 public PrivetRegisterOperation::Delegate, |
| 26 public PrivetDeviceLister::Delegate { |
15 public: | 27 public: |
16 LocalDiscoveryUIHandler(); | 28 LocalDiscoveryUIHandler(); |
17 virtual ~LocalDiscoveryUIHandler(); | 29 virtual ~LocalDiscoveryUIHandler(); |
18 | 30 |
19 // WebUIMessageHandler implementation. | 31 // WebUIMessageHandler implementation. |
20 // Does nothing for now. | |
21 virtual void RegisterMessages() OVERRIDE; | 32 virtual void RegisterMessages() OVERRIDE; |
22 | 33 |
| 34 // PrivetRegisterOperation::Delegate implementation. |
| 35 virtual void OnPrivetRegisterClaimToken(const std::string& token, |
| 36 const GURL& url) OVERRIDE; |
| 37 virtual void OnPrivetRegisterError( |
| 38 const std::string& action, |
| 39 PrivetRegisterOperation::FailureReason reason, |
| 40 int printer_http_code, |
| 41 const DictionaryValue* json) OVERRIDE; |
| 42 virtual void OnPrivetRegisterDone(const std::string& device_id) OVERRIDE; |
| 43 |
| 44 // PrivetDeviceLister::Delegate implementation. |
| 45 virtual void DeviceChanged( |
| 46 bool added, |
| 47 const std::string& name, |
| 48 const DeviceDescription& description) OVERRIDE; |
| 49 virtual void DeviceRemoved(const std::string& name) OVERRIDE; |
| 50 |
23 private: | 51 private: |
24 // Callback for adding new device to the devices page. | 52 // Message handlers: |
25 // |name| contains a user friendly name of the device. | 53 // For registering a device. |
26 void OnNewDevice(const std::string& name); | 54 void HandleRegisterDevice(const base::ListValue* args); |
| 55 // For when the page is ready to recieve device notifications. |
| 56 void HandleStart(const base::ListValue* args); |
27 | 57 |
28 content::ActionCallback action_callback_; | 58 // For when the IP address of the printer has been resolved. |
| 59 void OnDomainResolved(bool success, const net::IPAddressNumber& address); |
| 60 |
| 61 // For when the confirm operation on the cloudprint server has finished |
| 62 // executing. |
| 63 void OnConfirmDone(PrivetConfirmApiCallFlow::Status status); |
| 64 |
| 65 // Log an error to the web interface. |
| 66 void LogRegisterErrorToWeb(const std::string& error); |
| 67 |
| 68 // Log a successful registration to the web inteface. |
| 69 void LogRegisterDoneToWeb(const std::string& id); |
| 70 |
| 71 // The current HTTP client (used for the current operation). |
| 72 scoped_ptr<PrivetHTTPClient> current_http_client_; |
| 73 |
| 74 // The current register operation. Only one allowed at any time. |
| 75 scoped_ptr<PrivetRegisterOperation> current_register_operation_; |
| 76 |
| 77 // The current confirm call used during the registration flow. |
| 78 scoped_ptr<PrivetConfirmApiCallFlow> confirm_api_call_flow_; |
| 79 |
| 80 // The name of the currently registering device. |
| 81 std::string currently_registering_device_; |
| 82 |
| 83 // The device lister used to list devices on the local network. |
| 84 scoped_ptr<PrivetDeviceLister> privet_lister_; |
| 85 |
| 86 // The service discovery client used listen for devices on the local network. |
| 87 scoped_refptr<ServiceDiscoveryHostClient> service_discovery_client_; |
| 88 |
| 89 // A map of current device descriptions provided by the PrivetDeviceLister. |
| 90 std::map<std::string, DeviceDescription> device_descriptions_; |
| 91 |
| 92 // The local domain resolver used to resolve the domains for local devices. |
| 93 scoped_ptr<LocalDomainResolver> domain_resolver_; |
29 | 94 |
30 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); | 95 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); |
31 }; | 96 }; |
32 | 97 |
| 98 } // namespace local_discovery |
33 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 99 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
OLD | NEW |