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