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 8 #include "base/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/threading/thread_checker.h" 11 12 namespace base { 13 class SequencedTaskRunner; 14 class Thread; 15 } // namespace base 16 17 namespace device { 18 19 // Thread abstraction used by |BluetoothSocketChromeOS| and |BluetoothSocketWin| 20 // to perform IO operations on the underlying platform sockets. An instance of 21 // this class can be shared by many active sockets. 22 class BluetoothSocketThread 23 : public base::RefCountedThreadSafe<BluetoothSocketThread> { 24 public: 25 static scoped_refptr<BluetoothSocketThread> Get(); 26 static void CleanupForTesting(); 27 28 void OnSocketActivate(); 29 void OnSocketDeactivate(); 30 31 scoped_refptr<base::SequencedTaskRunner> task_runner() const; 32 33 private: 34 friend class base::RefCountedThreadSafe<BluetoothSocketThread>; 35 BluetoothSocketThread(); 36 virtual ~BluetoothSocketThread(); 37 38 void EnsureStarted(); 39 40 base::ThreadChecker thread_checker_; 41 int active_socket_count_; 42 scoped_ptr<base::Thread> thread_; 43 scoped_refptr<base::SequencedTaskRunner> task_runner_; 44 45 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketThread); 46 }; 47 48 } // namespace device 49 50 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_ 51