OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/browser/chromeos/printer_detector/printer_detector.h" | 5 #include "chrome/browser/chromeos/printer_detector/printer_detector.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
18 #include "chrome/browser/notifications/notification_delegate.h" | 19 #include "chrome/browser/notifications/notification_delegate.h" |
19 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
20 #include "chrome/common/extensions/api/webstore_widget_private.h" | 21 #include "chrome/common/extensions/api/webstore_widget_private.h" |
(...skipping 25 matching lines...) Expand all Loading... |
46 namespace { | 47 namespace { |
47 | 48 |
48 const char kPrinterProviderFoundNotificationID[] = | 49 const char kPrinterProviderFoundNotificationID[] = |
49 "chrome://settings/printer/printer_app_found"; | 50 "chrome://settings/printer/printer_app_found"; |
50 | 51 |
51 const char kNoPrinterProviderNotificationID[] = | 52 const char kNoPrinterProviderNotificationID[] = |
52 "chrome://settings/printer/no_printer_app"; | 53 "chrome://settings/printer/no_printer_app"; |
53 | 54 |
54 // Base class used for printer USB interfaces | 55 // Base class used for printer USB interfaces |
55 // (https://www.usb.org/developers/defined_class). | 56 // (https://www.usb.org/developers/defined_class). |
56 const uint8 kPrinterInterfaceClass = 7; | 57 const uint8_t kPrinterInterfaceClass = 7; |
57 | 58 |
58 enum PrinterServiceEvent { | 59 enum PrinterServiceEvent { |
59 PRINTER_ADDED, | 60 PRINTER_ADDED, |
60 DEPRECATED_PAGE_DISPLAYED, | 61 DEPRECATED_PAGE_DISPLAYED, |
61 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, | 62 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, |
62 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED, | 63 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED, |
63 WEBSTORE_WIDGET_APP_LAUNCHED, | 64 WEBSTORE_WIDGET_APP_LAUNCHED, |
64 PRINTER_SERVICE_EVENT_MAX, | 65 PRINTER_SERVICE_EVENT_MAX, |
65 }; | 66 }; |
66 | 67 |
67 base::string16 GetNotificationTitle(uint16 vendor_id, uint16 product_id) { | 68 base::string16 GetNotificationTitle(uint16_t vendor_id, uint16_t product_id) { |
68 const char* vendor_name = device::UsbIds::GetVendorName(vendor_id); | 69 const char* vendor_name = device::UsbIds::GetVendorName(vendor_id); |
69 if (vendor_name) { | 70 if (vendor_name) { |
70 return l10n_util::GetStringFUTF16(IDS_PRINTER_DETECTED_NOTIFICATION_TITLE, | 71 return l10n_util::GetStringFUTF16(IDS_PRINTER_DETECTED_NOTIFICATION_TITLE, |
71 base::UTF8ToUTF16(vendor_name)); | 72 base::UTF8ToUTF16(vendor_name)); |
72 } else { | 73 } else { |
73 return l10n_util::GetStringUTF16( | 74 return l10n_util::GetStringUTF16( |
74 IDS_PRINTER_DETECTED_NOTIFICATION_TITLE_UNKNOWN_VENDOR); | 75 IDS_PRINTER_DETECTED_NOTIFICATION_TITLE_UNKNOWN_VENDOR); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 }; | 136 }; |
136 | 137 |
137 // Delegate for notification shown when there are no printer provider apps that | 138 // Delegate for notification shown when there are no printer provider apps that |
138 // support the plugged in printer found. | 139 // support the plugged in printer found. |
139 // The notification is clickable, and clicking it is supposed to launch | 140 // The notification is clickable, and clicking it is supposed to launch |
140 // Chrome Web Store widget listing apps that can support the plugged in printer. | 141 // Chrome Web Store widget listing apps that can support the plugged in printer. |
141 // (not implemented yet). | 142 // (not implemented yet). |
142 class SearchPrinterAppNotificationDelegate : public NotificationDelegate { | 143 class SearchPrinterAppNotificationDelegate : public NotificationDelegate { |
143 public: | 144 public: |
144 SearchPrinterAppNotificationDelegate(content::BrowserContext* browser_context, | 145 SearchPrinterAppNotificationDelegate(content::BrowserContext* browser_context, |
145 uint16 vendor_id, | 146 uint16_t vendor_id, |
146 const std::string& vendor_id_str, | 147 const std::string& vendor_id_str, |
147 uint16 product_id, | 148 uint16_t product_id, |
148 const std::string& product_id_str) | 149 const std::string& product_id_str) |
149 : browser_context_(browser_context), | 150 : browser_context_(browser_context), |
150 vendor_id_(vendor_id), | 151 vendor_id_(vendor_id), |
151 vendor_id_str_(vendor_id_str), | 152 vendor_id_str_(vendor_id_str), |
152 product_id_(product_id), | 153 product_id_(product_id), |
153 product_id_str_(product_id_str) {} | 154 product_id_str_(product_id_str) {} |
154 | 155 |
155 std::string id() const override { | 156 std::string id() const override { |
156 return "system.printer.no_printer_provider_found/" + | 157 return "system.printer.no_printer_provider_found/" + |
157 GetNotificationTag(vendor_id_str_, product_id_str_); | 158 GetNotificationTag(vendor_id_str_, product_id_str_); |
(...skipping 17 matching lines...) Expand all Loading... |
175 webstore_widget_private_api::OnShowWidget::kEventName, | 176 webstore_widget_private_api::OnShowWidget::kEventName, |
176 webstore_widget_private_api::OnShowWidget::Create(options))); | 177 webstore_widget_private_api::OnShowWidget::Create(options))); |
177 event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId, | 178 event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId, |
178 event.Pass()); | 179 event.Pass()); |
179 } | 180 } |
180 | 181 |
181 private: | 182 private: |
182 ~SearchPrinterAppNotificationDelegate() override = default; | 183 ~SearchPrinterAppNotificationDelegate() override = default; |
183 | 184 |
184 content::BrowserContext* browser_context_; | 185 content::BrowserContext* browser_context_; |
185 uint16 vendor_id_; | 186 uint16_t vendor_id_; |
186 std::string vendor_id_str_; | 187 std::string vendor_id_str_; |
187 uint16 product_id_; | 188 uint16_t product_id_; |
188 std::string product_id_str_; | 189 std::string product_id_str_; |
189 | 190 |
190 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate); | 191 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate); |
191 }; | 192 }; |
192 | 193 |
193 // Shows a notification for a plugged in printer. | 194 // Shows a notification for a plugged in printer. |
194 // If there is a printerProvider app that handles the printer's USB (vendor_id, | 195 // If there is a printerProvider app that handles the printer's USB (vendor_id, |
195 // product_id) pair, the notification informs the user that the printer is ready | 196 // product_id) pair, the notification informs the user that the printer is ready |
196 // to be used, otherwise it offers the user to search the Chrome Web Store for | 197 // to be used, otherwise it offers the user to search the Chrome Web Store for |
197 // an app that can handle the printer. | 198 // an app that can handle the printer. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 : g_browser_process->notification_ui_manager(), | 299 : g_browser_process->notification_ui_manager(), |
299 device); | 300 device); |
300 } | 301 } |
301 | 302 |
302 void PrinterDetector::SetNotificationUIManagerForTesting( | 303 void PrinterDetector::SetNotificationUIManagerForTesting( |
303 NotificationUIManager* manager) { | 304 NotificationUIManager* manager) { |
304 notification_ui_manager_ = manager; | 305 notification_ui_manager_ = manager; |
305 } | 306 } |
306 | 307 |
307 } // namespace chromeos | 308 } // namespace chromeos |
OLD | NEW |