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