| 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/usb/web_usb_detector.h" | 5 #include "chrome/browser/usb/web_usb_detector.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 GURL landing_page_; | 107 GURL landing_page_; |
| 108 std::string notification_id_; | 108 std::string notification_id_; |
| 109 bool clicked_ = false; | 109 bool clicked_ = false; |
| 110 | 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); | 111 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 WebUsbDetector::WebUsbDetector() : observer_(this) { | 116 WebUsbDetector::WebUsbDetector() : observer_(this) {} |
| 117 Initialize(); | |
| 118 } | |
| 119 | 117 |
| 120 WebUsbDetector::~WebUsbDetector() {} | 118 WebUsbDetector::~WebUsbDetector() {} |
| 121 | 119 |
| 122 void WebUsbDetector::Initialize() { | 120 void WebUsbDetector::Initialize() { |
| 121 SCOPED_UMA_HISTOGRAM_TIMER("WebUsb.DetectorInitialization"); |
| 123 device::UsbService* usb_service = | 122 device::UsbService* usb_service = |
| 124 device::DeviceClient::Get()->GetUsbService(); | 123 device::DeviceClient::Get()->GetUsbService(); |
| 125 if (!usb_service) | 124 if (!usb_service) |
| 126 return; | 125 return; |
| 127 | 126 |
| 128 observer_.Add(usb_service); | 127 observer_.Add(usb_service); |
| 129 } | 128 } |
| 130 | 129 |
| 131 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) { | 130 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) { |
| 132 const base::string16& product_name = device->product_string(); | 131 const base::string16& product_name = device->product_string(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 163 } |
| 165 | 164 |
| 166 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { | 165 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { |
| 167 std::string notification_id = device->guid(); | 166 std::string notification_id = device->guid(); |
| 168 message_center::MessageCenter* message_center = | 167 message_center::MessageCenter* message_center = |
| 169 message_center::MessageCenter::Get(); | 168 message_center::MessageCenter::Get(); |
| 170 if (message_center->FindVisibleNotificationById(notification_id)) { | 169 if (message_center->FindVisibleNotificationById(notification_id)) { |
| 171 message_center->RemoveNotification(notification_id, false /* by_user */); | 170 message_center->RemoveNotification(notification_id, false /* by_user */); |
| 172 } | 171 } |
| 173 } | 172 } |
| OLD | NEW |