OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
10 #include "device/bluetooth/bluetooth_profile.h" | 12 #include "device/bluetooth/bluetooth_profile.h" |
11 #include "device/bluetooth/bluetooth_uuid.h" | 13 #include "device/bluetooth/bluetooth_uuid.h" |
12 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
13 | 15 |
| 16 namespace net { |
| 17 class IPEndPoint; |
| 18 class TCPSocket; |
| 19 } |
| 20 |
14 namespace device { | 21 namespace device { |
15 | 22 |
| 23 class BluetoothAdapter; |
| 24 class BluetoothAdapterWin; |
16 class BluetoothDeviceWin; | 25 class BluetoothDeviceWin; |
17 class BluetoothSocketThreadWin; | 26 class BluetoothSocketThreadWin; |
| 27 class BluetoothSocketWin; |
18 | 28 |
19 class BluetoothProfileWin : public BluetoothProfile { | 29 class BluetoothProfileWin : public BluetoothProfile { |
20 public: | 30 public: |
| 31 typedef base::Callback<void(const std::string&)> ErrorCallback; |
| 32 |
21 // BluetoothProfile override. | 33 // BluetoothProfile override. |
22 virtual void Unregister() OVERRIDE; | 34 virtual void Unregister() OVERRIDE; |
23 virtual void SetConnectionCallback( | 35 virtual void SetConnectionCallback( |
24 const ConnectionCallback& callback) OVERRIDE; | 36 const ConnectionCallback& callback) OVERRIDE; |
25 | 37 |
26 typedef base::Callback<void(const std::string&)> ErrorCallback; | 38 // Called by BluetoothProfile::Register to initialize the profile object |
| 39 // asynchronously. |
| 40 void Init(const BluetoothUUID& uuid, |
| 41 const device::BluetoothProfile::Options& options, |
| 42 const ProfileCallback& callback); |
27 | 43 |
28 void Connect(const BluetoothDeviceWin* device, | 44 void Connect(const BluetoothDeviceWin* device, |
29 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 45 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
30 scoped_refptr<BluetoothSocketThreadWin> socket_thread, | 46 scoped_refptr<BluetoothSocketThreadWin> socket_thread, |
31 net::NetLog* net_log, | 47 net::NetLog* net_log, |
32 const net::NetLog::Source& source, | 48 const net::NetLog::Source& source, |
33 const base::Closure& callback, | 49 const base::Closure& callback, |
34 const ErrorCallback& error_callback); | 50 const ErrorCallback& error_callback); |
35 | 51 |
36 private: | 52 private: |
37 friend BluetoothProfile; | 53 friend BluetoothProfile; |
38 | 54 |
39 BluetoothProfileWin(const BluetoothUUID& uuid, const std::string& name); | 55 struct ProfileRegData; |
| 56 |
| 57 BluetoothProfileWin(); |
40 virtual ~BluetoothProfileWin(); | 58 virtual ~BluetoothProfileWin(); |
41 | 59 |
42 const BluetoothUUID uuid_; | 60 // Internal method run to get the adapter object during initialization. |
43 const std::string name_; | 61 void OnGetAdapter(const ProfileCallback& callback, |
| 62 scoped_refptr<BluetoothAdapter> adapter); |
| 63 |
| 64 // Start a bluetooth server socket and register a service. |
| 65 static void RegisterProfileOnSocketThread( |
| 66 const BluetoothUUID& uuid, |
| 67 const std::string& name, |
| 68 int rfcomm_channel, |
| 69 bool* out_success, |
| 70 scoped_ptr<net::TCPSocket>* out_socket, |
| 71 scoped_ptr<ProfileRegData>* out_reg_data); |
| 72 void OnRegisterProfileOnUI(bool* success, |
| 73 scoped_ptr<net::TCPSocket>* socket, |
| 74 scoped_ptr<ProfileRegData>* reg_data, |
| 75 const ProfileCallback& callback); |
| 76 |
| 77 static void UnregisterProfileOnSocketThread( |
| 78 scoped_ptr<ProfileRegData> reg_data); |
| 79 |
| 80 void OnNewConnection(scoped_refptr<BluetoothSocketWin> connected, |
| 81 const net::IPEndPoint& peer_address); |
| 82 |
| 83 BluetoothAdapterWin* adapter() const; |
| 84 |
| 85 BluetoothUUID uuid_; |
| 86 std::string name_; |
| 87 int rfcomm_channel_; |
44 ConnectionCallback connection_callback_; | 88 ConnectionCallback connection_callback_; |
45 | 89 |
| 90 scoped_refptr<BluetoothAdapter> adapter_; |
| 91 |
| 92 scoped_refptr<BluetoothSocketWin> profile_socket_; |
| 93 scoped_ptr<ProfileRegData> profile_reg_data_; |
| 94 |
| 95 base::WeakPtrFactory<BluetoothProfileWin> weak_ptr_factory_; |
| 96 |
46 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileWin); | 97 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileWin); |
47 }; | 98 }; |
48 | 99 |
49 } // namespace device | 100 } // namespace device |
50 | 101 |
51 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ | 102 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_ |
OLD | NEW |