| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 // UsbService::observer override. | 96 // UsbService::observer override. |
| 97 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override { | 97 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override { |
| 98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 99 MaybeSetUpDevice(device, true); | 99 MaybeSetUpDevice(device, true); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // UsbService::observer override. | 102 // UsbService::observer override. |
| 103 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override { | 103 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override { |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 105 if (!UsbDeviceIsPrinter(device)) { | 105 if (!UsbDeviceIsPrinter(*device)) { |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 known_printers_.erase(device->guid()); | 108 known_printers_.erase(device->guid()); |
| 109 // TODO(justincarlson): Update failed printers. | 109 // TODO(justincarlson): Update failed printers. |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Returns the existing printer using this URI, if one exists, or | 112 // Returns the existing printer using this URI, if one exists, or |
| 113 // null otherwise. | 113 // null otherwise. |
| 114 std::unique_ptr<Printer> FindExistingPrinter(const std::string& uri) { | 114 std::unique_ptr<Printer> FindExistingPrinter(const std::string& uri) { |
| 115 // TODO(justincarlson): add a GetPrinterByURI to PrintersManager. | 115 // TODO(justincarlson): add a GetPrinterByURI to PrintersManager. |
| 116 // https://crbug.com/700602 | 116 // https://crbug.com/700602 |
| 117 auto existing_printers = | 117 auto existing_printers = |
| 118 PrintersManagerFactory::GetForBrowserContext(profile_)->GetPrinters(); | 118 PrintersManagerFactory::GetForBrowserContext(profile_)->GetPrinters(); |
| 119 for (std::unique_ptr<Printer>& printer : existing_printers) { | 119 for (std::unique_ptr<Printer>& printer : existing_printers) { |
| 120 if (printer->uri() == uri) { | 120 if (printer->uri() == uri) { |
| 121 // Found a match, so use the existing configuration. | 121 // Found a match, so use the existing configuration. |
| 122 return std::move(printer); | 122 return std::move(printer); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return nullptr; | 125 return nullptr; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // If this device is a printer and we haven't already tried to set it up, | 128 // If this device is a printer and we haven't already tried to set it up, |
| 129 // starts the process of setting the printer up. |hotplugged| | 129 // starts the process of setting the printer up. |hotplugged| |
| 130 // should be true if this was plugged in during the session. | 130 // should be true if this was plugged in during the session. |
| 131 void MaybeSetUpDevice(scoped_refptr<device::UsbDevice> device, | 131 void MaybeSetUpDevice(scoped_refptr<device::UsbDevice> device, |
| 132 bool hotplugged) { | 132 bool hotplugged) { |
| 133 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 133 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 134 | 134 |
| 135 if (!UsbDeviceIsPrinter(device) || | 135 if (!UsbDeviceIsPrinter(*device) || |
| 136 base::ContainsKey(known_printers_, device->guid())) { | 136 base::ContainsKey(known_printers_, device->guid())) { |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 known_printers_.insert(device->guid()); | 139 known_printers_.insert(device->guid()); |
| 140 | 140 |
| 141 auto data = base::MakeUnique<SetUpPrinterData>(); | 141 auto data = base::MakeUnique<SetUpPrinterData>(); |
| 142 data->configurer = PrinterConfigurer::Create(profile_); | 142 data->configurer = PrinterConfigurer::Create(profile_); |
| 143 data->device = device; | 143 data->device = device; |
| 144 data->hotplugged = hotplugged; | 144 data->hotplugged = hotplugged; |
| 145 | 145 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 } // namespace | 247 } // namespace |
| 248 | 248 |
| 249 // static | 249 // static |
| 250 std::unique_ptr<PrinterDetector> PrinterDetector::CreateCups(Profile* profile) { | 250 std::unique_ptr<PrinterDetector> PrinterDetector::CreateCups(Profile* profile) { |
| 251 return base::MakeUnique<CupsPrinterDetectorImpl>(profile); | 251 return base::MakeUnique<CupsPrinterDetectorImpl>(profile); |
| 252 } | 252 } |
| 253 | 253 |
| 254 } // namespace chromeos | 254 } // namespace chromeos |
| OLD | NEW |