bluetooth_socket_thread.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_
  6. #include <memory>
  7. #include "base/memory/ref_counted.h"
  8. #include "base/threading/thread_checker.h"
  9. #include "device/bluetooth/bluetooth_export.h"
  10. namespace base {
  11. class SequencedTaskRunner;
  12. class Thread;
  13. } // namespace base
  14. namespace device {
  15. // Thread abstraction used by |BluetoothSocketBlueZ| and |BluetoothSocketWin|
  16. // to perform IO operations on the underlying platform sockets. An instance of
  17. // this class can be shared by many active sockets.
  18. class DEVICE_BLUETOOTH_EXPORT BluetoothSocketThread
  19. : public base::RefCountedThreadSafe<BluetoothSocketThread> {
  20. public:
  21. static scoped_refptr<BluetoothSocketThread> Get();
  22. BluetoothSocketThread(const BluetoothSocketThread&) = delete;
  23. BluetoothSocketThread& operator=(const BluetoothSocketThread&) = delete;
  24. static void CleanupForTesting();
  25. void OnSocketActivate();
  26. void OnSocketDeactivate();
  27. scoped_refptr<base::SequencedTaskRunner> task_runner() const;
  28. private:
  29. friend class base::RefCountedThreadSafe<BluetoothSocketThread>;
  30. BluetoothSocketThread();
  31. virtual ~BluetoothSocketThread();
  32. void EnsureStarted();
  33. base::ThreadChecker thread_checker_;
  34. int active_socket_count_;
  35. std::unique_ptr<base::Thread> thread_;
  36. scoped_refptr<base::SequencedTaskRunner> task_runner_;
  37. };
  38. } // namespace device
  39. #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_