OLD | NEW |
---|---|
(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 #include "base/memory/ref_counted.h" | |
10 #include "base/observer_list.h" | |
11 #include "device/bluetooth/bluetooth_polling_thread_win.h" | |
12 | |
13 class MessageLoop; | |
14 | |
15 namespace device { | |
16 | |
17 // Manages the blocking Bluetooth tasks with a dedicated thread. It owns and | |
18 // runs a thread to perform blocking Bluetooth tasks and informs its observers | |
19 // of bluetooth adapter state changes and any other bluetooth device inquiry | |
20 // result. | |
21 // All the code in this class runs in the UI thread. | |
bryeung
2012/12/10 19:51:28
This deserves a more thorough comment about why we
youngki
2012/12/17 17:17:23
I put some more comments to explain the message pa
| |
22 class BluetoothTaskManagerWin | |
23 : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> { | |
24 public: | |
25 struct AdapterState { | |
26 std::string name; | |
27 std::string address; | |
28 bool powered; | |
29 }; | |
30 | |
31 class Observer { | |
32 public: | |
33 virtual ~Observer() {} | |
34 | |
35 virtual void AdapterStateChanged(const AdapterState& state) {} | |
36 }; | |
37 | |
38 BluetoothTaskManagerWin(); | |
39 | |
40 void AddObserver(Observer* observer); | |
41 void RemoveObserver(Observer* observer); | |
42 | |
43 void StartThread(); | |
44 void StopThread(); | |
45 | |
46 MessageLoop* message_loop() const { return ui_message_loop_; } | |
47 | |
48 private: | |
49 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>; | |
50 friend class BluetoothPollingThreadWin; | |
bryeung
2012/12/10 19:51:28
why is this necessary?
youngki
2012/12/17 17:17:23
This is necessary so that BluetoothPollingThreadWi
| |
51 | |
52 virtual ~BluetoothTaskManagerWin(); | |
53 | |
54 // Notify all Observers of updated AdapterState. Should only be called on the | |
55 // UI thread. | |
56 void OnAdapterStateChanged(const AdapterState* state); | |
57 | |
58 // Main message loop reference. | |
59 MessageLoop* const ui_message_loop_; | |
60 | |
61 BluetoothPollingThreadWin thread_; | |
62 | |
63 // List of observers interested in event notifications. | |
64 ObserverList<Observer> observers_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); | |
67 }; | |
68 | |
69 } // namespace device | |
70 | |
71 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | |
OLD | NEW |