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

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: Fixed some style issues. 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
50 void AddObserver(Observer* observer);
51 void RemoveObserver(Observer* observer);
52
53 void Initialize();
54 void Shutdown();
55
56 private:
57 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>;
58 friend class BluetoothTaskManagerWinTest;
59
60 static const int kPollIntervalMs;
61
62 virtual ~BluetoothTaskManagerWin();
63
64 // Notify all Observers of updated AdapterState. Should only be called on the
65 // UI thread.
66 void OnAdapterStateChanged(const AdapterState* state);
67
68 // Called on BluetoothTaskRunner.
69 void StartPolling();
70 void PollAdapter();
71
72 // UI task runner reference.
73 const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
74
75 const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
76 const scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_;
77
78 // List of observers interested in event notifications.
79 ObserverList<Observer> observers_;
80
81 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin);
82 };
83
84 } // namespace device
85
86 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698