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

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: Replace naked MessageLoop pointer with SequencedTaskRunner refcounted pointer Created 8 years 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 #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 base {
16
17 class SequencedTaskRunner;
18
19 } // namespace base
20
21 namespace device {
22
23 // Manages the blocking Bluetooth tasks with a dedicated thread. It owns and
24 // runs a thread to perform blocking Bluetooth tasks and informs its observers
25 // of bluetooth adapter state changes and any other bluetooth device inquiry
26 // result.
27 //
28 // It delegates the blocking Windows API calls to |thread_|'s message loop,
29 // and receives responses via methods like OnAdapterStateChanged posted by
30 // |thread_| to UI thread.
31 //
32 // This class is reference-counted to guarantee the lifetime of the object for
33 // the tasks posted by |thread_| to UI thread.
34 //
35 // All the code in this class runs in the UI thread.
36 class BluetoothTaskManagerWin
37 : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> {
38 public:
39 struct AdapterState {
40 std::string name;
41 std::string address;
42 bool powered;
43 };
44
45 class Observer {
46 public:
47 virtual ~Observer() {}
48
49 virtual void AdapterStateChanged(const AdapterState& state) {}
50 };
51
52 BluetoothTaskManagerWin();
53
54 void AddObserver(Observer* observer);
55 void RemoveObserver(Observer* observer);
56
57 void StartThread();
58 void StopThread();
59
60 scoped_refptr<base::SequencedTaskRunner> ui_task_runner() {
61 return ui_task_runner_;
62 }
63
64 private:
65 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>;
66 friend class BluetoothPollingThreadWin;
67
68 virtual ~BluetoothTaskManagerWin();
69
70 // Notify all Observers of updated AdapterState. Should only be called on the
71 // UI thread.
72 void OnAdapterStateChanged(const AdapterState* state);
73
74 // UI task runner reference.
75 const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
76
77 BluetoothPollingThreadWin thread_;
78
79 // List of observers interested in event notifications.
80 ObserverList<Observer> observers_;
81
82 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin);
83 };
84
85 } // namespace device
86
87 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698