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
3 // found in the LICENSE file.
5 #include "device/usb/usb_service.h"
7 #include "base/message_loop/message_loop.h"
8 #include "components/device_event_log/device_event_log.h"
9 #include "device/usb/usb_device.h"
10 #include "device/usb/usb_service_impl.h"
16 UsbService
* g_service
;
20 void UsbService::Observer::OnDeviceAdded(scoped_refptr
<UsbDevice
> device
) {
23 void UsbService::Observer::OnDeviceRemoved(scoped_refptr
<UsbDevice
> device
) {
26 void UsbService::Observer::OnDeviceRemovedCleanup(
27 scoped_refptr
<UsbDevice
> device
) {
31 UsbService
* UsbService::GetInstance(
32 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner
) {
34 // UsbService constructor saves the pointer this returns and UsbServiceImpl
35 // will destroy itself when the current message loop exits.
36 UsbServiceImpl::Create(blocking_task_runner
);
41 UsbService::UsbService() {
46 UsbService::~UsbService() {
51 void UsbService::AddObserver(Observer
* observer
) {
52 DCHECK(CalledOnValidThread());
53 observer_list_
.AddObserver(observer
);
56 void UsbService::RemoveObserver(Observer
* observer
) {
57 DCHECK(CalledOnValidThread());
58 observer_list_
.RemoveObserver(observer
);
61 void UsbService::NotifyDeviceAdded(scoped_refptr
<UsbDevice
> device
) {
62 DCHECK(CalledOnValidThread());
64 FOR_EACH_OBSERVER(Observer
, observer_list_
, OnDeviceAdded(device
));
67 void UsbService::NotifyDeviceRemoved(scoped_refptr
<UsbDevice
> device
) {
68 DCHECK(CalledOnValidThread());
70 FOR_EACH_OBSERVER(Observer
, observer_list_
, OnDeviceRemoved(device
));
71 FOR_EACH_OBSERVER(Observer
, observer_list_
, OnDeviceRemovedCleanup(device
));