OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/usb_service/usb_service.h" | 5 #include "components/usb_service/usb_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // UsbDevice will be destroyed after this. The corresponding | 147 // UsbDevice will be destroyed after this. The corresponding |
148 // PlatformUsbDevice will be unref'ed during this process. | 148 // PlatformUsbDevice will be unref'ed during this process. |
149 devices_.erase(disconnected_devices[i]); | 149 devices_.erase(disconnected_devices[i]); |
150 } | 150 } |
151 | 151 |
152 libusb_free_device_list(platform_devices, true); | 152 libusb_free_device_list(platform_devices, true); |
153 } | 153 } |
154 | 154 |
155 // static | 155 // static |
156 UsbService* UsbService::GetInstance() { | 156 UsbService* UsbService::GetInstance() { |
157 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
158 UsbService* instance = g_usb_service_instance.Get().get(); | 157 UsbService* instance = g_usb_service_instance.Get().get(); |
159 if (!instance) { | 158 if (!instance) { |
160 PlatformUsbContext context = NULL; | 159 PlatformUsbContext context = NULL; |
161 | 160 |
162 const int rv = libusb_init(&context); | 161 const int rv = libusb_init(&context); |
163 if (rv != LIBUSB_SUCCESS) { | 162 if (rv != LIBUSB_SUCCESS) { |
164 VLOG(1) << "Failed to initialize libusb: " << ConvertErrorToString(rv); | 163 VLOG(1) << "Failed to initialize libusb: " << ConvertErrorToString(rv); |
165 return NULL; | 164 return NULL; |
166 } | 165 } |
167 if (!context) | 166 if (!context) |
168 return NULL; | 167 return NULL; |
169 | 168 |
170 instance = new UsbServiceImpl(context); | 169 instance = new UsbServiceImpl(context); |
171 g_usb_service_instance.Get().reset(instance); | 170 g_usb_service_instance.Get().reset(instance); |
172 } | 171 } |
173 return instance; | 172 return instance; |
174 } | 173 } |
175 | 174 |
176 // static | 175 // static |
177 void UsbService::SetInstanceForTest(UsbService* instance) { | 176 void UsbService::SetInstanceForTest(UsbService* instance) { |
178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
179 g_usb_service_instance.Get().reset(instance); | 177 g_usb_service_instance.Get().reset(instance); |
180 } | 178 } |
181 | 179 |
182 } // namespace usb_service | 180 } // namespace usb_service |
OLD | NEW |