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 "base/cancelable_callback.h" |
13 #include "base/prefs/pref_member.h" | 13 #include "base/prefs/pref_member.h" |
| 14 #include "chrome/browser/local_discovery/cloud_device_list.h" |
14 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | 15 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" |
15 #include "chrome/browser/local_discovery/privet_device_lister.h" | 16 #include "chrome/browser/local_discovery/privet_device_lister.h" |
16 #include "chrome/browser/local_discovery/privet_http.h" | 17 #include "chrome/browser/local_discovery/privet_http.h" |
17 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
18 #include "content/public/browser/web_ui_message_handler.h" | 19 #include "content/public/browser/web_ui_message_handler.h" |
19 | 20 |
20 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) | 21 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) |
21 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE | 22 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE |
22 #endif | 23 #endif |
23 | 24 |
24 // TODO(noamsml): Factor out full registration flow into single class | 25 // TODO(noamsml): Factor out full registration flow into single class |
25 namespace local_discovery { | 26 namespace local_discovery { |
26 | 27 |
27 class PrivetConfirmApiCallFlow; | 28 class PrivetConfirmApiCallFlow; |
28 class PrivetHTTPAsynchronousFactory; | 29 class PrivetHTTPAsynchronousFactory; |
29 class PrivetHTTPResolution; | 30 class PrivetHTTPResolution; |
30 class ServiceDiscoverySharedClient; | 31 class ServiceDiscoverySharedClient; |
31 | 32 |
32 // UI Handler for chrome://devices/ | 33 // UI Handler for chrome://devices/ |
33 // It listens to local discovery notifications and passes those notifications | 34 // It listens to local discovery notifications and passes those notifications |
34 // into the Javascript to update the page. | 35 // into the Javascript to update the page. |
35 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, | 36 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, |
36 public PrivetRegisterOperation::Delegate, | 37 public PrivetRegisterOperation::Delegate, |
37 public PrivetDeviceLister::Delegate, | 38 public PrivetDeviceLister::Delegate, |
38 public CloudPrintPrinterList::Delegate, | 39 public CloudDeviceListDelegate, |
39 public SigninManagerBase::Observer { | 40 public SigninManagerBase::Observer { |
40 public: | 41 public: |
41 LocalDiscoveryUIHandler(); | 42 LocalDiscoveryUIHandler(); |
42 virtual ~LocalDiscoveryUIHandler(); | 43 virtual ~LocalDiscoveryUIHandler(); |
43 | 44 |
44 static bool GetHasVisible(); | 45 static bool GetHasVisible(); |
45 | 46 |
46 // WebUIMessageHandler implementation. | 47 // WebUIMessageHandler implementation. |
47 virtual void RegisterMessages() OVERRIDE; | 48 virtual void RegisterMessages() OVERRIDE; |
48 | 49 |
(...skipping 16 matching lines...) Expand all Loading... |
65 | 66 |
66 // PrivetDeviceLister::Delegate implementation. | 67 // PrivetDeviceLister::Delegate implementation. |
67 virtual void DeviceChanged(bool added, | 68 virtual void DeviceChanged(bool added, |
68 const std::string& name, | 69 const std::string& name, |
69 const DeviceDescription& description) OVERRIDE; | 70 const DeviceDescription& description) OVERRIDE; |
70 | 71 |
71 virtual void DeviceRemoved(const std::string& name) OVERRIDE; | 72 virtual void DeviceRemoved(const std::string& name) OVERRIDE; |
72 | 73 |
73 virtual void DeviceCacheFlushed() OVERRIDE; | 74 virtual void DeviceCacheFlushed() OVERRIDE; |
74 | 75 |
75 // CloudPrintPrinterList::Delegate implementation. | 76 // CloudDeviceListDelegate implementation. |
76 virtual void OnCloudPrintPrinterListReady() OVERRIDE; | 77 virtual void OnDeviceListReady() OVERRIDE; |
77 | 78 virtual void OnDeviceListUnavailable() OVERRIDE; |
78 virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE; | |
79 | 79 |
80 // SigninManagerBase::Observer implementation. | 80 // SigninManagerBase::Observer implementation. |
81 virtual void GoogleSigninSucceeded(const std::string& username, | 81 virtual void GoogleSigninSucceeded(const std::string& username, |
82 const std::string& password) OVERRIDE; | 82 const std::string& password) OVERRIDE; |
83 | 83 |
84 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 84 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; |
85 | 85 |
86 private: | 86 private: |
87 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; | 87 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; |
88 | 88 |
89 // Message handlers: | 89 // Message handlers: |
90 // For when the page is ready to receive device notifications. | 90 // For when the page is ready to receive device notifications. |
91 void HandleStart(const base::ListValue* args); | 91 void HandleStart(const base::ListValue* args); |
92 | 92 |
93 // For when a visibility change occurs. | 93 // For when a visibility change occurs. |
94 void HandleIsVisible(const base::ListValue* args); | 94 void HandleIsVisible(const base::ListValue* args); |
95 | 95 |
96 // For when a user choice is made. | 96 // For when a user choice is made. |
97 void HandleRegisterDevice(const base::ListValue* args); | 97 void HandleRegisterDevice(const base::ListValue* args); |
98 | 98 |
99 // For when a cancelation is made. | 99 // For when a cancellation is made. |
100 void HandleCancelRegistration(const base::ListValue* args); | 100 void HandleCancelRegistration(const base::ListValue* args); |
101 | 101 |
102 // For requesting the printer list. | 102 // For requesting the device list. |
103 void HandleRequestPrinterList(const base::ListValue* args); | 103 void HandleRequestDeviceList(const base::ListValue* args); |
104 | 104 |
105 // For opening URLs (relative to the Google Cloud Print base URL) in a new | 105 // For opening URLs (relative to the Google Cloud Print base URL) in a new |
106 // tab. | 106 // tab. |
107 void HandleOpenCloudPrintURL(const base::ListValue* args); | 107 void HandleOpenCloudPrintURL(const base::ListValue* args); |
108 | 108 |
109 // For showing sync login UI. | 109 // For showing sync login UI. |
110 void HandleShowSyncUI(const base::ListValue* args); | 110 void HandleShowSyncUI(const base::ListValue* args); |
111 | 111 |
112 // For when the IP address of the printer has been resolved for registration. | 112 // For when the IP address of the printer has been resolved for registration. |
113 void StartRegisterHTTP( | 113 void StartRegisterHTTP( |
(...skipping 12 matching lines...) Expand all Loading... |
126 | 126 |
127 // Set the visibility of the page. | 127 // Set the visibility of the page. |
128 void SetIsVisible(bool visible); | 128 void SetIsVisible(bool visible); |
129 | 129 |
130 // Get the sync account email. | 130 // Get the sync account email. |
131 std::string GetSyncAccount(); | 131 std::string GetSyncAccount(); |
132 | 132 |
133 // Reset and cancel the current registration. | 133 // Reset and cancel the current registration. |
134 void ResetCurrentRegistration(); | 134 void ResetCurrentRegistration(); |
135 | 135 |
136 scoped_ptr<base::DictionaryValue> CreatePrinterInfo( | |
137 const CloudPrintPrinterList::PrinterDetails& description); | |
138 | |
139 // Announcement hasn't been sent for a certain time after registration | 136 // Announcement hasn't been sent for a certain time after registration |
140 // finished. Consider it failed. | 137 // finished. Consider it failed. |
141 // TODO(noamsml): Re-resolve service first. | 138 // TODO(noamsml): Re-resolve service first. |
142 void OnAnnouncementTimeoutReached(); | 139 void OnAnnouncementTimeoutReached(); |
143 | 140 |
144 void CheckUserLoggedIn(); | 141 void CheckUserLoggedIn(); |
145 | 142 |
| 143 void CheckListingDone(); |
| 144 |
146 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 145 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
147 void StartCloudPrintConnector(); | 146 void StartCloudPrintConnector(); |
148 void OnCloudPrintPrefsChanged(); | 147 void OnCloudPrintPrefsChanged(); |
149 void ShowCloudPrintSetupDialog(const base::ListValue* args); | 148 void ShowCloudPrintSetupDialog(const base::ListValue* args); |
150 void HandleDisableCloudPrintConnector(const base::ListValue* args); | 149 void HandleDisableCloudPrintConnector(const base::ListValue* args); |
151 void SetupCloudPrintConnectorSection(); | 150 void SetupCloudPrintConnectorSection(); |
152 void RemoveCloudPrintConnectorSection(); | 151 void RemoveCloudPrintConnectorSection(); |
153 void RefreshCloudPrintStatusFromService(); | 152 void RefreshCloudPrintStatusFromService(); |
154 #endif | 153 #endif |
155 | 154 |
(...skipping 19 matching lines...) Expand all Loading... |
175 scoped_ptr<PrivetHTTPResolution> privet_resolution_; | 174 scoped_ptr<PrivetHTTPResolution> privet_resolution_; |
176 | 175 |
177 // A map of current device descriptions provided by the PrivetDeviceLister. | 176 // A map of current device descriptions provided by the PrivetDeviceLister. |
178 DeviceDescriptionMap device_descriptions_; | 177 DeviceDescriptionMap device_descriptions_; |
179 | 178 |
180 // Whether or not the page is marked as visible. | 179 // Whether or not the page is marked as visible. |
181 bool is_visible_; | 180 bool is_visible_; |
182 | 181 |
183 // List of printers from cloud print. | 182 // List of printers from cloud print. |
184 scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_; | 183 scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_; |
| 184 scoped_ptr<CloudDeviceList> cloud_device_list_; |
| 185 int failed_list_count_; |
| 186 int succeded_list_count_; |
185 | 187 |
186 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 188 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
187 StringPrefMember cloud_print_connector_email_; | 189 StringPrefMember cloud_print_connector_email_; |
188 BooleanPrefMember cloud_print_connector_enabled_; | 190 BooleanPrefMember cloud_print_connector_enabled_; |
189 bool cloud_print_connector_ui_enabled_; | 191 bool cloud_print_connector_ui_enabled_; |
190 #endif | 192 #endif |
191 | 193 |
192 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); | 194 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); |
193 }; | 195 }; |
194 | 196 |
195 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE | 197 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE |
196 | 198 |
197 } // namespace local_discovery | 199 } // namespace local_discovery |
198 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 200 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
OLD | NEW |