| 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 |
| 9 #include <memory> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
| 20 #include "chrome/browser/notifications/notification_delegate.h" | 21 #include "chrome/browser/notifications/notification_delegate.h" |
| 21 #include "chrome/browser/notifications/notification_ui_manager.h" | 22 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 22 #include "chrome/common/extensions/api/webstore_widget_private.h" | 23 #include "chrome/common/extensions/api/webstore_widget_private.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 WEBSTORE_WIDGET_APP_LAUNCHED, | 166 WEBSTORE_WIDGET_APP_LAUNCHED, |
| 166 PRINTER_SERVICE_EVENT_MAX); | 167 PRINTER_SERVICE_EVENT_MAX); |
| 167 webstore_widget_private_api::Options options; | 168 webstore_widget_private_api::Options options; |
| 168 options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER; | 169 options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER; |
| 169 options.usb_id.reset(new webstore_widget_private_api::UsbId()); | 170 options.usb_id.reset(new webstore_widget_private_api::UsbId()); |
| 170 options.usb_id->vendor_id = vendor_id_; | 171 options.usb_id->vendor_id = vendor_id_; |
| 171 options.usb_id->product_id = product_id_; | 172 options.usb_id->product_id = product_id_; |
| 172 | 173 |
| 173 extensions::EventRouter* event_router = | 174 extensions::EventRouter* event_router = |
| 174 extensions::EventRouter::Get(browser_context_); | 175 extensions::EventRouter::Get(browser_context_); |
| 175 scoped_ptr<extensions::Event> event(new extensions::Event( | 176 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 176 extensions::events::WEBSTORE_WIDGET_PRIVATE_ON_SHOW_WIDGET, | 177 extensions::events::WEBSTORE_WIDGET_PRIVATE_ON_SHOW_WIDGET, |
| 177 webstore_widget_private_api::OnShowWidget::kEventName, | 178 webstore_widget_private_api::OnShowWidget::kEventName, |
| 178 webstore_widget_private_api::OnShowWidget::Create(options))); | 179 webstore_widget_private_api::OnShowWidget::Create(options))); |
| 179 event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId, | 180 event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId, |
| 180 std::move(event)); | 181 std::move(event)); |
| 181 } | 182 } |
| 182 | 183 |
| 183 private: | 184 private: |
| 184 ~SearchPrinterAppNotificationDelegate() override = default; | 185 ~SearchPrinterAppNotificationDelegate() override = default; |
| 185 | 186 |
| 186 content::BrowserContext* browser_context_; | 187 content::BrowserContext* browser_context_; |
| 187 uint16_t vendor_id_; | 188 uint16_t vendor_id_; |
| 188 std::string vendor_id_str_; | 189 std::string vendor_id_str_; |
| 189 uint16_t product_id_; | 190 uint16_t product_id_; |
| 190 std::string product_id_str_; | 191 std::string product_id_str_; |
| 191 | 192 |
| 192 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate); | 193 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate); |
| 193 }; | 194 }; |
| 194 | 195 |
| 195 // Shows a notification for a plugged in printer. | 196 // Shows a notification for a plugged in printer. |
| 196 // If there is a printerProvider app that handles the printer's USB (vendor_id, | 197 // If there is a printerProvider app that handles the printer's USB (vendor_id, |
| 197 // product_id) pair, the notification informs the user that the printer is ready | 198 // product_id) pair, the notification informs the user that the printer is ready |
| 198 // to be used, otherwise it offers the user to search the Chrome Web Store for | 199 // to be used, otherwise it offers the user to search the Chrome Web Store for |
| 199 // an app that can handle the printer. | 200 // an app that can handle the printer. |
| 200 void ShowPrinterPluggedNotification( | 201 void ShowPrinterPluggedNotification( |
| 201 Profile* profile, | 202 Profile* profile, |
| 202 NotificationUIManager* notification_ui_manager, | 203 NotificationUIManager* notification_ui_manager, |
| 203 const scoped_refptr<device::UsbDevice>& device) { | 204 const scoped_refptr<device::UsbDevice>& device) { |
| 204 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 205 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 205 scoped_ptr<Notification> notification; | 206 std::unique_ptr<Notification> notification; |
| 206 | 207 |
| 207 const std::string kVendorIdStr = base::IntToString(device->vendor_id()); | 208 const std::string kVendorIdStr = base::IntToString(device->vendor_id()); |
| 208 const std::string kProductIdStr = base::IntToString(device->product_id()); | 209 const std::string kProductIdStr = base::IntToString(device->product_id()); |
| 209 | 210 |
| 210 if (HasAppThatSupportsPrinter(profile, device)) { | 211 if (HasAppThatSupportsPrinter(profile, device)) { |
| 211 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", | 212 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", |
| 212 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, | 213 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, |
| 213 PRINTER_SERVICE_EVENT_MAX); | 214 PRINTER_SERVICE_EVENT_MAX); |
| 214 notification.reset(new Notification( | 215 notification.reset(new Notification( |
| 215 message_center::NOTIFICATION_TYPE_SIMPLE, | 216 message_center::NOTIFICATION_TYPE_SIMPLE, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 : g_browser_process->notification_ui_manager(), | 301 : g_browser_process->notification_ui_manager(), |
| 301 device); | 302 device); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void PrinterDetector::SetNotificationUIManagerForTesting( | 305 void PrinterDetector::SetNotificationUIManagerForTesting( |
| 305 NotificationUIManager* manager) { | 306 NotificationUIManager* manager) { |
| 306 notification_ui_manager_ = manager; | 307 notification_ui_manager_ = manager; |
| 307 } | 308 } |
| 308 | 309 |
| 309 } // namespace chromeos | 310 } // namespace chromeos |
| OLD | NEW |