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

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

Issue 2565913002: [Onion Soup] Move WebBluetoothImpl from //content/renderer/bluetooth to Blink's bluetooth module (Closed)
Patch Set: renamed BluetoothUUID.typemap to Bluetooth.typemap Created 3 years, 11 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 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 "modules/bluetooth/BluetoothDevice.h" 5 #include "modules/bluetooth/BluetoothDevice.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
11 #include "core/events/Event.h" 11 #include "core/events/Event.h"
12 #include "modules/bluetooth/Bluetooth.h"
12 #include "modules/bluetooth/BluetoothAttributeInstanceMap.h" 13 #include "modules/bluetooth/BluetoothAttributeInstanceMap.h"
13 #include "modules/bluetooth/BluetoothError.h" 14 #include "modules/bluetooth/BluetoothError.h"
14 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" 15 #include "modules/bluetooth/BluetoothRemoteGATTServer.h"
15 #include "modules/bluetooth/BluetoothSupplement.h"
16 #include "public/platform/modules/bluetooth/WebBluetooth.h"
17 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic Init.h"
18 #include <memory> 16 #include <memory>
19 #include <utility> 17 #include <utility>
20 18
21 namespace blink { 19 namespace blink {
22 20
23 BluetoothDevice::BluetoothDevice( 21 BluetoothDevice::BluetoothDevice(ExecutionContext* context,
24 ExecutionContext* context, 22 const String& id,
25 std::unique_ptr<WebBluetoothDeviceInit> webDevice) 23 const String& name,
24 Bluetooth* bluetooth)
26 : ContextLifecycleObserver(context), 25 : ContextLifecycleObserver(context),
27 m_attributeInstanceMap(new BluetoothAttributeInstanceMap(this)), 26 m_attributeInstanceMap(new BluetoothAttributeInstanceMap(this)),
28 m_webDevice(std::move(webDevice)), 27 m_id(id),
29 m_gatt(BluetoothRemoteGATTServer::create(this)) { 28 m_name(name),
29 m_gatt(BluetoothRemoteGATTServer::create(this)),
30 m_bluetooth(bluetooth) {}
31
32 // static
33 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver,
34 const String& id,
35 const String& name,
36 Bluetooth* bluetooth) {
37 return new BluetoothDevice(resolver->getExecutionContext(), id, name,
38 bluetooth);
30 } 39 }
31 40
32 BluetoothDevice* BluetoothDevice::take( 41 // static
33 ScriptPromiseResolver* resolver, 42 mojom::blink::WebBluetoothDeviceIdPtr BluetoothDevice::createMojoDeviceId(
34 std::unique_ptr<WebBluetoothDeviceInit> webDevice) { 43 const String& deviceId) {
35 ASSERT(webDevice); 44 auto result = mojom::blink::WebBluetoothDeviceId::New();
36 return new BluetoothDevice(resolver->getExecutionContext(), 45 result->device_id = deviceId;
37 std::move(webDevice)); 46 return result;
38 } 47 }
39 48
40 BluetoothRemoteGATTService* 49 BluetoothRemoteGATTService*
41 BluetoothDevice::getOrCreateBluetoothRemoteGATTService( 50 BluetoothDevice::getOrCreateBluetoothRemoteGATTService(
42 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { 51 const String& serviceInstanceId,
52 const String& uuid,
53 bool isPrimary,
54 const String& deviceInstanceId) {
43 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService( 55 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService(
44 std::move(webService)); 56 serviceInstanceId, uuid, isPrimary, deviceInstanceId);
45 } 57 }
46 58
47 bool BluetoothDevice::isValidService(const String& serviceInstanceId) { 59 bool BluetoothDevice::isValidService(const String& serviceInstanceId) {
48 return m_attributeInstanceMap->containsService(serviceInstanceId); 60 return m_attributeInstanceMap->containsService(serviceInstanceId);
49 } 61 }
50 62
51 BluetoothRemoteGATTCharacteristic* 63 BluetoothRemoteGATTCharacteristic*
52 BluetoothDevice::getOrCreateBluetoothRemoteGATTCharacteristic( 64 BluetoothDevice::getOrCreateBluetoothRemoteGATTCharacteristic(
53 ExecutionContext* context, 65 ExecutionContext* context,
54 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, 66 const String& characteristicInstanceId,
67 const String& serviceInstanceId,
68 const String& uuid,
69 uint32_t characteristicProperties,
55 BluetoothRemoteGATTService* service) { 70 BluetoothRemoteGATTService* service) {
56 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTCharacteristic( 71 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTCharacteristic(
57 context, std::move(webCharacteristic), service); 72 context, characteristicInstanceId, serviceInstanceId, uuid,
73 characteristicProperties, service);
58 } 74 }
59 75
60 bool BluetoothDevice::isValidCharacteristic( 76 bool BluetoothDevice::isValidCharacteristic(
61 const String& characteristicInstanceId) { 77 const String& characteristicInstanceId) {
62 return m_attributeInstanceMap->containsCharacteristic( 78 return m_attributeInstanceMap->containsCharacteristic(
63 characteristicInstanceId); 79 characteristicInstanceId);
64 } 80 }
65 81
66 void BluetoothDevice::dispose() { 82 void BluetoothDevice::dispose() {
67 disconnectGATTIfConnected(); 83 disconnectGATTIfConnected();
68 } 84 }
69 85
70 void BluetoothDevice::contextDestroyed() { 86 void BluetoothDevice::contextDestroyed() {
71 disconnectGATTIfConnected(); 87 disconnectGATTIfConnected();
72 } 88 }
73 89
74 void BluetoothDevice::disconnectGATTIfConnected() { 90 void BluetoothDevice::disconnectGATTIfConnected() {
75 if (m_gatt->connected()) { 91 if (m_gatt->connected()) {
76 m_gatt->setConnected(false); 92 m_gatt->setConnected(false);
77 m_gatt->ClearActiveAlgorithms(); 93 m_gatt->ClearActiveAlgorithms();
78 BluetoothSupplement::fromExecutionContext(getExecutionContext()) 94 m_bluetooth->removeDevice(id());
79 ->disconnect(id()); 95 mojom::blink::WebBluetoothService* service = m_bluetooth->service();
96 auto deviceId = mojom::blink::WebBluetoothDeviceId::New();
97 deviceId->device_id = id();
98 service->RemoteServerDisconnect(std::move(deviceId));
80 } 99 }
81 } 100 }
82 101
83 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() { 102 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() {
84 DCHECK(m_gatt->connected()); 103 DCHECK(m_gatt->connected());
85 m_gatt->setConnected(false); 104 m_gatt->setConnected(false);
86 m_gatt->ClearActiveAlgorithms(); 105 m_gatt->ClearActiveAlgorithms();
87 m_attributeInstanceMap->Clear(); 106 m_attributeInstanceMap->Clear();
88 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected)); 107 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected));
89 } 108 }
(...skipping 11 matching lines...) Expand all
101 return; 120 return;
102 } 121 }
103 cleanupDisconnectedDeviceAndFireEvent(); 122 cleanupDisconnectedDeviceAndFireEvent();
104 } 123 }
105 124
106 DEFINE_TRACE(BluetoothDevice) { 125 DEFINE_TRACE(BluetoothDevice) {
107 EventTargetWithInlineData::trace(visitor); 126 EventTargetWithInlineData::trace(visitor);
108 ContextLifecycleObserver::trace(visitor); 127 ContextLifecycleObserver::trace(visitor);
109 visitor->trace(m_attributeInstanceMap); 128 visitor->trace(m_attributeInstanceMap);
110 visitor->trace(m_gatt); 129 visitor->trace(m_gatt);
130 visitor->trace(m_bluetooth);
111 } 131 }
112 132
113 } // namespace blink 133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698