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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_task_manager_win.h
diff --git a/device/bluetooth/bluetooth_task_manager_win.h b/device/bluetooth/bluetooth_task_manager_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..8625b83d80c290a9609f9158266a76e3381cddc4
--- /dev/null
+++ b/device/bluetooth/bluetooth_task_manager_win.h
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
+
+#include <string>
+#include "base/memory/ref_counted.h"
+#include "base/observer_list.h"
+#include "device/bluetooth/bluetooth_polling_thread_win.h"
+
+class MessageLoop;
+
+namespace base {
+
+class SequencedTaskRunner;
+
+} // namespace base
+
+namespace device {
+
+// Manages the blocking Bluetooth tasks with a dedicated thread. It owns and
+// runs a thread to perform blocking Bluetooth tasks and informs its observers
+// of bluetooth adapter state changes and any other bluetooth device inquiry
+// result.
+//
+// It delegates the blocking Windows API calls to |thread_|'s message loop,
+// and receives responses via methods like OnAdapterStateChanged posted by
+// |thread_| to UI thread.
+//
+// This class is reference-counted to guarantee the lifetime of the object for
+// the tasks posted by |thread_| to UI thread.
+//
+// All the code in this class runs in the UI thread.
+class BluetoothTaskManagerWin
+ : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> {
+ public:
+ struct AdapterState {
+ std::string name;
+ std::string address;
+ bool powered;
+ };
+
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ virtual void AdapterStateChanged(const AdapterState& state) {}
+ };
+
+ BluetoothTaskManagerWin();
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ void StartThread();
+ void StopThread();
+
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner() {
+ return ui_task_runner_;
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>;
+ friend class BluetoothPollingThreadWin;
+
+ virtual ~BluetoothTaskManagerWin();
+
+ // Notify all Observers of updated AdapterState. Should only be called on the
+ // UI thread.
+ void OnAdapterStateChanged(const AdapterState* state);
+
+ // UI task runner reference.
+ const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
+
+ BluetoothPollingThreadWin thread_;
+
+ // List of observers interested in event notifications.
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin);
+};
+
+} // namespace device
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698