[go: nahoru, domu]

blob: 768042da404ed6ba151a3c5042db4dcfee763ff2 [file] [log] [blame]
keybuk@chromium.org2c24d942014-05-02 16:07:311// 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
thakis08c9d69b02016-04-11 04:37:258#include <memory>
9
keybuk@chromium.org2c24d942014-05-02 16:07:3110#include "base/memory/ref_counted.h"
keybuk@chromium.org2c24d942014-05-02 16:07:3111#include "base/threading/thread_checker.h"
Gabriel Charetted87f10f2022-03-31 00:44:2212#include "base/time/time.h"
scheib7c0d2772014-12-06 16:02:0413#include "device/bluetooth/bluetooth_export.h"
keybuk@chromium.org2c24d942014-05-02 16:07:3114
15namespace base {
16class SequencedTaskRunner;
17class Thread;
18} // namespace base
19
20namespace device {
21
rkc41077042015-11-06 07:20:5822// Thread abstraction used by |BluetoothSocketBlueZ| and |BluetoothSocketWin|
keybuk@chromium.org2c24d942014-05-02 16:07:3123// to perform IO operations on the underlying platform sockets. An instance of
24// this class can be shared by many active sockets.
scheib7c0d2772014-12-06 16:02:0425class DEVICE_BLUETOOTH_EXPORT BluetoothSocketThread
keybuk@chromium.org2c24d942014-05-02 16:07:3126 : public base::RefCountedThreadSafe<BluetoothSocketThread> {
27 public:
28 static scoped_refptr<BluetoothSocketThread> Get();
Peter Boström4769b842021-10-05 20:59:2329
30 BluetoothSocketThread(const BluetoothSocketThread&) = delete;
31 BluetoothSocketThread& operator=(const BluetoothSocketThread&) = delete;
32
keybuk@chromium.org891c3942014-05-13 23:33:4033 static void CleanupForTesting();
34
keybuk@chromium.org2c24d942014-05-02 16:07:3135 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_;
thakis08c9d69b02016-04-11 04:37:2549 std::unique_ptr<base::Thread> thread_;
keybuk@chromium.org2c24d942014-05-02 16:07:3150 scoped_refptr<base::SequencedTaskRunner> task_runner_;
keybuk@chromium.org2c24d942014-05-02 16:07:3151};
52
53} // namespace device
54
55#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_