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

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

Issue 1874313002: Convert device to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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.cc ('k') | device/usb/usb_service_unittest.cc » ('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 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 "device/usb/usb_service_impl.h" 5 #include "device/usb/usb_service_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
8 #include <list> 9 #include <list>
10 #include <memory>
9 #include <set> 11 #include <set>
10 #include <utility> 12 #include <utility>
11 13
12 #include "base/barrier_closure.h" 14 #include "base/barrier_closure.h"
13 #include "base/bind.h" 15 #include "base/bind.h"
14 #include "base/location.h" 16 #include "base/location.h"
15 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
16 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 19 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 device_handle->Close(); 119 device_handle->Close();
118 continuation.Run(); 120 continuation.Run();
119 } 121 }
120 122
121 void SaveStringsAndRunContinuation( 123 void SaveStringsAndRunContinuation(
122 scoped_refptr<UsbDeviceImpl> device, 124 scoped_refptr<UsbDeviceImpl> device,
123 uint8_t manufacturer, 125 uint8_t manufacturer,
124 uint8_t product, 126 uint8_t product,
125 uint8_t serial_number, 127 uint8_t serial_number,
126 const base::Closure& continuation, 128 const base::Closure& continuation,
127 scoped_ptr<std::map<uint8_t, base::string16>> string_map) { 129 std::unique_ptr<std::map<uint8_t, base::string16>> string_map) {
128 if (manufacturer != 0) 130 if (manufacturer != 0)
129 device->set_manufacturer_string((*string_map)[manufacturer]); 131 device->set_manufacturer_string((*string_map)[manufacturer]);
130 if (product != 0) 132 if (product != 0)
131 device->set_product_string((*string_map)[product]); 133 device->set_product_string((*string_map)[product]);
132 if (serial_number != 0) 134 if (serial_number != 0)
133 device->set_serial_number((*string_map)[serial_number]); 135 device->set_serial_number((*string_map)[serial_number]);
134 continuation.Run(); 136 continuation.Run();
135 } 137 }
136 138
137 void OnReadBosDescriptor(scoped_refptr<UsbDeviceHandle> device_handle, 139 void OnReadBosDescriptor(scoped_refptr<UsbDeviceHandle> device_handle,
138 const base::Closure& barrier, 140 const base::Closure& barrier,
139 scoped_ptr<WebUsbAllowedOrigins> allowed_origins, 141 std::unique_ptr<WebUsbAllowedOrigins> allowed_origins,
140 const GURL& landing_page) { 142 const GURL& landing_page) {
141 scoped_refptr<UsbDeviceImpl> device = 143 scoped_refptr<UsbDeviceImpl> device =
142 static_cast<UsbDeviceImpl*>(device_handle->GetDevice().get()); 144 static_cast<UsbDeviceImpl*>(device_handle->GetDevice().get());
143 145
144 if (allowed_origins) 146 if (allowed_origins)
145 device->set_webusb_allowed_origins(std::move(allowed_origins)); 147 device->set_webusb_allowed_origins(std::move(allowed_origins));
146 if (landing_page.is_valid()) 148 if (landing_page.is_valid())
147 device->set_webusb_landing_page(landing_page); 149 device->set_webusb_landing_page(landing_page);
148 150
149 barrier.Run(); 151 barrier.Run();
150 } 152 }
151 153
152 void OnDeviceOpenedReadDescriptors( 154 void OnDeviceOpenedReadDescriptors(
153 uint8_t manufacturer, 155 uint8_t manufacturer,
154 uint8_t product, 156 uint8_t product,
155 uint8_t serial_number, 157 uint8_t serial_number,
156 bool read_bos_descriptors, 158 bool read_bos_descriptors,
157 const base::Closure& success_closure, 159 const base::Closure& success_closure,
158 const base::Closure& failure_closure, 160 const base::Closure& failure_closure,
159 scoped_refptr<UsbDeviceHandle> device_handle) { 161 scoped_refptr<UsbDeviceHandle> device_handle) {
160 if (device_handle) { 162 if (device_handle) {
161 scoped_ptr<std::map<uint8_t, base::string16>> string_map( 163 std::unique_ptr<std::map<uint8_t, base::string16>> string_map(
162 new std::map<uint8_t, base::string16>()); 164 new std::map<uint8_t, base::string16>());
163 if (manufacturer != 0) 165 if (manufacturer != 0)
164 (*string_map)[manufacturer] = base::string16(); 166 (*string_map)[manufacturer] = base::string16();
165 if (product != 0) 167 if (product != 0)
166 (*string_map)[product] = base::string16(); 168 (*string_map)[product] = base::string16();
167 if (serial_number != 0) 169 if (serial_number != 0)
168 (*string_map)[serial_number] = base::string16(); 170 (*string_map)[serial_number] = base::string16();
169 171
170 int count = 0; 172 int count = 0;
171 if (!string_map->empty()) 173 if (!string_map->empty())
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 PlatformDeviceMap::iterator it = platform_devices_.find(platform_device); 610 PlatformDeviceMap::iterator it = platform_devices_.find(platform_device);
609 if (it != platform_devices_.end()) { 611 if (it != platform_devices_.end()) {
610 RemoveDevice(it->second); 612 RemoveDevice(it->second);
611 } else { 613 } else {
612 devices_being_enumerated_.erase(platform_device); 614 devices_being_enumerated_.erase(platform_device);
613 } 615 }
614 libusb_unref_device(platform_device); 616 libusb_unref_device(platform_device);
615 } 617 }
616 618
617 } // namespace device 619 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_service.cc ('k') | device/usb/usb_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698