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

Side by Side Diff: content/renderer/usb/web_usb_client_impl.cc

Issue 1865913005: Nuke WebPassOwnPtr<T> and replace it with std::unique_ptr<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
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 "content/renderer/usb/web_usb_client_impl.h" 5 #include "content/renderer/usb/web_usb_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
9 #include <memory>
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/ptr_util.h"
12 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
13 #include "base/move.h" 16 #include "base/move.h"
14 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
15 #include "content/child/mojo/type_converters.h" 18 #include "content/child/mojo/type_converters.h"
16 #include "content/child/scoped_web_callbacks.h" 19 #include "content/child/scoped_web_callbacks.h"
17 #include "content/public/common/service_registry.h" 20 #include "content/public/common/service_registry.h"
18 #include "content/renderer/usb/type_converters.h" 21 #include "content/renderer/usb/type_converters.h"
19 #include "content/renderer/usb/web_usb_device_impl.h" 22 #include "content/renderer/usb/web_usb_device_impl.h"
20 #include "mojo/public/cpp/bindings/array.h" 23 #include "mojo/public/cpp/bindings/array.h"
21 #include "mojo/public/cpp/bindings/interface_request.h" 24 #include "mojo/public/cpp/bindings/interface_request.h"
22 #include "third_party/WebKit/public/platform/WebCallbacks.h" 25 #include "third_party/WebKit/public/platform/WebCallbacks.h"
23 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h"
24 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceFilter.h " 26 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceFilter.h "
25 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h" 27 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h"
26 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceRequestO ptions.h" 28 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceRequestO ptions.h"
27 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBError.h" 29 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBError.h"
28 30
29 namespace content { 31 namespace content {
30 32
31 namespace { 33 namespace {
32 34
33 const char kNoServiceError[] = "USB service unavailable."; 35 const char kNoServiceError[] = "USB service unavailable.";
(...skipping 16 matching lines...) Expand all
50 callbacks, 52 callbacks,
51 base::Bind(&RejectCallbacksWithError<CallbacksType>, 53 base::Bind(&RejectCallbacksWithError<CallbacksType>,
52 blink::WebUSBError(blink::WebUSBError::Error::NotFound, 54 blink::WebUSBError(blink::WebUSBError::Error::NotFound,
53 base::ASCIIToUTF16(kNoServiceError)))); 55 base::ASCIIToUTF16(kNoServiceError))));
54 } 56 }
55 57
56 void OnGetDevicesComplete( 58 void OnGetDevicesComplete(
57 ScopedWebCallbacks<blink::WebUSBClientGetDevicesCallbacks> scoped_callbacks, 59 ScopedWebCallbacks<blink::WebUSBClientGetDevicesCallbacks> scoped_callbacks,
58 device::usb::DeviceManager* device_manager, 60 device::usb::DeviceManager* device_manager,
59 mojo::Array<device::usb::DeviceInfoPtr> results) { 61 mojo::Array<device::usb::DeviceInfoPtr> results) {
60 blink::WebVector<blink::WebUSBDevice*>* devices = 62 // TODO(dcheng): This WebVector should hold smart pointers.
61 new blink::WebVector<blink::WebUSBDevice*>(results.size()); 63 std::unique_ptr<blink::WebVector<blink::WebUSBDevice*>> devices(
64 new blink::WebVector<blink::WebUSBDevice*>(results.size()));
62 for (size_t i = 0; i < results.size(); ++i) { 65 for (size_t i = 0; i < results.size(); ++i) {
63 device::usb::DevicePtr device; 66 device::usb::DevicePtr device;
64 device_manager->GetDevice(results[i]->guid, mojo::GetProxy(&device)); 67 device_manager->GetDevice(results[i]->guid, mojo::GetProxy(&device));
65 (*devices)[i] = new WebUSBDeviceImpl( 68 (*devices)[i] = new WebUSBDeviceImpl(
66 std::move(device), 69 std::move(device),
67 mojo::ConvertTo<blink::WebUSBDeviceInfo>(results[i])); 70 mojo::ConvertTo<blink::WebUSBDeviceInfo>(results[i]));
68 } 71 }
69 scoped_callbacks.PassCallbacks()->onSuccess(blink::adoptWebPtr(devices)); 72 scoped_callbacks.PassCallbacks()->onSuccess(std::move(devices));
70 } 73 }
71 74
72 void OnRequestDevicesComplete( 75 void OnRequestDevicesComplete(
73 ScopedWebCallbacks<blink::WebUSBClientRequestDeviceCallbacks> callbacks, 76 ScopedWebCallbacks<blink::WebUSBClientRequestDeviceCallbacks> callbacks,
74 device::usb::DeviceManager* device_manager, 77 device::usb::DeviceManager* device_manager,
75 device::usb::DeviceInfoPtr result) { 78 device::usb::DeviceInfoPtr result) {
76 auto scoped_callbacks = callbacks.PassCallbacks(); 79 auto scoped_callbacks = callbacks.PassCallbacks();
77 if (result) { 80 if (result) {
78 device::usb::DevicePtr device; 81 device::usb::DevicePtr device;
79 device_manager->GetDevice(result->guid, mojo::GetProxy(&device)); 82 device_manager->GetDevice(result->guid, mojo::GetProxy(&device));
80 blink::WebUSBDevice* web_usb_device = new WebUSBDeviceImpl( 83 std::unique_ptr<blink::WebUSBDevice> web_usb_device(new WebUSBDeviceImpl(
81 std::move(device), mojo::ConvertTo<blink::WebUSBDeviceInfo>(result)); 84 std::move(device), mojo::ConvertTo<blink::WebUSBDeviceInfo>(result)));
82 85
83 scoped_callbacks->onSuccess(blink::adoptWebPtr(web_usb_device)); 86 scoped_callbacks->onSuccess(std::move(web_usb_device));
84 } else { 87 } else {
85 scoped_callbacks->onError( 88 scoped_callbacks->onError(
86 blink::WebUSBError(blink::WebUSBError::Error::NotFound, 89 blink::WebUSBError(blink::WebUSBError::Error::NotFound,
87 base::ASCIIToUTF16("No device selected."))); 90 base::ASCIIToUTF16("No device selected.")));
88 } 91 }
89 } 92 }
90 93
91 } // namespace 94 } // namespace
92 95
93 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry) 96 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return; 156 return;
154 157
155 device_manager_->GetDeviceChanges(base::Bind( 158 device_manager_->GetDeviceChanges(base::Bind(
156 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this))); 159 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
157 for (size_t i = 0; i < notification->devices_added.size(); ++i) { 160 for (size_t i = 0; i < notification->devices_added.size(); ++i) {
158 const device::usb::DeviceInfoPtr& device_info = 161 const device::usb::DeviceInfoPtr& device_info =
159 notification->devices_added[i]; 162 notification->devices_added[i];
160 for (auto observer : observers_) { 163 for (auto observer : observers_) {
161 device::usb::DevicePtr device; 164 device::usb::DevicePtr device;
162 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); 165 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device));
163 observer->onDeviceConnected(blink::adoptWebPtr(new WebUSBDeviceImpl( 166 observer->onDeviceConnected(base::WrapUnique(new WebUSBDeviceImpl(
164 std::move(device), 167 std::move(device),
165 mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); 168 mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info))));
166 } 169 }
167 } 170 }
168 for (size_t i = 0; i < notification->devices_removed.size(); ++i) { 171 for (size_t i = 0; i < notification->devices_removed.size(); ++i) {
169 const device::usb::DeviceInfoPtr& device_info = 172 const device::usb::DeviceInfoPtr& device_info =
170 notification->devices_removed[i]; 173 notification->devices_removed[i];
171 for (auto observer : observers_) 174 for (auto observer : observers_)
172 observer->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( 175 observer->onDeviceDisconnected(base::WrapUnique(new WebUSBDeviceImpl(
173 nullptr, mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); 176 nullptr, mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info))));
174 } 177 }
175 } 178 }
176 179
177 } // namespace content 180 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.cc ('k') | content/renderer/usb/web_usb_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698