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

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

Issue 2565913002: [Onion Soup] Move WebBluetoothImpl from //content/renderer/bluetooth to Blink's bluetooth module (Closed)
Patch Set: renamed BluetoothUUID.typemap to Bluetooth.typemap Created 3 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 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 #ifndef BluetoothDevice_h 5 #ifndef BluetoothDevice_h
6 #define BluetoothDevice_h 6 #define BluetoothDevice_h
7 7
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "core/dom/ContextLifecycleObserver.h" 9 #include "core/dom/ContextLifecycleObserver.h"
10 #include "modules/EventTargetModules.h" 10 #include "modules/EventTargetModules.h"
11 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" 11 #include "modules/bluetooth/BluetoothRemoteGATTServer.h"
12 #include "platform/heap/Heap.h" 12 #include "platform/heap/Heap.h"
13 #include "public/platform/modules/bluetooth/WebBluetoothDevice.h" 13 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h"
14 #include "public/platform/modules/bluetooth/WebBluetoothDeviceInit.h"
15 #include "wtf/text/WTFString.h" 14 #include "wtf/text/WTFString.h"
16 #include <memory> 15 #include <memory>
17 16
18 namespace blink { 17 namespace blink {
19 18
19 class Bluetooth;
20 class BluetoothAttributeInstanceMap; 20 class BluetoothAttributeInstanceMap;
21 class BluetoothRemoteGATTCharacteristic; 21 class BluetoothRemoteGATTCharacteristic;
22 class BluetoothRemoteGATTServer; 22 class BluetoothRemoteGATTServer;
23 class BluetoothRemoteGATTService; 23 class BluetoothRemoteGATTService;
24 class ScriptPromiseResolver; 24 class ScriptPromiseResolver;
25 25
26 struct WebBluetoothRemoteGATTCharacteristicInit;
27 struct WebBluetoothRemoteGATTService;
28
29 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. 26 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL.
30 // 27 //
31 // Callbacks providing WebBluetoothDevice objects are handled by 28 // Callbacks providing WebBluetoothDevice objects are handled by
32 // CallbackPromiseAdapter templatized with this class. See this class's 29 // CallbackPromiseAdapter templatized with this class. See this class's
33 // "Interface required by CallbackPromiseAdapter" section and the 30 // "Interface required by CallbackPromiseAdapter" section and the
34 // CallbackPromiseAdapter class comments. 31 // CallbackPromiseAdapter class comments.
35 class BluetoothDevice final : public EventTargetWithInlineData, 32 class BluetoothDevice final : public EventTargetWithInlineData,
36 public ContextLifecycleObserver, 33 public ContextLifecycleObserver {
37 public WebBluetoothDevice {
38 USING_PRE_FINALIZER(BluetoothDevice, dispose); 34 USING_PRE_FINALIZER(BluetoothDevice, dispose);
39 DEFINE_WRAPPERTYPEINFO(); 35 DEFINE_WRAPPERTYPEINFO();
40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); 36 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice);
41 37
42 public: 38 public:
43 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); 39 BluetoothDevice(ExecutionContext*,
40 const String& id,
41 const String& name,
42 Bluetooth*);
44 43
45 // Interface required by CallbackPromiseAdapter: 44 // Interface required by CallbackPromiseAdapter:
46 using WebType = std::unique_ptr<WebBluetoothDeviceInit>;
47 static BluetoothDevice* take(ScriptPromiseResolver*, 45 static BluetoothDevice* take(ScriptPromiseResolver*,
48 std::unique_ptr<WebBluetoothDeviceInit>); 46 const String& id,
47 const String& name,
48 Bluetooth*);
49
50 static mojom::blink::WebBluetoothDeviceIdPtr createMojoDeviceId(
51 const String& deviceId);
49 52
50 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( 53 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService(
51 std::unique_ptr<WebBluetoothRemoteGATTService>); 54 const String& serviceInstanceId,
55 const String& uuid,
56 bool isPrimary,
57 const String& deviceInstanceId);
52 bool isValidService(const String& serviceInstanceId); 58 bool isValidService(const String& serviceInstanceId);
53 59
54 BluetoothRemoteGATTCharacteristic* 60 BluetoothRemoteGATTCharacteristic*
55 getOrCreateBluetoothRemoteGATTCharacteristic( 61 getOrCreateBluetoothRemoteGATTCharacteristic(
56 ExecutionContext*, 62 ExecutionContext*,
57 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, 63 const String& characteristicInstanceId,
64 const String& serviceInstanceId,
65 const String& uuid,
66 uint32_t characteristicProperties,
58 BluetoothRemoteGATTService*); 67 BluetoothRemoteGATTService*);
59 bool isValidCharacteristic(const String& characteristicInstanceId); 68 bool isValidCharacteristic(const String& characteristicInstanceId);
60 69
61 // We should disconnect from the device in all of the following cases: 70 // We should disconnect from the device in all of the following cases:
62 // 1. When the object gets GarbageCollected e.g. it went out of scope. 71 // 1. When the object gets GarbageCollected e.g. it went out of scope.
63 // dispose() is called in this case. 72 // dispose() is called in this case.
64 // 2. When the parent document gets detached e.g. reloading a page. 73 // 2. When the parent document gets detached e.g. reloading a page.
65 // stop() is called in this case. 74 // stop() is called in this case.
66 // TODO(ortuno): Users should be able to turn on notifications for 75 // TODO(ortuno): Users should be able to turn on notifications for
67 // events on navigator.bluetooth and still remain connected even if the 76 // events on navigator.bluetooth and still remain connected even if the
(...skipping 13 matching lines...) Expand all
81 void disconnectGATTIfConnected(); 90 void disconnectGATTIfConnected();
82 91
83 // Performs necessary cleanup when a device disconnects and fires 92 // Performs necessary cleanup when a device disconnects and fires
84 // gattserverdisconnected event. 93 // gattserverdisconnected event.
85 void cleanupDisconnectedDeviceAndFireEvent(); 94 void cleanupDisconnectedDeviceAndFireEvent();
86 95
87 // EventTarget methods: 96 // EventTarget methods:
88 const AtomicString& interfaceName() const override; 97 const AtomicString& interfaceName() const override;
89 ExecutionContext* getExecutionContext() const override; 98 ExecutionContext* getExecutionContext() const override;
90 99
91 // WebBluetoothDevice interface: 100 void dispatchGattServerDisconnected();
92 void dispatchGattServerDisconnected() override; 101
102 Bluetooth* bluetooth() { return m_bluetooth; }
93 103
94 // Interface required by Garbage Collection: 104 // Interface required by Garbage Collection:
95 DECLARE_VIRTUAL_TRACE(); 105 DECLARE_VIRTUAL_TRACE();
96 106
97 // IDL exposed interface: 107 // IDL exposed interface:
98 String id() { return m_webDevice->id; } 108 String id() { return m_id; }
99 String name() { return m_webDevice->name; } 109 String name() { return m_name; }
100 BluetoothRemoteGATTServer* gatt() { return m_gatt; } 110 BluetoothRemoteGATTServer* gatt() { return m_gatt; }
101 111
102 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); 112 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected);
103 113
104 private: 114 private:
105 // Holds all GATT Attributes associated with this BluetoothDevice. 115 // Holds all GATT Attributes associated with this BluetoothDevice.
106 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; 116 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap;
107 117
108 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; 118 const String m_id;
119 const String m_name;
109 Member<BluetoothRemoteGATTServer> m_gatt; 120 Member<BluetoothRemoteGATTServer> m_gatt;
121 Member<Bluetooth> m_bluetooth;
110 }; 122 };
111 123
112 } // namespace blink 124 } // namespace blink
113 125
114 #endif // BluetoothDevice_h 126 #endif // BluetoothDevice_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698