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

Side by Side Diff: content/browser/bluetooth/frame_connected_bluetooth_devices.h

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Rebase Created 4 years, 4 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 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 11
12 #include "base/optional.h"
13 #include "content/common/bluetooth/web_bluetooth_device_id.h"
12 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
13 #include "url/origin.h" 15 #include "url/origin.h"
14 16
15 namespace device { 17 namespace device {
16 class BluetoothGattConnection; 18 class BluetoothGattConnection;
17 } // namespace device 19 } // namespace device
18 20
19 namespace content { 21 namespace content {
20 22
21 class RenderFrameHost; 23 class RenderFrameHost;
22 class WebContentsImpl; 24 class WebContentsImpl;
23 25
24 // Holds information about connected devices and updates the WebContents 26 // Holds information about connected devices and updates the WebContents
25 // when new connections are made or connections closed. WebContents must 27 // when new connections are made or connections closed. WebContents must
26 // outlive this class. 28 // outlive this class.
27 // This class does not keep track of the status of the connections. Owners of 29 // This class does not keep track of the status of the connections. Owners of
28 // this class should inform it when a connection is terminated so that the 30 // this class should inform it when a connection is terminated so that the
29 // connection is removed from the appropriate maps. 31 // connection is removed from the appropriate maps.
30 class CONTENT_EXPORT FrameConnectedBluetoothDevices final { 32 class CONTENT_EXPORT FrameConnectedBluetoothDevices final {
31 public: 33 public:
32 // |rfh| should be the RenderFrameHost that owns the WebBluetoothServiceImpl 34 // |rfh| should be the RenderFrameHost that owns the WebBluetoothServiceImpl
33 // that owns this map. 35 // that owns this map.
34 explicit FrameConnectedBluetoothDevices(RenderFrameHost* rfh); 36 explicit FrameConnectedBluetoothDevices(RenderFrameHost* rfh);
35 ~FrameConnectedBluetoothDevices(); 37 ~FrameConnectedBluetoothDevices();
36 38
37 // Returns true if the map holds a connection to |device_id|. 39 // Returns true if the map holds a connection to |device_id|.
38 bool IsConnectedToDeviceWithId(const std::string& device_id); 40 bool IsConnectedToDeviceWithId(const WebBluetoothDeviceId& device_id);
39 41
40 // If a connection doesn't exist already for |device_id|, adds a connection to 42 // If a connection doesn't exist already for |device_id|, adds a connection to
41 // the map and increases the WebContents count of connected devices. 43 // the map and increases the WebContents count of connected devices.
42 void Insert(const std::string& device_id, 44 void Insert(const WebBluetoothDeviceId& device_id,
43 std::unique_ptr<device::BluetoothGattConnection> connection); 45 std::unique_ptr<device::BluetoothGattConnection> connection);
44 46
45 // Deletes the BluetoothGattConnection for |device_id| and decrements the 47 // Deletes the BluetoothGattConnection for |device_id| and decrements the
46 // WebContents count of connected devices if |device_id| had a connection. 48 // WebContents count of connected devices if |device_id| had a connection.
47 void CloseConnectionToDeviceWithId(const std::string& device_id); 49 void CloseConnectionToDeviceWithId(const WebBluetoothDeviceId& device_id);
48 50
49 // Deletes the BluetoothGattConnection for |device_address| and decrements the 51 // Deletes the BluetoothGattConnection for |device_address| and decrements the
50 // WebContents count of connected devices if |device_address| had a 52 // WebContents count of connected devices if |device_address| had a
51 // connection. Returns the device_id of the device associated with the 53 // connection. Returns the device_id of the device associated with the
52 // connection. 54 // connection.
53 std::string CloseConnectionToDeviceWithAddress( 55 base::Optional<WebBluetoothDeviceId> CloseConnectionToDeviceWithAddress(
54 const std::string& device_address); 56 const std::string& device_address);
55 57
56 private: 58 private:
57 // Increments the Connected Devices count of the frame's WebContents. 59 // Increments the Connected Devices count of the frame's WebContents.
58 void IncrementDevicesConnectedCount(); 60 void IncrementDevicesConnectedCount();
59 // Decrements the Connected Devices count of the frame's WebContents. 61 // Decrements the Connected Devices count of the frame's WebContents.
60 void DecrementDevicesConnectedCount(); 62 void DecrementDevicesConnectedCount();
61 63
62 // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map. 64 // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map.
63 WebContentsImpl* web_contents_impl_; 65 WebContentsImpl* web_contents_impl_;
64 66
65 // Keeps the BluetoothGattConnection objects alive so that connections don't 67 // Keeps the BluetoothGattConnection objects alive so that connections don't
66 // get closed. 68 // get closed.
67 std::unordered_map<std::string, 69 std::unordered_map<WebBluetoothDeviceId,
68 std::unique_ptr<device::BluetoothGattConnection>> 70 std::unique_ptr<device::BluetoothGattConnection>,
71 WebBluetoothDeviceIdHash>
69 device_id_to_connection_map_; 72 device_id_to_connection_map_;
70 73
71 // Keeps track of which device addresses correspond to which ids. 74 // Keeps track of which device addresses correspond to which ids.
72 std::unordered_map<std::string, std::string> device_address_to_id_map_; 75 std::unordered_map<std::string, WebBluetoothDeviceId>
76 device_address_to_id_map_;
73 77
74 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices); 78 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices);
75 }; 79 };
76 80
77 } // namespace content 81 } // namespace content
78 82
79 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ 83 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698