1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
2c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// found in the LICENSE file.
4c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_
6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_
7c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
8c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "base/memory/ref_counted.h"
9c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "base/memory/scoped_ptr.h"
10c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "base/threading/thread_checker.h"
11c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace base {
13c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass SequencedTaskRunner;
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass Thread;
15c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace base
16c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace device {
18c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Thread abstraction used by |BluetoothSocketChromeOS| and |BluetoothSocketWin|
20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// to perform IO operations on the underlying platform sockets. An instance of
21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// this class can be shared by many active sockets.
22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class BluetoothSocketThread
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    : public base::RefCountedThreadSafe<BluetoothSocketThread> {
24c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch public:
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  static scoped_refptr<BluetoothSocketThread> Get();
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static void CleanupForTesting();
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
28c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void OnSocketActivate();
29c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void OnSocketDeactivate();
30c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
31c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_refptr<base::SequencedTaskRunner> task_runner() const;
32c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch private:
34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  friend class base::RefCountedThreadSafe<BluetoothSocketThread>;
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  BluetoothSocketThread();
36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual ~BluetoothSocketThread();
37c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
38c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void EnsureStarted();
39c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  base::ThreadChecker thread_checker_;
41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  int active_socket_count_;
42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_ptr<base::Thread> thread_;
43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_refptr<base::SequencedTaskRunner> task_runner_;
44c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(BluetoothSocketThread);
46c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch};
47c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
48c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace device
49c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif  // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_THREAD_H_
51