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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp

Issue 2771893002: Move Bluetooth.Web.FunctionCall.Count UMA from browser to WebKit (Closed)
Patch Set: move Bluetooth.Web.FunctionCall.Count UMA from browser to WebKit Created 3 years, 9 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/bluetooth/Bluetooth.h" 5 #include "modules/bluetooth/Bluetooth.h"
6 6
7 #include <memory>
8 #include <utility>
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 9 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 11 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 12 #include "core/dom/DOMException.h"
11 #include "core/dom/Document.h" 13 #include "core/dom/Document.h"
12 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
13 #include "core/dom/ExecutionContext.h" 15 #include "core/dom/ExecutionContext.h"
14 #include "core/frame/LocalFrame.h" 16 #include "core/frame/LocalFrame.h"
15 #include "modules/bluetooth/BluetoothDevice.h" 17 #include "modules/bluetooth/BluetoothDevice.h"
16 #include "modules/bluetooth/BluetoothError.h" 18 #include "modules/bluetooth/BluetoothError.h"
19 #include "modules/bluetooth/BluetoothMetrics.h"
17 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" 20 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h"
18 #include "modules/bluetooth/BluetoothUUID.h" 21 #include "modules/bluetooth/BluetoothUUID.h"
19 #include "modules/bluetooth/RequestDeviceOptions.h" 22 #include "modules/bluetooth/RequestDeviceOptions.h"
20 #include "platform/UserGestureIndicator.h" 23 #include "platform/UserGestureIndicator.h"
21 #include "public/platform/InterfaceProvider.h" 24 #include "public/platform/InterfaceProvider.h"
22 #include "public/platform/Platform.h" 25 #include "public/platform/Platform.h"
23 #include <memory>
24 #include <utility>
25 26
26 namespace blink { 27 namespace blink {
27 28
28 namespace { 29 namespace {
29 // Per the Bluetooth Spec: The name is a user-friendly name associated with the 30 // Per the Bluetooth Spec: The name is a user-friendly name associated with the
30 // device and consists of a maximum of 248 bytes coded according to the UTF-8 31 // device and consists of a maximum of 248 bytes coded according to the UTF-8
31 // standard. 32 // standard.
32 const size_t kMaxDeviceNameLength = 248; 33 const size_t kMaxDeviceNameLength = 248;
33 const char kDeviceNameTooLong[] = 34 const char kDeviceNameTooLong[] =
34 "A device name can't be longer than 248 bytes."; 35 "A device name can't be longer than 248 bytes.";
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 resolver->resolve(bluetoothDevice); 152 resolver->resolve(bluetoothDevice);
152 } else { 153 } else {
153 resolver->reject(BluetoothError::CreateDOMException(result)); 154 resolver->reject(BluetoothError::CreateDOMException(result));
154 } 155 }
155 } 156 }
156 157
157 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice 158 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
158 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, 159 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState,
159 const RequestDeviceOptions& options, 160 const RequestDeviceOptions& options,
160 ExceptionState& exceptionState) { 161 ExceptionState& exceptionState) {
162 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
163
161 ExecutionContext* context = scriptState->getExecutionContext(); 164 ExecutionContext* context = scriptState->getExecutionContext();
162 165
163 // If the incumbent settings object is not a secure context, reject promise 166 // If the incumbent settings object is not a secure context, reject promise
164 // with a SecurityError and abort these steps. 167 // with a SecurityError and abort these steps.
165 String errorMessage; 168 String errorMessage;
166 if (!context->isSecureContext(errorMessage)) { 169 if (!context->isSecureContext(errorMessage)) {
167 return ScriptPromise::rejectWithDOMException( 170 return ScriptPromise::rejectWithDOMException(
168 scriptState, DOMException::create(SecurityError, errorMessage)); 171 scriptState, DOMException::create(SecurityError, errorMessage));
169 } 172 }
170 173
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 BluetoothDevice* device = m_deviceInstanceMap.at(id); 287 BluetoothDevice* device = m_deviceInstanceMap.at(id);
285 if (!device) { 288 if (!device) {
286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); 289 device = BluetoothDevice::take(resolver, std::move(devicePtr), this);
287 auto result = m_deviceInstanceMap.insert(id, device); 290 auto result = m_deviceInstanceMap.insert(id, device);
288 DCHECK(result.isNewEntry); 291 DCHECK(result.isNewEntry);
289 } 292 }
290 return device; 293 return device;
291 } 294 }
292 295
293 } // namespace blink 296 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698