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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chromeos/printer_detector/printer_detector.h" | 19 #include "chrome/browser/chromeos/printer_detector/printer_detector.h" |
| 20 #include "chrome/browser/chromeos/printing/usb_printer_util.h" |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #include "chrome/browser/notifications/notification.h" | 22 #include "chrome/browser/notifications/notification.h" |
22 #include "chrome/browser/notifications/notification_delegate.h" | 23 #include "chrome/browser/notifications/notification_delegate.h" |
23 #include "chrome/browser/notifications/notification_ui_manager.h" | 24 #include "chrome/browser/notifications/notification_ui_manager.h" |
24 #include "chrome/browser/ui/browser_navigator.h" | 25 #include "chrome/browser/ui/browser_navigator.h" |
25 #include "chrome/common/extensions/api/webstore_widget_private.h" | 26 #include "chrome/common/extensions/api/webstore_widget_private.h" |
26 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "chrome/grit/theme_resources.h" | 29 #include "chrome/grit/theme_resources.h" |
29 #include "components/user_manager/user.h" | 30 #include "components/user_manager/user.h" |
(...skipping 21 matching lines...) Expand all Loading... |
51 | 52 |
52 namespace chromeos { | 53 namespace chromeos { |
53 namespace { | 54 namespace { |
54 | 55 |
55 const char kPrinterProviderFoundNotificationID[] = | 56 const char kPrinterProviderFoundNotificationID[] = |
56 "chrome://settings/printer/printer_app_found"; | 57 "chrome://settings/printer/printer_app_found"; |
57 | 58 |
58 const char kNoPrinterProviderNotificationID[] = | 59 const char kNoPrinterProviderNotificationID[] = |
59 "chrome://settings/printer/no_printer_app"; | 60 "chrome://settings/printer/no_printer_app"; |
60 | 61 |
61 // Base class used for printer USB interfaces | |
62 // (https://www.usb.org/developers/defined_class). | |
63 const uint8_t kPrinterInterfaceClass = 7; | |
64 | |
65 enum PrinterServiceEvent { | 62 enum PrinterServiceEvent { |
66 PRINTER_ADDED, | 63 PRINTER_ADDED, |
67 DEPRECATED_PAGE_DISPLAYED, | 64 DEPRECATED_PAGE_DISPLAYED, |
68 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, | 65 NOTIFICATION_SHOWN_PRINTER_SUPPORTED, |
69 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED, | 66 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED, |
70 WEBSTORE_WIDGET_APP_LAUNCHED, | 67 WEBSTORE_WIDGET_APP_LAUNCHED, |
71 PRINTER_SERVICE_EVENT_MAX, | 68 PRINTER_SERVICE_EVENT_MAX, |
72 }; | 69 }; |
73 | 70 |
74 base::string16 GetNotificationTitle(uint16_t vendor_id, uint16_t product_id) { | 71 base::string16 GetNotificationTitle(uint16_t vendor_id, uint16_t product_id) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 private: | 223 private: |
227 // UsbService::observer override: | 224 // UsbService::observer override: |
228 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override { | 225 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override { |
229 const user_manager::User* user = | 226 const user_manager::User* user = |
230 ProfileHelper::Get()->GetUserByProfile(profile_); | 227 ProfileHelper::Get()->GetUserByProfile(profile_); |
231 if (!user || !user->HasGaiaAccount() || !user_manager::UserManager::Get() || | 228 if (!user || !user->HasGaiaAccount() || !user_manager::UserManager::Get() || |
232 user != user_manager::UserManager::Get()->GetActiveUser()) { | 229 user != user_manager::UserManager::Get()->GetActiveUser()) { |
233 return; | 230 return; |
234 } | 231 } |
235 | 232 |
236 device::UsbDeviceFilter printer_filter; | 233 if (!UsbDeviceIsPrinter(device)) { |
237 printer_filter.interface_class = kPrinterInterfaceClass; | |
238 if (!printer_filter.Matches(device)) | |
239 return; | 234 return; |
| 235 } |
240 | 236 |
241 if (notification_ui_manager_ == nullptr) { | 237 if (notification_ui_manager_ == nullptr) { |
242 notification_ui_manager_ = g_browser_process->notification_ui_manager(); | 238 notification_ui_manager_ = g_browser_process->notification_ui_manager(); |
243 } | 239 } |
244 | 240 |
245 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", | 241 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", |
246 PRINTER_ADDED, PRINTER_SERVICE_EVENT_MAX); | 242 PRINTER_ADDED, PRINTER_SERVICE_EVENT_MAX); |
247 ShowPrinterPluggedNotification(device); | 243 ShowPrinterPluggedNotification(device); |
248 } | 244 } |
249 | 245 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 324 |
329 } // namespace | 325 } // namespace |
330 | 326 |
331 // static | 327 // static |
332 std::unique_ptr<PrinterDetector> PrinterDetector::CreateLegacy( | 328 std::unique_ptr<PrinterDetector> PrinterDetector::CreateLegacy( |
333 Profile* profile) { | 329 Profile* profile) { |
334 return base::MakeUnique<LegacyPrinterDetectorImpl>(profile); | 330 return base::MakeUnique<LegacyPrinterDetectorImpl>(profile); |
335 } | 331 } |
336 | 332 |
337 } // namespace chromeos | 333 } // namespace chromeos |
OLD | NEW |