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

Unified Diff: content/browser/bluetooth/bluetooth_connected_devices_map.h

Issue 1902153003: bluetooth: Move connect/disconnect to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-connection-tests
Patch Set: Moar clean up Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/bluetooth/bluetooth_connected_devices_map.h
diff --git a/content/browser/bluetooth/bluetooth_connected_devices_map.h b/content/browser/bluetooth/bluetooth_connected_devices_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..a78690a1f11c0f1bd60605c82475aa70bd7d0921
--- /dev/null
+++ b/content/browser/bluetooth/bluetooth_connected_devices_map.h
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_CONNECTED_DEVICES_MAP_H_
+#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_CONNECTED_DEVICES_MAP_H_
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+#include "content/common/content_export.h"
+#include "url/origin.h"
+
+namespace device {
+class BluetoothGattConnection;
+} // namespace device
+
+namespace content {
+
+class WebContents;
+class WebContentsImpl;
+
+// Holds information about connected devices and updates the WebContents
+// when new connections are made or connections closed. WebContents should
Jeffrey Yasskin 2016/05/03 01:15:57 s/should/must/
ortuno 2016/05/03 16:11:53 Done.
+// outlive this class.
+// This class does not keep track of the status of the connections. Owners of
+// this class should inform it when a connection is terminated so that the
+// connection removed from the appropriate maps.
+class CONTENT_EXPORT BluetoothConnectedDevicesMap final {
Jeffrey Yasskin 2016/05/03 01:15:57 I think I'd name this "FrameConnectedBluetoothDevi
ortuno 2016/05/03 16:11:53 Done.
+ public:
+ explicit BluetoothConnectedDevicesMap(WebContents* web_contents);
Jeffrey Yasskin 2016/05/03 01:15:57 If this argument flows directly into this->web_con
ortuno 2016/05/03 16:11:53 Done.
+ ~BluetoothConnectedDevicesMap();
+
+ // Returns true if the map holds a connection to |device_id|.
+ bool IsConnectedToDeviceWithId(const std::string& device_id);
+
+ // If a connection doesn't exist already for |device_id| adds a connection to
Jeffrey Yasskin 2016/05/03 01:15:57 Add a comma before "adds".
ortuno 2016/05/03 16:11:53 Done.
+ // the map and increases the WebContents count of connected devices.
+ void Insert(const std::string& device_id,
+ std::unique_ptr<device::BluetoothGattConnection> connection);
+
+ // Deletes the BluetoothGattConnection for |device_id| and decrements the
+ // WebContents count of connected devices if |device_id| had a connection.
+ void CloseConnectionToDeviceWithId(const std::string& device_id);
+
+ // Deletes the BluetoothGattConnection for |device_address| and decrements the
+ // WebContents count of connected devices if |device_address| had a
+ // connection. Returns the device_id of the device associated with the
+ // connection.
+ std::string CloseConnectionToDeviceWithAddress(
+ const std::string& device_address);
+
+ private:
+ // Increments the Connected Devices count of the frame's WebContents.
+ void IncrementDevicesConnectedCount();
+ // Decrements the Connected Devices count of the frame's WebContents.
+ void DecrementDevicesConnectedCount();
+
+ // WebContentsImpl that owns the WebBluetoothServiceImpl that owns this map.
+ WebContentsImpl* web_contents_impl_;
+
+ // Keeps the BluetoothGattConnection objects alive so that connections don't
+ // get closed..
Jeffrey Yasskin 2016/05/03 01:15:57 s/.././
ortuno 2016/05/03 16:11:54 Done.
+ std::unordered_map<std::string,
+ std::unique_ptr<device::BluetoothGattConnection>>
+ device_id_to_connection_map_;
+
+ // Keeps track of which device addresses correspond to which ids.
+ std::unordered_map<std::string, std::string> device_address_to_id_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothConnectedDevicesMap);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_CONNECTED_DEVICES_MAP_H_

Powered by Google App Engine
This is Rietveld 408576698