Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: device/usb/usb_service.cc

Issue 2482463002: Remove DeviceMonitorLinux::WillDestroyCurrentMessageLoop(). (Closed)
Patch Set: CR achuithb #24 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/usb/usb_service.h ('k') | device/usb/usb_service_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "device/usb/usb_service.h" 5 #include "device/usb/usb_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #elif defined(USE_UDEV) 44 #elif defined(USE_UDEV)
45 return base::WrapUnique(new UsbServiceLinux(blocking_task_runner)); 45 return base::WrapUnique(new UsbServiceLinux(blocking_task_runner));
46 #elif defined(OS_WIN) || defined(OS_MACOSX) 46 #elif defined(OS_WIN) || defined(OS_MACOSX)
47 return base::WrapUnique(new UsbServiceImpl(blocking_task_runner)); 47 return base::WrapUnique(new UsbServiceImpl(blocking_task_runner));
48 #else 48 #else
49 return nullptr; 49 return nullptr;
50 #endif 50 #endif
51 } 51 }
52 52
53 UsbService::~UsbService() { 53 UsbService::~UsbService() {
54 #if DCHECK_IS_ON()
55 DCHECK(did_shutdown_);
56 #endif
54 for (const auto& map_entry : devices_) 57 for (const auto& map_entry : devices_)
55 map_entry.second->OnDisconnect(); 58 map_entry.second->OnDisconnect();
56 for (auto& observer : observer_list_) 59 for (auto& observer : observer_list_)
57 observer.WillDestroyUsbService(); 60 observer.WillDestroyUsbService();
58 } 61 }
59 62
60 UsbService::UsbService( 63 UsbService::UsbService(
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
62 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) 65 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
63 : task_runner_(task_runner), blocking_task_runner_(blocking_task_runner) {} 66 : task_runner_(task_runner), blocking_task_runner_(blocking_task_runner) {}
64 67
65 scoped_refptr<UsbDevice> UsbService::GetDevice(const std::string& guid) { 68 scoped_refptr<UsbDevice> UsbService::GetDevice(const std::string& guid) {
66 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
67 auto it = devices_.find(guid); 70 auto it = devices_.find(guid);
68 if (it == devices_.end()) 71 if (it == devices_.end())
69 return nullptr; 72 return nullptr;
70 return it->second; 73 return it->second;
71 } 74 }
72 75
76 void UsbService::Shutdown() {
77 #if DCHECK_IS_ON()
78 DCHECK(!did_shutdown_);
79 did_shutdown_ = true;
80 #endif
81 }
82
73 void UsbService::GetDevices(const GetDevicesCallback& callback) { 83 void UsbService::GetDevices(const GetDevicesCallback& callback) {
74 std::vector<scoped_refptr<UsbDevice>> devices; 84 std::vector<scoped_refptr<UsbDevice>> devices;
75 devices.reserve(devices_.size()); 85 devices.reserve(devices_.size());
76 for (const auto& map_entry : devices_) 86 for (const auto& map_entry : devices_)
77 devices.push_back(map_entry.second); 87 devices.push_back(map_entry.second);
78 if (task_runner_) 88 if (task_runner_)
79 task_runner_->PostTask(FROM_HERE, base::Bind(callback, devices)); 89 task_runner_->PostTask(FROM_HERE, base::Bind(callback, devices));
80 else 90 else
81 callback.Run(devices); 91 callback.Run(devices);
82 } 92 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(CalledOnValidThread()); 146 DCHECK(CalledOnValidThread());
137 147
138 for (auto& observer : observer_list_) 148 for (auto& observer : observer_list_)
139 observer.OnDeviceRemoved(device); 149 observer.OnDeviceRemoved(device);
140 device->NotifyDeviceRemoved(); 150 device->NotifyDeviceRemoved();
141 for (auto& observer : observer_list_) 151 for (auto& observer : observer_list_)
142 observer.OnDeviceRemovedCleanup(device); 152 observer.OnDeviceRemovedCleanup(device);
143 } 153 }
144 154
145 } // namespace device 155 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_service.h ('k') | device/usb/usb_service_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698