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

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

Issue 2362173002: Clear Document::m_frame after dispatching ContextLifecycleObesrver::contextDestroyed (Closed)
Patch Set: temp Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/BluetoothError.h" 12 #include "modules/bluetooth/BluetoothError.h"
13 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" 13 #include "modules/bluetooth/BluetoothRemoteGATTServer.h"
14 #include "modules/bluetooth/BluetoothSupplement.h" 14 #include "modules/bluetooth/BluetoothSupplement.h"
15 #include "public/platform/modules/bluetooth/WebBluetooth.h" 15 #include "public/platform/modules/bluetooth/WebBluetooth.h"
16 #include <memory> 16 #include <memory>
17 17
18 namespace blink { 18 namespace blink {
19 19
20 BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebB luetoothDeviceInit> webDevice) 20 BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebB luetoothDeviceInit> webDevice)
21 : ActiveDOMObject(context) 21 : ContextLifecycleObserver(context)
22 , m_webDevice(std::move(webDevice)) 22 , m_webDevice(std::move(webDevice))
23 , m_gatt(BluetoothRemoteGATTServer::create(this)) 23 , m_gatt(BluetoothRemoteGATTServer::create(this))
24 { 24 {
25 // See example in Source/platform/heap/ThreadState.h 25 // See example in Source/platform/heap/ThreadState.h
26 ThreadState::current()->registerPreFinalizer(this); 26 ThreadState::current()->registerPreFinalizer(this);
27 } 27 }
28 28
29 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, std::uni que_ptr<WebBluetoothDeviceInit> webDevice) 29 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, std::uni que_ptr<WebBluetoothDeviceInit> webDevice)
30 { 30 {
31 ASSERT(webDevice); 31 ASSERT(webDevice);
32 BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext( ), std::move(webDevice)); 32 return new BluetoothDevice(resolver->getExecutionContext(), std::move(webDev ice));
33 device->suspendIfNeeded();
34 return device;
35 } 33 }
36 34
37 void BluetoothDevice::dispose() 35 void BluetoothDevice::dispose()
38 { 36 {
39 disconnectGATTIfConnected(); 37 disconnectGATTIfConnected();
40 } 38 }
41 39
42 void BluetoothDevice::stop() 40 void BluetoothDevice::contextDestroyed()
43 { 41 {
44 disconnectGATTIfConnected(); 42 disconnectGATTIfConnected();
45 } 43 }
46 44
47 bool BluetoothDevice::disconnectGATTIfConnected() 45 bool BluetoothDevice::disconnectGATTIfConnected()
48 { 46 {
49 if (m_gatt->connected()) { 47 if (m_gatt->connected()) {
50 m_gatt->setConnected(false); 48 m_gatt->setConnected(false);
51 m_gatt->ClearActiveAlgorithms(); 49 m_gatt->ClearActiveAlgorithms();
52 BluetoothSupplement::fromExecutionContext(getExecutionContext())->discon nect(id()); 50 BluetoothSupplement::fromExecutionContext(getExecutionContext())->discon nect(id());
53 return true; 51 return true;
54 } 52 }
55 return false; 53 return false;
56 } 54 }
57 55
58 const WTF::AtomicString& BluetoothDevice::interfaceName() const 56 const WTF::AtomicString& BluetoothDevice::interfaceName() const
59 { 57 {
60 return EventTargetNames::BluetoothDevice; 58 return EventTargetNames::BluetoothDevice;
61 } 59 }
62 60
63 ExecutionContext* BluetoothDevice::getExecutionContext() const 61 ExecutionContext* BluetoothDevice::getExecutionContext() const
64 { 62 {
65 return ActiveDOMObject::getExecutionContext(); 63 return ContextLifecycleObserver::getExecutionContext();
66 } 64 }
67 65
68 void BluetoothDevice::dispatchGattServerDisconnected() 66 void BluetoothDevice::dispatchGattServerDisconnected()
69 { 67 {
70 if (m_gatt->connected()) { 68 if (m_gatt->connected()) {
71 m_gatt->setConnected(false); 69 m_gatt->setConnected(false);
72 m_gatt->ClearActiveAlgorithms(); 70 m_gatt->ClearActiveAlgorithms();
73 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected )); 71 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected ));
74 } 72 }
75 } 73 }
76 74
77 DEFINE_TRACE(BluetoothDevice) 75 DEFINE_TRACE(BluetoothDevice)
78 { 76 {
79 EventTargetWithInlineData::trace(visitor); 77 EventTargetWithInlineData::trace(visitor);
80 ActiveDOMObject::trace(visitor); 78 ContextLifecycleObserver::trace(visitor);
81 visitor->trace(m_gatt); 79 visitor->trace(m_gatt);
82 } 80 }
83 81
84 Vector<String> BluetoothDevice::uuids() 82 Vector<String> BluetoothDevice::uuids()
85 { 83 {
86 Vector<String> uuids(m_webDevice->uuids.size()); 84 Vector<String> uuids(m_webDevice->uuids.size());
87 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) 85 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i)
88 uuids[i] = m_webDevice->uuids[i]; 86 uuids[i] = m_webDevice->uuids[i];
89 return uuids; 87 return uuids;
90 } 88 }
91 89
92 } // namespace blink 90 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698