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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webusb/USB.cpp
diff --git a/third_party/WebKit/Source/modules/webusb/USB.cpp b/third_party/WebKit/Source/modules/webusb/USB.cpp
index 8882221fd6e54b98e95f2c723043a10df17eb703..f031a0e67df43a78f5815f70d9f3ab7c6a4a3b72 100644
--- a/third_party/WebKit/Source/modules/webusb/USB.cpp
+++ b/third_party/WebKit/Source/modules/webusb/USB.cpp
@@ -9,6 +9,7 @@
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/frame/UseCounter.h"
#include "device/usb/public/interfaces/device.mojom-blink.h"
#include "modules/EventTargetModules.h"
#include "modules/webusb/USBConnectionEvent.h"
@@ -78,13 +79,16 @@ void USB::dispose()
ScriptPromise USB::getDevices(ScriptState* scriptState)
{
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ UseCounter::count(executionContext, UseCounter::UsbGetDevices);
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
if (!m_deviceManager) {
resolver->reject(DOMException::create(NotSupportedError));
} else {
String errorMessage;
- if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) {
+ if (!executionContext->isSecureContext(errorMessage)) {
resolver->reject(DOMException::create(SecurityError, errorMessage));
} else {
m_deviceManagerRequests.add(resolver);
@@ -96,11 +100,14 @@ ScriptPromise USB::getDevices(ScriptState* scriptState)
ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceRequestOptions& options)
{
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ UseCounter::count(executionContext, UseCounter::UsbRequestDevice);
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
if (!m_chooserService) {
- LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionContext())->frame() : nullptr;
+ LocalFrame* frame = executionContext->isDocument() ? toDocument(executionContext)->frame() : nullptr;
if (!frame) {
resolver->reject(DOMException::create(NotSupportedError));
return promise;
@@ -110,7 +117,7 @@ ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques
}
String errorMessage;
- if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) {
+ if (!executionContext->isSecureContext(errorMessage)) {
resolver->reject(DOMException::create(SecurityError, errorMessage));
} else if (!UserGestureIndicator::consumeUserGesture()) {
resolver->reject(DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request."));
« 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