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