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

Side by Side Diff: third_party/WebKit/Source/modules/webusb/USB.cpp

Issue 2272563003: Add an UMA histogram for WebUSB function calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 4 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 "modules/webusb/USB.h" 5 #include "modules/webusb/USB.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/frame/UseCounter.h"
12 #include "device/usb/public/interfaces/device.mojom-blink.h" 13 #include "device/usb/public/interfaces/device.mojom-blink.h"
13 #include "modules/EventTargetModules.h" 14 #include "modules/EventTargetModules.h"
14 #include "modules/webusb/USBConnectionEvent.h" 15 #include "modules/webusb/USBConnectionEvent.h"
15 #include "modules/webusb/USBDevice.h" 16 #include "modules/webusb/USBDevice.h"
16 #include "modules/webusb/USBDeviceFilter.h" 17 #include "modules/webusb/USBDeviceFilter.h"
17 #include "modules/webusb/USBDeviceRequestOptions.h" 18 #include "modules/webusb/USBDeviceRequestOptions.h"
18 #include "platform/UserGestureIndicator.h" 19 #include "platform/UserGestureIndicator.h"
19 #include "platform/mojo/MojoHelper.h" 20 #include "platform/mojo/MojoHelper.h"
20 #include "public/platform/InterfaceProvider.h" 21 #include "public/platform/InterfaceProvider.h"
21 #include "wtf/Functional.h" 22 #include "wtf/Functional.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 void USB::dispose() 73 void USB::dispose()
73 { 74 {
74 // The pipe to this object must be closed when is marked unreachable to 75 // The pipe to this object must be closed when is marked unreachable to
75 // prevent messages from being dispatched before lazy sweeping. 76 // prevent messages from being dispatched before lazy sweeping.
76 m_clientBinding.Close(); 77 m_clientBinding.Close();
77 } 78 }
78 79
79 ScriptPromise USB::getDevices(ScriptState* scriptState) 80 ScriptPromise USB::getDevices(ScriptState* scriptState)
80 { 81 {
82 ExecutionContext* executionContext = scriptState->getExecutionContext();
83 UseCounter::count(executionContext, UseCounter::UsbGetDevices);
84
81 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
82 ScriptPromise promise = resolver->promise(); 86 ScriptPromise promise = resolver->promise();
83 if (!m_deviceManager) { 87 if (!m_deviceManager) {
84 resolver->reject(DOMException::create(NotSupportedError)); 88 resolver->reject(DOMException::create(NotSupportedError));
85 } else { 89 } else {
86 String errorMessage; 90 String errorMessage;
87 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { 91 if (!executionContext->isSecureContext(errorMessage)) {
88 resolver->reject(DOMException::create(SecurityError, errorMessage)); 92 resolver->reject(DOMException::create(SecurityError, errorMessage));
89 } else { 93 } else {
90 m_deviceManagerRequests.add(resolver); 94 m_deviceManagerRequests.add(resolver);
91 m_deviceManager->GetDevices(nullptr, convertToBaseCallback(WTF::bind (&USB::onGetDevices, wrapPersistent(this), wrapPersistent(resolver)))); 95 m_deviceManager->GetDevices(nullptr, convertToBaseCallback(WTF::bind (&USB::onGetDevices, wrapPersistent(this), wrapPersistent(resolver))));
92 } 96 }
93 } 97 }
94 return promise; 98 return promise;
95 } 99 }
96 100
97 ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques tOptions& options) 101 ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques tOptions& options)
98 { 102 {
103 ExecutionContext* executionContext = scriptState->getExecutionContext();
104 UseCounter::count(executionContext, UseCounter::UsbRequestDevice);
105
99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 106 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
100 ScriptPromise promise = resolver->promise(); 107 ScriptPromise promise = resolver->promise();
101 108
102 if (!m_chooserService) { 109 if (!m_chooserService) {
103 LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionConte xt())->frame() : nullptr; 110 LocalFrame* frame = executionContext->isDocument() ? toDocument(executio nContext)->frame() : nullptr;
104 if (!frame) { 111 if (!frame) {
105 resolver->reject(DOMException::create(NotSupportedError)); 112 resolver->reject(DOMException::create(NotSupportedError));
106 return promise; 113 return promise;
107 } 114 }
108 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_chooserServic e)); 115 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_chooserServic e));
109 m_chooserService.set_connection_error_handler(convertToBaseCallback(WTF: :bind(&USB::onChooserServiceConnectionError, wrapWeakPersistent(this)))); 116 m_chooserService.set_connection_error_handler(convertToBaseCallback(WTF: :bind(&USB::onChooserServiceConnectionError, wrapWeakPersistent(this))));
110 } 117 }
111 118
112 String errorMessage; 119 String errorMessage;
113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { 120 if (!executionContext->isSecureContext(errorMessage)) {
114 resolver->reject(DOMException::create(SecurityError, errorMessage)); 121 resolver->reject(DOMException::create(SecurityError, errorMessage));
115 } else if (!UserGestureIndicator::consumeUserGesture()) { 122 } else if (!UserGestureIndicator::consumeUserGesture()) {
116 resolver->reject(DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request.")); 123 resolver->reject(DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request."));
117 } else { 124 } else {
118 Vector<usb::DeviceFilterPtr> filters; 125 Vector<usb::DeviceFilterPtr> filters;
119 if (options.hasFilters()) { 126 if (options.hasFilters()) {
120 filters.reserveCapacity(options.filters().size()); 127 filters.reserveCapacity(options.filters().size());
121 for (const auto& filter : options.filters()) 128 for (const auto& filter : options.filters())
122 filters.append(convertDeviceFilter(filter)); 129 filters.append(convertDeviceFilter(filter));
123 } 130 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DEFINE_TRACE(USB) 234 DEFINE_TRACE(USB)
228 { 235 {
229 EventTargetWithInlineData::trace(visitor); 236 EventTargetWithInlineData::trace(visitor);
230 ContextLifecycleObserver::trace(visitor); 237 ContextLifecycleObserver::trace(visitor);
231 visitor->trace(m_deviceManagerRequests); 238 visitor->trace(m_deviceManagerRequests);
232 visitor->trace(m_chooserServiceRequests); 239 visitor->trace(m_chooserServiceRequests);
233 visitor->trace(m_deviceCache); 240 visitor->trace(m_deviceCache);
234 } 241 }
235 242
236 } // namespace blink 243 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | third_party/WebKit/Source/modules/webusb/USBDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698