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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « no previous file | content/browser/bluetooth/frame_connected_bluetooth_devices.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 12 #include "base/optional.h"
13 #include "content/common/bluetooth/web_bluetooth_device_id.h" 13 #include "content/common/bluetooth/web_bluetooth_device_id.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
15 #include "url/origin.h" 16 #include "url/origin.h"
16 17
17 namespace device { 18 namespace device {
18 class BluetoothGattConnection; 19 class BluetoothGattConnection;
19 } // namespace device 20 } // namespace device
20 21
21 namespace content { 22 namespace content {
22 23
24 struct GATTConnectionAndServerClient;
23 class RenderFrameHost; 25 class RenderFrameHost;
24 class WebContentsImpl; 26 class WebContentsImpl;
25 27
26 // Holds information about connected devices and updates the WebContents 28 // Holds information about connected devices and updates the WebContents
27 // when new connections are made or connections closed. WebContents must 29 // when new connections are made or connections closed. WebContents must
28 // outlive this class. 30 // outlive this class.
29 // This class does not keep track of the status of the connections. Owners of 31 // 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 32 // this class should inform it when a connection is terminated so that the
31 // connection is removed from the appropriate maps. 33 // connection is removed from the appropriate maps.
32 class CONTENT_EXPORT FrameConnectedBluetoothDevices final { 34 class CONTENT_EXPORT FrameConnectedBluetoothDevices final {
33 public: 35 public:
34 // |rfh| should be the RenderFrameHost that owns the WebBluetoothServiceImpl 36 // |rfh| should be the RenderFrameHost that owns the WebBluetoothServiceImpl
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<WebBluetoothDeviceId,
70 std::unique_ptr<device::BluetoothGattConnection>, 73 std::unique_ptr<GATTConnectionAndServerClient>,
71 WebBluetoothDeviceIdHash> 74 WebBluetoothDeviceIdHash>
72 device_id_to_connection_map_; 75 device_id_to_connection_map_;
73 76
74 // Keeps track of which device addresses correspond to which ids. 77 // Keeps track of which device addresses correspond to which ids.
75 std::unordered_map<std::string, WebBluetoothDeviceId> 78 std::unordered_map<std::string, WebBluetoothDeviceId>
76 device_address_to_id_map_; 79 device_address_to_id_map_;
77 80
78 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices); 81 DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices);
79 }; 82 };
80 83
81 } // namespace content 84 } // namespace content
82 85
83 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_ 86 #endif // CONTENT_BROWSER_BLUETOOTH_FRAME_CONNECTED_BLUETOOTH_DEVICES_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/frame_connected_bluetooth_devices.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698