OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
6 #define CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 #include <utility> |
11 | 12 |
12 #include "base/optional.h" | 13 #include "base/optional.h" |
13 #include "content/common/bluetooth/web_bluetooth_device_id.h" | 14 #include "content/common/bluetooth/web_bluetooth_device_id.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" |
15 #include "url/origin.h" | 17 #include "url/origin.h" |
16 | 18 |
17 namespace device { | 19 namespace device { |
18 class BluetoothGattConnection; | 20 class BluetoothGattConnection; |
19 } // namespace device | 21 } // namespace device |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
23 class RenderFrameHost; | 25 class RenderFrameHost; |
24 class WebContentsImpl; | 26 class WebContentsImpl; |
(...skipping 10 matching lines...) Expand all Loading... |
35 // that owns this map. | 37 // that owns this map. |
36 explicit FrameConnectedBluetoothDevices(RenderFrameHost* rfh); | 38 explicit FrameConnectedBluetoothDevices(RenderFrameHost* rfh); |
37 ~FrameConnectedBluetoothDevices(); | 39 ~FrameConnectedBluetoothDevices(); |
38 | 40 |
39 // Returns true if the map holds a connection to |device_id|. | 41 // Returns true if the map holds a connection to |device_id|. |
40 bool IsConnectedToDeviceWithId(const WebBluetoothDeviceId& device_id); | 42 bool IsConnectedToDeviceWithId(const WebBluetoothDeviceId& device_id); |
41 | 43 |
42 // If a connection doesn't exist already for |device_id|, adds a connection to | 44 // If a connection doesn't exist already for |device_id|, adds a connection to |
43 // the map and increases the WebContents count of connected devices. | 45 // the map and increases the WebContents count of connected devices. |
44 void Insert(const WebBluetoothDeviceId& device_id, | 46 void Insert(const WebBluetoothDeviceId& device_id, |
45 std::unique_ptr<device::BluetoothGattConnection> connection); | 47 std::unique_ptr<device::BluetoothGattConnection> connection, |
| 48 blink::mojom::WebBluetoothServerClientAssociatedPtr client); |
46 | 49 |
47 // Deletes the BluetoothGattConnection for |device_id| and decrements the | 50 // Deletes the BluetoothGattConnection for |device_id| and decrements the |
48 // WebContents count of connected devices if |device_id| had a connection. | 51 // WebContents count of connected devices if |device_id| had a connection. |
49 void CloseConnectionToDeviceWithId(const WebBluetoothDeviceId& device_id); | 52 void CloseConnectionToDeviceWithId(const WebBluetoothDeviceId& device_id); |
50 | 53 |
51 // Deletes the BluetoothGattConnection for |device_address| and decrements the | 54 // Deletes the BluetoothGattConnection for |device_address| and decrements the |
52 // WebContents count of connected devices if |device_address| had a | 55 // WebContents count of connected devices if |device_address| had a |
53 // connection. Returns the device_id of the device associated with the | 56 // connection. Returns the device_id of the device associated with the |
54 // connection. | 57 // connection. |
55 base::Optional<WebBluetoothDeviceId> CloseConnectionToDeviceWithAddress( | 58 base::Optional<WebBluetoothDeviceId> CloseConnectionToDeviceWithAddress( |
56 const std::string& device_address); | 59 const std::string& device_address); |
57 | 60 |
58 private: | 61 private: |
59 // Increments the Connected Devices count of the frame's WebContents. | 62 // Increments the Connected Devices count of the frame's WebContents. |
60 void IncrementDevicesConnectedCount(); | 63 void IncrementDevicesConnectedCount(); |
61 // Decrements the Connected Devices count of the frame's WebContents. | 64 // Decrements the Connected Devices count of the frame's WebContents. |
62 void DecrementDevicesConnectedCount(); | 65 void DecrementDevicesConnectedCount(); |
63 | 66 |
64 // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map. | 67 // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map. |
65 WebContentsImpl* web_contents_impl_; | 68 WebContentsImpl* web_contents_impl_; |
66 | 69 |
67 // Keeps the BluetoothGattConnection objects alive so that connections don't | 70 // Keeps the BluetoothGattConnection objects alive so that connections don't |
68 // get closed. | 71 // get closed. |
69 std::unordered_map<WebBluetoothDeviceId, | 72 std::unordered_map< |
70 std::unique_ptr<device::BluetoothGattConnection>, | 73 WebBluetoothDeviceId, |
71 WebBluetoothDeviceIdHash> | 74 std::pair<std::unique_ptr<device::BluetoothGattConnection>, |
| 75 blink::mojom::WebBluetoothServerClientAssociatedPtr>, |
| 76 WebBluetoothDeviceIdHash> |
72 device_id_to_connection_map_; | 77 device_id_to_connection_map_; |
73 | 78 |
74 // Keeps track of which device addresses correspond to which ids. | 79 // Keeps track of which device addresses correspond to which ids. |
75 std::unordered_map<std::string, WebBluetoothDeviceId> | 80 std::unordered_map<std::string, WebBluetoothDeviceId> |
76 device_address_to_id_map_; | 81 device_address_to_id_map_; |
77 | 82 |
78 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices); | 83 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices); |
79 }; | 84 }; |
80 | 85 |
81 } // namespace content | 86 } // namespace content |
82 | 87 |
83 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ | 88 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
OLD | NEW |