OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H |
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "components/proximity_auth/connection.h" | 13 #include "components/cryptauth/connection.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 15 #include "device/bluetooth/bluetooth_device.h" |
16 #include "device/bluetooth/bluetooth_socket.h" | 16 #include "device/bluetooth/bluetooth_socket.h" |
17 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class IOBuffer; | 20 class IOBuffer; |
21 } | 21 } |
22 | 22 |
23 namespace cryptauth { | 23 namespace cryptauth { |
24 struct RemoteDevice; | 24 struct RemoteDevice; |
25 } | 25 } |
26 | 26 |
27 namespace proximity_auth { | 27 namespace proximity_auth { |
28 | 28 |
29 // Represents a Bluetooth connection with a remote device. The connection is a | 29 // Represents a Bluetooth connection with a remote device. The connection is a |
30 // persistent bidirectional channel for sending and receiving wire messages. | 30 // persistent bidirectional channel for sending and receiving wire messages. |
31 class BluetoothConnection : public Connection, | 31 class BluetoothConnection : public cryptauth::Connection, |
32 public device::BluetoothAdapter::Observer { | 32 public device::BluetoothAdapter::Observer { |
33 public: | 33 public: |
34 // Constructs a Bluetooth connection to the service with |uuid| on the | 34 // Constructs a Bluetooth connection to the service with |uuid| on the |
35 // |remote_device|. The |remote_device| must already be known to the system | 35 // |remote_device|. The |remote_device| must already be known to the system |
36 // Bluetooth daemon. | 36 // Bluetooth daemon. |
37 BluetoothConnection(const cryptauth::RemoteDevice& remote_device, | 37 BluetoothConnection(const cryptauth::RemoteDevice& remote_device, |
38 const device::BluetoothUUID& uuid); | 38 const device::BluetoothUUID& uuid); |
39 ~BluetoothConnection() override; | 39 ~BluetoothConnection() override; |
40 | 40 |
41 // Connection: | 41 // Connection: |
42 void Connect() override; | 42 void Connect() override; |
43 void Disconnect() override; | 43 void Disconnect() override; |
44 | 44 |
45 protected: | 45 protected: |
46 // Connection: | 46 // Connection: |
47 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; | 47 void SendMessageImpl( |
| 48 std::unique_ptr<cryptauth::WireMessage> message) override; |
48 | 49 |
49 // BluetoothAdapter::Observer: | 50 // BluetoothAdapter::Observer: |
50 void DeviceChanged(device::BluetoothAdapter* adapter, | 51 void DeviceChanged(device::BluetoothAdapter* adapter, |
51 device::BluetoothDevice* device) override; | 52 device::BluetoothDevice* device) override; |
52 void DeviceRemoved(device::BluetoothAdapter* adapter, | 53 void DeviceRemoved(device::BluetoothAdapter* adapter, |
53 device::BluetoothDevice* device) override; | 54 device::BluetoothDevice* device) override; |
54 | 55 |
55 private: | 56 private: |
56 // Registers receive callbacks with the backing |socket_|. | 57 // Registers receive callbacks with the backing |socket_|. |
57 void StartReceive(); | 58 void StartReceive(); |
(...skipping 15 matching lines...) Expand all Loading... |
73 // The Bluetooth adapter over which this connection is made. Non-null iff | 74 // The Bluetooth adapter over which this connection is made. Non-null iff |
74 // |this| connection is registered as an observer of the |adapter_|. | 75 // |this| connection is registered as an observer of the |adapter_|. |
75 scoped_refptr<device::BluetoothAdapter> adapter_; | 76 scoped_refptr<device::BluetoothAdapter> adapter_; |
76 | 77 |
77 // The Bluetooth socket that backs this connection. NULL iff the connection is | 78 // The Bluetooth socket that backs this connection. NULL iff the connection is |
78 // not in a connected state. | 79 // not in a connected state. |
79 scoped_refptr<device::BluetoothSocket> socket_; | 80 scoped_refptr<device::BluetoothSocket> socket_; |
80 | 81 |
81 // The message that was sent over the backing |socket_|. NULL iff there is no | 82 // The message that was sent over the backing |socket_|. NULL iff there is no |
82 // send operation in progress. | 83 // send operation in progress. |
83 std::unique_ptr<WireMessage> pending_message_; | 84 std::unique_ptr<cryptauth::WireMessage> pending_message_; |
84 | 85 |
85 base::WeakPtrFactory<BluetoothConnection> weak_ptr_factory_; | 86 base::WeakPtrFactory<BluetoothConnection> weak_ptr_factory_; |
86 | 87 |
87 DISALLOW_COPY_AND_ASSIGN(BluetoothConnection); | 88 DISALLOW_COPY_AND_ASSIGN(BluetoothConnection); |
88 }; | 89 }; |
89 | 90 |
90 } // namespace proximity_auth | 91 } // namespace proximity_auth |
91 | 92 |
92 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H | 93 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_H |
OLD | NEW |