Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h

Issue 1553333002: Move cloud print specific files out of local_discovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moveprn
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 12 #include "base/macros.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" 14 #include "chrome/browser/printing/cloud_print/cloud_print_printer_list.h"
15 #include "chrome/browser/local_discovery/privet_device_lister.h" 15 #include "chrome/browser/printing/cloud_print/privet_device_lister.h"
16 #include "chrome/browser/local_discovery/privet_http.h" 16 #include "chrome/browser/printing/cloud_print/privet_http.h"
17 #include "components/signin/core/browser/signin_manager.h" 17 #include "components/signin/core/browser/signin_manager.h"
18 #include "content/public/browser/web_ui_message_handler.h" 18 #include "content/public/browser/web_ui_message_handler.h"
19 19
20 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS) 20 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
21 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE 21 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE
22 #endif 22 #endif
23 23
24 namespace cloud_print {
25 class PrivetConfirmApiCallFlow;
26 class PrivetHTTPAsynchronousFactory;
27 class PrivetHTTPResolution;
28 class PrivetV1HTTPClient;
29 }
30
24 // TODO(noamsml): Factor out full registration flow into single class 31 // TODO(noamsml): Factor out full registration flow into single class
25 namespace local_discovery { 32 namespace local_discovery {
26 33
27 class PrivetConfirmApiCallFlow;
28 class PrivetHTTPAsynchronousFactory;
29 class PrivetHTTPResolution;
30 class PrivetV1HTTPClient;
31 class ServiceDiscoverySharedClient; 34 class ServiceDiscoverySharedClient;
32 35
33 // UI Handler for chrome://devices/ 36 // UI Handler for chrome://devices/
34 // It listens to local discovery notifications and passes those notifications 37 // It listens to local discovery notifications and passes those notifications
35 // into the Javascript to update the page. 38 // into the Javascript to update the page.
36 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, 39 class LocalDiscoveryUIHandler
37 public PrivetRegisterOperation::Delegate, 40 : public content::WebUIMessageHandler,
38 public PrivetDeviceLister::Delegate, 41 public cloud_print::PrivetRegisterOperation::Delegate,
39 public CloudPrintPrinterList::Delegate, 42 public cloud_print::PrivetDeviceLister::Delegate,
40 public SigninManagerBase::Observer { 43 public cloud_print::CloudPrintPrinterList::Delegate,
44 public SigninManagerBase::Observer {
41 public: 45 public:
42 LocalDiscoveryUIHandler(); 46 LocalDiscoveryUIHandler();
43 ~LocalDiscoveryUIHandler() override; 47 ~LocalDiscoveryUIHandler() override;
44 48
45 static bool GetHasVisible(); 49 static bool GetHasVisible();
46 50
47 // WebUIMessageHandler implementation. 51 // WebUIMessageHandler implementation.
48 void RegisterMessages() override; 52 void RegisterMessages() override;
49 // PrivetRegisterOperation::Delegate implementation. 53 // PrivetRegisterOperation::Delegate implementation.
50 void OnPrivetRegisterClaimToken(PrivetRegisterOperation* operation, 54 void OnPrivetRegisterClaimToken(
51 const std::string& token, 55 cloud_print::PrivetRegisterOperation* operation,
52 const GURL& url) override; 56 const std::string& token,
53 void OnPrivetRegisterError(PrivetRegisterOperation* operation, 57 const GURL& url) override;
54 const std::string& action, 58 void OnPrivetRegisterError(
55 PrivetRegisterOperation::FailureReason reason, 59 cloud_print::PrivetRegisterOperation* operation,
56 int printer_http_code, 60 const std::string& action,
57 const base::DictionaryValue* json) override; 61 cloud_print::PrivetRegisterOperation::FailureReason reason,
58 void OnPrivetRegisterDone(PrivetRegisterOperation* operation, 62 int printer_http_code,
63 const base::DictionaryValue* json) override;
64 void OnPrivetRegisterDone(cloud_print::PrivetRegisterOperation* operation,
59 const std::string& device_id) override; 65 const std::string& device_id) override;
60 66
61 // PrivetDeviceLister::Delegate implementation. 67 // PrivetDeviceLister::Delegate implementation.
62 void DeviceChanged(bool added, 68 void DeviceChanged(
63 const std::string& name, 69 bool added,
64 const DeviceDescription& description) override; 70 const std::string& name,
71 const cloud_print::DeviceDescription& description) override;
65 void DeviceRemoved(const std::string& name) override; 72 void DeviceRemoved(const std::string& name) override;
66 void DeviceCacheFlushed() override; 73 void DeviceCacheFlushed() override;
67 74
68 // CloudPrintPrinterList::Delegate implementation. 75 // CloudPrintPrinterList::Delegate implementation.
69 void OnDeviceListReady( 76 void OnDeviceListReady(
70 const CloudPrintPrinterList::DeviceList& devices) override; 77 const cloud_print::CloudPrintPrinterList::DeviceList& devices) override;
71 void OnDeviceListUnavailable() override; 78 void OnDeviceListUnavailable() override;
72 79
73 // SigninManagerBase::Observer implementation. 80 // SigninManagerBase::Observer implementation.
74 void GoogleSigninSucceeded(const std::string& account_id, 81 void GoogleSigninSucceeded(const std::string& account_id,
75 const std::string& username, 82 const std::string& username,
76 const std::string& password) override; 83 const std::string& password) override;
77 void GoogleSignedOut(const std::string& account_id, 84 void GoogleSignedOut(const std::string& account_id,
78 const std::string& username) override; 85 const std::string& username) override;
79 86
80 private: 87 private:
81 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; 88 typedef std::map<std::string,
89 cloud_print::DeviceDescription> DeviceDescriptionMap;
82 typedef base::Callback<void(bool result)> ResultCallback; 90 typedef base::Callback<void(bool result)> ResultCallback;
83 91
84 // Message handlers: 92 // Message handlers:
85 // For when the page is ready to receive device notifications. 93 // For when the page is ready to receive device notifications.
86 void HandleStart(const base::ListValue* args); 94 void HandleStart(const base::ListValue* args);
87 95
88 // For when a visibility change occurs. 96 // For when a visibility change occurs.
89 void HandleIsVisible(const base::ListValue* args); 97 void HandleIsVisible(const base::ListValue* args);
90 98
91 // For when a user choice is made. 99 // For when a user choice is made.
92 void HandleRegisterDevice(const base::ListValue* args); 100 void HandleRegisterDevice(const base::ListValue* args);
93 101
94 // For when a cancellation is made. 102 // For when a cancellation is made.
95 void HandleCancelRegistration(const base::ListValue* args); 103 void HandleCancelRegistration(const base::ListValue* args);
96 104
97 // For requesting the device list. 105 // For requesting the device list.
98 void HandleRequestDeviceList(const base::ListValue* args); 106 void HandleRequestDeviceList(const base::ListValue* args);
99 107
100 // For opening URLs (relative to the Google Cloud Print base URL) in a new 108 // For opening URLs (relative to the Google Cloud Print base URL) in a new
101 // tab. 109 // tab.
102 void HandleOpenCloudPrintURL(const base::ListValue* args); 110 void HandleOpenCloudPrintURL(const base::ListValue* args);
103 111
104 // For showing sync login UI. 112 // For showing sync login UI.
105 void HandleShowSyncUI(const base::ListValue* args); 113 void HandleShowSyncUI(const base::ListValue* args);
106 114
107 // For when the IP address of the printer has been resolved for registration. 115 // For when the IP address of the printer has been resolved for registration.
108 void StartRegisterHTTP(scoped_ptr<PrivetHTTPClient> http_client); 116 void StartRegisterHTTP(scoped_ptr<cloud_print::PrivetHTTPClient> http_client);
109 117
110 // For when the confirm operation on the cloudprint server has finished 118 // For when the confirm operation on the cloudprint server has finished
111 // executing. 119 // executing.
112 void OnConfirmDone(GCDApiFlow::Status status); 120 void OnConfirmDone(cloud_print::GCDApiFlow::Status status);
113 121
114 // Signal to the web interface an error has ocurred while registering. 122 // Signal to the web interface an error has ocurred while registering.
115 void SendRegisterError(); 123 void SendRegisterError();
116 124
117 // Singal to the web interface that registration has finished. 125 // Singal to the web interface that registration has finished.
118 void SendRegisterDone(const std::string& service_name); 126 void SendRegisterDone(const std::string& service_name);
119 127
120 // Set the visibility of the page. 128 // Set the visibility of the page.
121 void SetIsVisible(bool visible); 129 void SetIsVisible(bool visible);
122 130
123 // Get the sync account email. 131 // Get the sync account email.
124 std::string GetSyncAccount(); 132 std::string GetSyncAccount();
125 133
126 // Reset and cancel the current registration. 134 // Reset and cancel the current registration.
127 void ResetCurrentRegistration(); 135 void ResetCurrentRegistration();
128 136
129 scoped_ptr<GCDApiFlow> CreateApiFlow(); 137 scoped_ptr<cloud_print::GCDApiFlow> CreateApiFlow();
130 void OnSetupError(); 138 void OnSetupError();
131 139
132 // Announcement hasn't been sent for a certain time after registration 140 // Announcement hasn't been sent for a certain time after registration
133 // finished. Consider it failed. 141 // finished. Consider it failed.
134 // TODO(noamsml): Re-resolve service first. 142 // TODO(noamsml): Re-resolve service first.
135 void OnAnnouncementTimeoutReached(); 143 void OnAnnouncementTimeoutReached();
136 144
137 void CheckUserLoggedIn(); 145 void CheckUserLoggedIn();
138 146
139 void CheckListingDone(); 147 void CheckListingDone();
(...skipping 10 matching lines...) Expand all
150 void RefreshCloudPrintStatusFromService(); 158 void RefreshCloudPrintStatusFromService();
151 #endif 159 #endif
152 160
153 // A map of current device descriptions provided by the PrivetDeviceLister. 161 // A map of current device descriptions provided by the PrivetDeviceLister.
154 DeviceDescriptionMap device_descriptions_; 162 DeviceDescriptionMap device_descriptions_;
155 163
156 // The service discovery client used listen for devices on the local network. 164 // The service discovery client used listen for devices on the local network.
157 scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_; 165 scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
158 166
159 // A factory for creating the privet HTTP Client. 167 // A factory for creating the privet HTTP Client.
160 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory_; 168 scoped_ptr<cloud_print::PrivetHTTPAsynchronousFactory> privet_http_factory_;
161 169
162 // An object representing the resolution process for the privet_http_factory. 170 // An object representing the resolution process for the privet_http_factory.
163 scoped_ptr<PrivetHTTPResolution> privet_resolution_; 171 scoped_ptr<cloud_print::PrivetHTTPResolution> privet_resolution_;
164 172
165 // The current HTTP client (used for the current operation). 173 // The current HTTP client (used for the current operation).
166 scoped_ptr<PrivetV1HTTPClient> current_http_client_; 174 scoped_ptr<cloud_print::PrivetV1HTTPClient> current_http_client_;
167 175
168 // The current register operation. Only one allowed at any time. 176 // The current register operation. Only one allowed at any time.
169 scoped_ptr<PrivetRegisterOperation> current_register_operation_; 177 scoped_ptr<cloud_print::PrivetRegisterOperation> current_register_operation_;
170 178
171 // The current confirm call used during the registration flow. 179 // The current confirm call used during the registration flow.
172 scoped_ptr<GCDApiFlow> confirm_api_call_flow_; 180 scoped_ptr<cloud_print::GCDApiFlow> confirm_api_call_flow_;
173 181
174 // The device lister used to list devices on the local network. 182 // The device lister used to list devices on the local network.
175 scoped_ptr<PrivetDeviceLister> privet_lister_; 183 scoped_ptr<cloud_print::PrivetDeviceLister> privet_lister_;
176 184
177 // Whether or not the page is marked as visible. 185 // Whether or not the page is marked as visible.
178 bool is_visible_; 186 bool is_visible_;
179 187
180 // List of printers from cloud print. 188 // List of printers from cloud print.
181 scoped_ptr<GCDApiFlow> cloud_print_printer_list_; 189 scoped_ptr<cloud_print::GCDApiFlow> cloud_print_printer_list_;
182 std::vector<CloudPrintPrinterList::Device> cloud_devices_; 190 std::vector<cloud_print::CloudPrintPrinterList::Device> cloud_devices_;
183 int failed_list_count_; 191 int failed_list_count_;
184 int succeded_list_count_; 192 int succeded_list_count_;
185 193
186 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 194 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
187 StringPrefMember cloud_print_connector_email_; 195 StringPrefMember cloud_print_connector_email_;
188 BooleanPrefMember cloud_print_connector_enabled_; 196 BooleanPrefMember cloud_print_connector_enabled_;
189 bool cloud_print_connector_ui_enabled_; 197 bool cloud_print_connector_ui_enabled_;
190 #endif 198 #endif
191 199
192 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); 200 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler);
193 }; 201 };
194 202
195 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE 203 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE
196 204
197 } // namespace local_discovery 205 } // namespace local_discovery
198 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ 206 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698