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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address comments 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 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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, 68 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor,
69 BluetoothRemoteGATTCharacteristic* characteristic) { 69 BluetoothRemoteGATTCharacteristic* characteristic) {
70 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTDescriptor( 70 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTDescriptor(
71 std::move(descriptor), characteristic); 71 std::move(descriptor), characteristic);
72 } 72 }
73 73
74 bool BluetoothDevice::isValidDescriptor(const String& descriptorInstanceId) { 74 bool BluetoothDevice::isValidDescriptor(const String& descriptorInstanceId) {
75 return m_attributeInstanceMap->containsDescriptor(descriptorInstanceId); 75 return m_attributeInstanceMap->containsDescriptor(descriptorInstanceId);
76 } 76 }
77 77
78 void BluetoothDevice::dispose() { 78 void BluetoothDevice::dispose() {
ortuno 2017/03/01 04:52:06 Let's just do both on BluetoothRemoteGATTServer.
juncai 2017/03/02 03:23:47 Done.
ortuno 2017/03/06 11:31:20 Also add contextDestroyed to BluetoothRemoteGATTSe
juncai 2017/03/09 07:30:57 Done.
79 disconnectGATTIfConnected(); 79 m_gatt->disconnectIfConnected();
80 } 80 }
81 81
82 void BluetoothDevice::contextDestroyed(ExecutionContext*) { 82 void BluetoothDevice::contextDestroyed(ExecutionContext*) {
83 disconnectGATTIfConnected(); 83 m_gatt->disconnectIfConnected();
84 } 84 }
85 85
86 void BluetoothDevice::disconnectGATTIfConnected() { 86 void BluetoothDevice::clearAttributeInstanceMapAndFireEvent() {
87 if (m_gatt->connected()) {
88 m_gatt->setConnected(false);
89 m_gatt->ClearActiveAlgorithms();
90 m_bluetooth->removeFromConnectedDevicesMap(id());
91 mojom::blink::WebBluetoothService* service = m_bluetooth->service();
92 service->RemoteServerDisconnect(id());
93 }
94 }
95
96 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() {
97 DCHECK(m_gatt->connected());
98 m_gatt->setConnected(false);
99 m_gatt->ClearActiveAlgorithms();
100 m_attributeInstanceMap->Clear(); 87 m_attributeInstanceMap->Clear();
101 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected)); 88 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected));
102 } 89 }
103 90
104 const WTF::AtomicString& BluetoothDevice::interfaceName() const { 91 const WTF::AtomicString& BluetoothDevice::interfaceName() const {
105 return EventTargetNames::BluetoothDevice; 92 return EventTargetNames::BluetoothDevice;
106 } 93 }
107 94
108 ExecutionContext* BluetoothDevice::getExecutionContext() const { 95 ExecutionContext* BluetoothDevice::getExecutionContext() const {
109 return ContextLifecycleObserver::getExecutionContext(); 96 return ContextLifecycleObserver::getExecutionContext();
110 } 97 }
111 98
112 void BluetoothDevice::dispatchGattServerDisconnected() {
113 if (!m_gatt->connected()) {
114 return;
115 }
116 cleanupDisconnectedDeviceAndFireEvent();
117 }
118
119 DEFINE_TRACE(BluetoothDevice) { 99 DEFINE_TRACE(BluetoothDevice) {
120 visitor->trace(m_attributeInstanceMap); 100 visitor->trace(m_attributeInstanceMap);
121 visitor->trace(m_gatt); 101 visitor->trace(m_gatt);
122 visitor->trace(m_bluetooth); 102 visitor->trace(m_bluetooth);
123 EventTargetWithInlineData::trace(visitor); 103 EventTargetWithInlineData::trace(visitor);
124 ContextLifecycleObserver::trace(visitor); 104 ContextLifecycleObserver::trace(visitor);
125 } 105 }
126 106
127 } // namespace blink 107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698