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

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h

Issue 1611773002: bluetooth: Disconnect if the page becomes hidden or is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address haraken's comments Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h
index 5cad45982a6563fe2fce9cc1e2a4eee7f3fc7800..87e6504071350cb428b0bf6e429e5f344b41c5f5 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.h
@@ -7,6 +7,8 @@
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/modules/v8/UnionTypesModules.h"
+#include "core/dom/ActiveDOMObject.h"
+#include "core/page/PageLifecycleObserver.h"
#include "platform/heap/Heap.h"
#include "public/platform/modules/bluetooth/WebBluetoothGATTRemoteServer.h"
#include "wtf/OwnPtr.h"
@@ -27,17 +29,48 @@ class ScriptState;
// CallbackPromiseAdapter class comments.
class BluetoothGATTRemoteServer final
: public GarbageCollectedFinalized<BluetoothGATTRemoteServer>
+ , public ActiveDOMObject
+ , public PageLifecycleObserver
, public ScriptWrappable {
+ USING_PRE_FINALIZER(BluetoothGATTRemoteServer, dispose);
DEFINE_WRAPPERTYPEINFO();
+ WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BluetoothGATTRemoteServer);
public:
- BluetoothGATTRemoteServer(PassOwnPtr<WebBluetoothGATTRemoteServer>);
+ BluetoothGATTRemoteServer(ExecutionContext*, PassOwnPtr<WebBluetoothGATTRemoteServer>);
// Interface required by CallbackPromiseAdapter:
using WebType = OwnPtr<WebBluetoothGATTRemoteServer>;
static BluetoothGATTRemoteServer* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTRemoteServer>);
+ // We should disconnect from the device in all of the following cases:
+ // 1. When the object gets GarbageCollected e.g. it went out of scope.
+ // dispose() is called in this case.
+ // 2. When the parent document gets detached e.g. reloading a page.
+ // stop() is called in this case.
+ // 3. For now (https://crbug.com/579746), when the tab is no longer in the
+ // foreground e.g. change tabs.
+ // pageVisibilityChanged() is called in this case.
+ // TODO(ortuno): Users should be able to turn on notifications listen for
+ // events on navigator.bluetooth and still remain connected even if the
+ // BluetoothGATTRemoteServer object is garbage collected.
+ // TODO(ortuno): Allow connections when the tab is in the background.
+ // This is a short term solution instead of implementing a tab indicator
+ // for bluetooth connections.
+
+ // USING_PRE_FINALIZER interface.
+ // Called before the object gets garbage collected.
+ void dispose();
+
+ // ActiveDOMObject interface.
+ void stop() override;
+
+ // PageLifecycleObserver interface.
+ void pageVisibilityChanged() override;
+
+ void disconnectIfConnected();
+
// Interface required by Garbage Collectoin:
- DEFINE_INLINE_TRACE() { }
+ DECLARE_VIRTUAL_TRACE();
// IDL exposed interface:
bool connected() { return m_webGATT->connected; }

Powered by Google App Engine
This is Rietveld 408576698