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

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

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

Powered by Google App Engine
This is Rietveld 408576698