Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: device/bluetooth/bluetooth_task_manager_win.h

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: changed to const char[] Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_TASK_MANAGER_WIN_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list.h"
12
13 class MessageLoop;
14
15 namespace base {
16
17 class SequencedTaskRunner;
18 class SequencedWorkerPool;
19
20 } // namespace base
21
22 namespace device {
23
24 // Manages the blocking Bluetooth tasks using |SequencedWorkerPool|. It runs
25 // bluetooth tasks using |SequencedWorkerPool| and informs its observers of
26 // bluetooth adapter state changes and any other bluetooth device inquiry
27 // result.
28 //
29 // It delegates the blocking Windows API calls to |bluetooth_task_runner_|'s
30 // message loop, and receives responses via methods like OnAdapterStateChanged
31 // posted to UI thread.
32 class BluetoothTaskManagerWin
33 : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> {
34 public:
35 struct AdapterState {
36 std::string name;
37 std::string address;
38 bool powered;
39 };
40
41 class Observer {
42 public:
43 virtual ~Observer() {}
44
45 virtual void AdapterStateChanged(const AdapterState& state) {}
46 };
47
48 BluetoothTaskManagerWin(
49 scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
50
51 void AddObserver(Observer* observer);
52 void RemoveObserver(Observer* observer);
53
54 void Initialize();
55 void Shutdown();
56
57 private:
58 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>;
59 friend class BluetoothTaskManagerWinTest;
60
61 // Returns true if the machine has a bluetooth stack available. The first call
62 // to this function will involve file IO, so it should be done on an
63 // appropriate thread. This function is not threadsafe.
64 static bool HasBluetoothStack();
65
66 static const int kPollIntervalMs;
67
68 // Constructor to pass |ui_task_runner_| and |bluetooth_task_runner_| for
69 // testing.
70 BluetoothTaskManagerWin(
71 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
72 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
73
74 virtual ~BluetoothTaskManagerWin();
75
76 // Notify all Observers of updated AdapterState. Should only be called on the
77 // UI thread.
78 void OnAdapterStateChanged(const AdapterState* state);
79
80 // Called on BluetoothTaskRunner.
81 void StartPolling();
82 void PollAdapter();
83
84 // UI task runner reference.
85 const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
86
87 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
88 const scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_;
89
90 // List of observers interested in event notifications.
91 ObserverList<Observer> observers_;
92
93 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin);
94 };
95
96 } // namespace device
97
98 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win_unittest.cc ('k') | device/bluetooth/bluetooth_task_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698