Add ICU message format support
[chromium-blink-merge.git] / device / usb / usb_service.cc
blob18732b50d3e14d581dca34d2641184e6b9cf7908
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"
12 namespace device {
14 namespace {
16 UsbService* g_service;
18 } // namespace
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) {
30 // static
31 UsbService* UsbService::GetInstance(
32 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
33 if (!g_service) {
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);
38 return g_service;
41 UsbService::UsbService() {
42 DCHECK(!g_service);
43 g_service = this;
46 UsbService::~UsbService() {
47 DCHECK(g_service);
48 g_service = nullptr;
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));
74 } // namespace device