keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_ |
| 7 | |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 11 | #include "base/threading/thread_checker.h" |
Gabriel Charette | d87f10f | 2022-03-31 00:44:22 | [diff] [blame^] | 12 | #include "base/time/time.h" |
scheib | 7c0d277 | 2014-12-06 16:02:04 | [diff] [blame] | 13 | #include "device/bluetooth/bluetooth_export.h" |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | class SequencedTaskRunner; |
| 17 | class Thread; |
| 18 | } // namespace base |
| 19 | |
| 20 | namespace device { |
| 21 | |
rkc | 4107704 | 2015-11-06 07:20:58 | [diff] [blame] | 22 | // Thread abstraction used by |BluetoothSocketBlueZ| and |BluetoothSocketWin| |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 23 | // to perform IO operations on the underlying platform sockets. An instance of |
| 24 | // this class can be shared by many active sockets. |
scheib | 7c0d277 | 2014-12-06 16:02:04 | [diff] [blame] | 25 | class DEVICE_BLUETOOTH_EXPORT BluetoothSocketThread |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 26 | : public base::RefCountedThreadSafe<BluetoothSocketThread> { |
| 27 | public: |
| 28 | static scoped_refptr<BluetoothSocketThread> Get(); |
Peter Boström | 4769b84 | 2021-10-05 20:59:23 | [diff] [blame] | 29 | |
| 30 | BluetoothSocketThread(const BluetoothSocketThread&) = delete; |
| 31 | BluetoothSocketThread& operator=(const BluetoothSocketThread&) = delete; |
| 32 | |
keybuk@chromium.org | 891c394 | 2014-05-13 23:33:40 | [diff] [blame] | 33 | static void CleanupForTesting(); |
| 34 | |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 35 | void OnSocketActivate(); |
| 36 | void OnSocketDeactivate(); |
| 37 | |
| 38 | scoped_refptr<base::SequencedTaskRunner> task_runner() const; |
| 39 | |
| 40 | private: |
| 41 | friend class base::RefCountedThreadSafe<BluetoothSocketThread>; |
| 42 | BluetoothSocketThread(); |
| 43 | virtual ~BluetoothSocketThread(); |
| 44 | |
| 45 | void EnsureStarted(); |
| 46 | |
| 47 | base::ThreadChecker thread_checker_; |
| 48 | int active_socket_count_; |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 49 | std::unique_ptr<base::Thread> thread_; |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 50 | scoped_refptr<base::SequencedTaskRunner> task_runner_; |
keybuk@chromium.org | 2c24d94 | 2014-05-02 16:07:31 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace device |
| 54 | |
| 55 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_ |