Chromium Code Reviews| 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 |
| 25 : public content::WebUIMessageHandler, | |
| 26 public PrivetRegisterOperation::Delegate, | |
| 27 public PrivetDeviceLister::Delegate { | |
| 15 public: | 28 public: |
| 16 LocalDiscoveryUIHandler(); | 29 LocalDiscoveryUIHandler(); |
| 17 virtual ~LocalDiscoveryUIHandler(); | 30 virtual ~LocalDiscoveryUIHandler(); |
| 18 | 31 |
| 19 // WebUIMessageHandler implementation. | 32 // WebUIMessageHandler implementation: |
|
James Hawkins
2013/07/29 16:27:03
Please revert this change. Comments must end with
Noam Samuel
2013/08/02 22:20:02
Done.
| |
| 20 // Does nothing for now. | |
| 21 virtual void RegisterMessages() OVERRIDE; | 33 virtual void RegisterMessages() OVERRIDE; |
| 22 | 34 |
| 35 // PrivetRegisterOperation::Delegate implementation: | |
| 36 virtual void OnPrivetRegisterClaimToken(const std::string& token, | |
| 37 const GURL& url) OVERRIDE; | |
| 38 | |
| 39 virtual void OnPrivetRegisterError( | |
| 40 const std::string& action, | |
| 41 PrivetRegisterOperation::FailureReason reason, | |
| 42 int printer_http_code, | |
| 43 const DictionaryValue* json) OVERRIDE; | |
| 44 | |
| 45 virtual void OnPrivetRegisterDone(const std::string& device_id) OVERRIDE; | |
| 46 | |
| 47 // PrivetDeviceLister::Delegate implementation: | |
| 48 virtual void DeviceChanged( | |
| 49 bool added, | |
| 50 const std::string& name, | |
| 51 const DeviceDescription& description) OVERRIDE; | |
| 52 virtual void DeviceRemoved(const std::string& name) OVERRIDE; | |
| 53 | |
| 23 private: | 54 private: |
| 24 // Callback for adding new device to the devices page. | 55 // Message handlers: |
| 25 // |name| contains a user friendly name of the device. | 56 // For registering a device. |
| 26 void OnNewDevice(const std::string& name); | 57 void OnRegisterDevice(const base::ListValue* data); |
| 58 // For when the page is ready to recieve device notifications. | |
| 59 void OnStart(const base::ListValue* value); | |
| 27 | 60 |
| 28 content::ActionCallback action_callback_; | 61 // For when the IP address of the printer has been resolved. |
| 62 void OnDomainResolved(bool success, const net::IPAddressNumber& address); | |
| 63 | |
| 64 // For when the confirm operation on the cloudprint server has finished | |
| 65 // executing. | |
| 66 void OnConfirmDone(PrivetConfirmApiCallFlow::Status status); | |
| 67 | |
| 68 // Log an error to the web interface. | |
| 69 void LogRegisterErrorToWeb(const std::string& error); | |
| 70 | |
| 71 // Log a successful registration to the web inteface. | |
| 72 void LogRegisterDoneToWeb(const std::string& id); | |
| 73 | |
| 74 scoped_ptr<PrivetHTTPClient> current_http_client_; | |
| 75 scoped_ptr<PrivetRegisterOperation> | |
| 76 current_register_operation_; | |
| 77 scoped_ptr<PrivetConfirmApiCallFlow> confirm_api_call_flow_; | |
| 78 std::string currently_registering_device_; | |
| 79 | |
| 80 scoped_ptr<PrivetDeviceLister> privet_lister_; | |
| 81 scoped_refptr<ServiceDiscoveryHostClient> | |
| 82 service_discovery_client_; | |
| 83 | |
| 84 std::map<std::string, DeviceDescription> | |
| 85 device_descriptions_; | |
| 86 | |
| 87 scoped_ptr<LocalDomainResolver> domain_resolver_; | |
| 29 | 88 |
| 30 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); | 89 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); |
| 31 }; | 90 }; |
| 32 | 91 |
| 92 } // namespace local_discovery | |
| 33 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 93 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
| OLD | NEW |