| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
| 6 #define CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "content/common/content_export.h" |
| 13 #include "url/origin.h" |
| 14 |
| 15 namespace device { |
| 16 class BluetoothGattConnection; |
| 17 } // namespace device |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class RenderFrameHost; |
| 22 class WebContentsImpl; |
| 23 |
| 24 // Holds information about connected devices and updates the WebContents |
| 25 // when new connections are made or connections closed. WebContents must |
| 26 // outlive this class. |
| 27 // 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 |
| 29 // connection is removed from the appropriate maps. |
| 30 class CONTENT_EXPORT FrameConnectedBluetoothDevices final { |
| 31 public: |
| 32 // |rfh| should be the RenderFrameHost that owns the WebBluetoothServiceImpl |
| 33 // that owns this map. |
| 34 explicit FrameConnectedBluetoothDevices(RenderFrameHost* rfh); |
| 35 ~FrameConnectedBluetoothDevices(); |
| 36 |
| 37 // Returns true if the map holds a connection to |device_id|. |
| 38 bool IsConnectedToDeviceWithId(const std::string& device_id); |
| 39 |
| 40 // 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. |
| 42 void Insert(const std::string& device_id, |
| 43 std::unique_ptr<device::BluetoothGattConnection> connection); |
| 44 |
| 45 // Deletes the BluetoothGattConnection for |device_id| and decrements the |
| 46 // WebContents count of connected devices if |device_id| had a connection. |
| 47 void CloseConnectionToDeviceWithId(const std::string& device_id); |
| 48 |
| 49 // Deletes the BluetoothGattConnection for |device_address| and decrements the |
| 50 // WebContents count of connected devices if |device_address| had a |
| 51 // connection. Returns the device_id of the device associated with the |
| 52 // connection. |
| 53 std::string CloseConnectionToDeviceWithAddress( |
| 54 const std::string& device_address); |
| 55 |
| 56 private: |
| 57 // Increments the Connected Devices count of the frame's WebContents. |
| 58 void IncrementDevicesConnectedCount(); |
| 59 // Decrements the Connected Devices count of the frame's WebContents. |
| 60 void DecrementDevicesConnectedCount(); |
| 61 |
| 62 // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map. |
| 63 WebContentsImpl* web_contents_impl_; |
| 64 |
| 65 // Keeps the BluetoothGattConnection objects alive so that connections don't |
| 66 // get closed. |
| 67 std::unordered_map<std::string, |
| 68 std::unique_ptr<device::BluetoothGattConnection>> |
| 69 device_id_to_connection_map_; |
| 70 |
| 71 // Keeps track of which device addresses correspond to which ids. |
| 72 std::unordered_map<std::string, std::string> device_address_to_id_map_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices); |
| 75 }; |
| 76 |
| 77 } // namespace content |
| 78 |
| 79 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ |
| OLD | NEW |