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

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: fixed layout tests Created 4 years 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/web_bluetooth.mojom-blink.h"
16 #include "public/platform/modules/bluetooth/WebBluetooth.h"
17 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic Init.h"
18 #include <memory> 17 #include <memory>
19 #include <utility> 18 #include <utility>
20 19
21 namespace blink { 20 namespace blink {
22 21
23 BluetoothDevice::BluetoothDevice( 22 BluetoothDevice::BluetoothDevice(ExecutionContext* context,
24 ExecutionContext* context, 23 const String& id,
25 std::unique_ptr<WebBluetoothDeviceInit> webDevice) 24 const String& name,
25 Bluetooth* bluetooth)
26 : ContextLifecycleObserver(context), 26 : ContextLifecycleObserver(context),
27 m_attributeInstanceMap(new BluetoothAttributeInstanceMap(this)), 27 m_attributeInstanceMap(new BluetoothAttributeInstanceMap(this)),
28 m_webDevice(std::move(webDevice)), 28 m_id(id),
29 m_gatt(BluetoothRemoteGATTServer::create(this)) { 29 m_name(name),
30 } 30 m_gatt(BluetoothRemoteGATTServer::create(this)),
31 m_bluetooth(bluetooth) {}
31 32
32 BluetoothDevice* BluetoothDevice::take( 33 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver,
33 ScriptPromiseResolver* resolver, 34 const String& id,
34 std::unique_ptr<WebBluetoothDeviceInit> webDevice) { 35 const String& name,
35 ASSERT(webDevice); 36 Bluetooth* bluetooth) {
36 return new BluetoothDevice(resolver->getExecutionContext(), 37 return new BluetoothDevice(resolver->getExecutionContext(), id, name,
37 std::move(webDevice)); 38 bluetooth);
38 } 39 }
39 40
40 BluetoothRemoteGATTService* 41 BluetoothRemoteGATTService*
41 BluetoothDevice::getOrCreateBluetoothRemoteGATTService( 42 BluetoothDevice::getOrCreateBluetoothRemoteGATTService(
42 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { 43 const String& serviceInstanceId,
44 const String& uuid,
45 bool isPrimary,
46 const String& deviceInstanceId) {
43 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService( 47 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService(
44 std::move(webService)); 48 serviceInstanceId, uuid, isPrimary, deviceInstanceId);
45 } 49 }
46 50
47 bool BluetoothDevice::isValidService(const String& serviceInstanceId) { 51 bool BluetoothDevice::isValidService(const String& serviceInstanceId) {
48 return m_attributeInstanceMap->containsService(serviceInstanceId); 52 return m_attributeInstanceMap->containsService(serviceInstanceId);
49 } 53 }
50 54
51 BluetoothRemoteGATTCharacteristic* 55 BluetoothRemoteGATTCharacteristic*
52 BluetoothDevice::getOrCreateBluetoothRemoteGATTCharacteristic( 56 BluetoothDevice::getOrCreateBluetoothRemoteGATTCharacteristic(
53 ExecutionContext* context, 57 ExecutionContext* context,
54 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, 58 const String& characteristicInstanceId,
59 const String& serviceInstanceId,
60 const String& uuid,
61 uint32_t characteristicProperties,
55 BluetoothRemoteGATTService* service) { 62 BluetoothRemoteGATTService* service) {
56 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTCharacteristic( 63 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTCharacteristic(
57 context, std::move(webCharacteristic), service); 64 context, characteristicInstanceId, serviceInstanceId, uuid,
65 characteristicProperties, service);
58 } 66 }
59 67
60 bool BluetoothDevice::isValidCharacteristic( 68 bool BluetoothDevice::isValidCharacteristic(
61 const String& characteristicInstanceId) { 69 const String& characteristicInstanceId) {
62 return m_attributeInstanceMap->containsCharacteristic( 70 return m_attributeInstanceMap->containsCharacteristic(
63 characteristicInstanceId); 71 characteristicInstanceId);
64 } 72 }
65 73
66 void BluetoothDevice::dispose() { 74 void BluetoothDevice::dispose() {
67 disconnectGATTIfConnected(); 75 disconnectGATTIfConnected();
68 } 76 }
69 77
70 void BluetoothDevice::contextDestroyed() { 78 void BluetoothDevice::contextDestroyed() {
71 disconnectGATTIfConnected(); 79 disconnectGATTIfConnected();
72 } 80 }
73 81
74 void BluetoothDevice::disconnectGATTIfConnected() { 82 void BluetoothDevice::disconnectGATTIfConnected() {
75 if (m_gatt->connected()) { 83 if (m_gatt->connected()) {
76 m_gatt->setConnected(false); 84 m_gatt->setConnected(false);
77 m_gatt->ClearActiveAlgorithms(); 85 m_gatt->ClearActiveAlgorithms();
78 BluetoothSupplement::fromExecutionContext(getExecutionContext()) 86 m_bluetooth->removeDevice(id());
79 ->disconnect(id()); 87 mojom::blink::WebBluetoothService* service = m_bluetooth->service();
88 mojom::blink::WebBluetoothDeviceIdPtr deviceIdPtr =
89 mojom::blink::WebBluetoothDeviceId::New();
Reilly Grant (use Gerrit) 2016/12/16 01:41:29 auto deviceId = mojom::blink::WebBluetoothDeviceId
juncai 2016/12/17 01:18:52 Done.
90 deviceIdPtr->device_id = id();
91 service->RemoteServerDisconnect(std::move(deviceIdPtr));
80 } 92 }
81 } 93 }
82 94
83 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() { 95 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() {
84 DCHECK(m_gatt->connected()); 96 DCHECK(m_gatt->connected());
85 m_gatt->setConnected(false); 97 m_gatt->setConnected(false);
86 m_gatt->ClearActiveAlgorithms(); 98 m_gatt->ClearActiveAlgorithms();
87 m_attributeInstanceMap->Clear(); 99 m_attributeInstanceMap->Clear();
88 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected)); 100 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected));
89 } 101 }
(...skipping 11 matching lines...) Expand all
101 return; 113 return;
102 } 114 }
103 cleanupDisconnectedDeviceAndFireEvent(); 115 cleanupDisconnectedDeviceAndFireEvent();
104 } 116 }
105 117
106 DEFINE_TRACE(BluetoothDevice) { 118 DEFINE_TRACE(BluetoothDevice) {
107 EventTargetWithInlineData::trace(visitor); 119 EventTargetWithInlineData::trace(visitor);
108 ContextLifecycleObserver::trace(visitor); 120 ContextLifecycleObserver::trace(visitor);
109 visitor->trace(m_attributeInstanceMap); 121 visitor->trace(m_attributeInstanceMap);
110 visitor->trace(m_gatt); 122 visitor->trace(m_gatt);
123 visitor->trace(m_bluetooth);
111 } 124 }
112 125
113 } // namespace blink 126 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698