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

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

Issue 2478013002: bluetooth: Invalidate services upon disconnection (Closed)
Patch Set: Clean up Created 4 years, 1 month 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 27 matching lines...) Expand all
38 std::move(webDevice)); 38 std::move(webDevice));
39 } 39 }
40 40
41 BluetoothRemoteGATTService* 41 BluetoothRemoteGATTService*
42 BluetoothDevice::getOrCreateBluetoothRemoteGATTService( 42 BluetoothDevice::getOrCreateBluetoothRemoteGATTService(
43 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { 43 std::unique_ptr<WebBluetoothRemoteGATTService> webService) {
44 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService( 44 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService(
45 std::move(webService)); 45 std::move(webService));
46 } 46 }
47 47
48 bool BluetoothDevice::isValidService(const String& serviceInstanceId) {
49 return m_attributeInstanceMap->containsService(serviceInstanceId);
50 }
51
48 void BluetoothDevice::dispose() { 52 void BluetoothDevice::dispose() {
49 disconnectGATTIfConnected(); 53 disconnectGATTIfConnected();
50 } 54 }
51 55
52 void BluetoothDevice::contextDestroyed() { 56 void BluetoothDevice::contextDestroyed() {
53 disconnectGATTIfConnected(); 57 disconnectGATTIfConnected();
54 } 58 }
55 59
56 bool BluetoothDevice::disconnectGATTIfConnected() { 60 bool BluetoothDevice::disconnectGATTIfConnected() {
57 if (m_gatt->connected()) { 61 if (m_gatt->connected()) {
58 m_gatt->setConnected(false); 62 m_gatt->setConnected(false);
59 m_gatt->ClearActiveAlgorithms(); 63 m_gatt->ClearActiveAlgorithms();
60 BluetoothSupplement::fromExecutionContext(getExecutionContext()) 64 BluetoothSupplement::fromExecutionContext(getExecutionContext())
61 ->disconnect(id()); 65 ->disconnect(id());
62 return true; 66 return true;
63 } 67 }
64 return false; 68 return false;
65 } 69 }
66 70
71 void BluetoothDevice::CleanupDisconnectedDeviceAndFireEvent() {
72 m_gatt->setConnected(false);
scheib 2016/11/04 22:53:50 Here can we either if (connected), or DCHECK(conne
ortuno 2016/11/06 22:44:12 Done.
73 m_gatt->ClearActiveAlgorithms();
74 m_attributeInstanceMap->Clear();
75 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected));
76 }
77
67 const WTF::AtomicString& BluetoothDevice::interfaceName() const { 78 const WTF::AtomicString& BluetoothDevice::interfaceName() const {
68 return EventTargetNames::BluetoothDevice; 79 return EventTargetNames::BluetoothDevice;
69 } 80 }
70 81
71 ExecutionContext* BluetoothDevice::getExecutionContext() const { 82 ExecutionContext* BluetoothDevice::getExecutionContext() const {
72 return ContextLifecycleObserver::getExecutionContext(); 83 return ContextLifecycleObserver::getExecutionContext();
73 } 84 }
74 85
75 void BluetoothDevice::dispatchGattServerDisconnected() { 86 void BluetoothDevice::dispatchGattServerDisconnected() {
76 if (m_gatt->connected()) { 87 if (!m_gatt->connected()) {
77 m_gatt->setConnected(false); 88 return;
78 m_gatt->ClearActiveAlgorithms();
79 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected));
80 } 89 }
90 CleanupDisconnectedDeviceAndFireEvent();
81 } 91 }
82 92
83 DEFINE_TRACE(BluetoothDevice) { 93 DEFINE_TRACE(BluetoothDevice) {
84 EventTargetWithInlineData::trace(visitor); 94 EventTargetWithInlineData::trace(visitor);
85 ContextLifecycleObserver::trace(visitor); 95 ContextLifecycleObserver::trace(visitor);
86 visitor->trace(m_attributeInstanceMap); 96 visitor->trace(m_attributeInstanceMap);
87 visitor->trace(m_gatt); 97 visitor->trace(m_gatt);
88 } 98 }
89 99
90 } // namespace blink 100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698