Index: device/bluetooth/bluetooth_polling_thread_win.h |
diff --git a/device/bluetooth/bluetooth_polling_thread_win.h b/device/bluetooth/bluetooth_polling_thread_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e7f0700cde23823a6454a8b9afe8e201c26e40b6 |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_polling_thread_win.h |
@@ -0,0 +1,78 @@ |
+// 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_POLLING_THREAD_WIN_H_ |
+#define DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/synchronization/cancellation_flag.h" |
+#include "base/threading/thread.h" |
+#include "base/threading/thread_checker.h" |
+ |
+namespace base { |
+ |
+class CancellationFlag; |
+class ThreadChecker; |
bryeung
2012/11/28 16:26:08
not needed with the headers above
youngki
2012/11/28 19:19:13
Done.
|
+ |
+} // namespace base |
+ |
+namespace device { |
+ |
+// A thread dedicated to perform blocking bluetooth APIs on Windows. |
+class BluetoothPollingThreadWin : public base::Thread { |
+ public: |
+ struct AdapterState { |
+ std::string name; |
+ std::string address; |
+ bool powered; |
+ }; |
+ |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // This will always be called on the UI thread. |
+ virtual void AdapterStateChanged(const AdapterState& state) {} |
+ }; |
+ |
+ BluetoothPollingThreadWin(); |
+ virtual ~BluetoothPollingThreadWin(); |
+ |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ void Init(); |
+ |
+ private: |
+ // Populates bluetooth adapter state using adapter_handle. |
+ static void GetAdapterState(const HANDLE adapter_handle, |
bryeung
2012/11/28 16:26:08
this should go inside an anonymous namespace in th
youngki
2012/11/28 19:19:13
Done.
|
+ AdapterState* state); |
+ |
+ // Polls Windows Bluetooth API on BluetoothPollingThread. |
bryeung
2012/11/28 16:26:08
More descriptive comments would be nice, e.g.:
"Ca
youngki
2012/11/28 19:19:13
Done.
|
+ void PollAdapter(base::WeakPtr<BluetoothPollingThreadWin> weak_ptr); |
+ |
+ // Callback to be run on the UI thread. |
bryeung
2012/11/28 16:26:08
"Notify all Observers of updated AdapterState. Sh
youngki
2012/11/28 19:19:13
Done.
|
+ void OnAdapterStateChanged(const AdapterState* state); |
+ |
+ static const int kPollIntervalMs; |
+ |
+ // Polling will be canceled when BluetoothPollingThread terminates. |
+ base::CancellationFlag cancellation_flag_; |
+ |
+ // Checks that PollAdapter runs on BluetoothPollingThread. |
+ base::ThreadChecker thread_checker_; |
+ |
+ // List of observers interested in event notifications from us. |
bryeung
2012/11/28 16:26:08
s/from us//
youngki
2012/11/28 19:19:13
Done.
|
+ ObserverList<Observer> observers_; |
+ |
+ // NOTE: This should remain the last member so it'll be destroyed and |
+ // invalidate its weak pointers before any other members are destroyed. |
+ base::WeakPtrFactory<BluetoothPollingThreadWin> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothPollingThreadWin); |
+}; |
+ |
+} // namespace device |
+ |
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ |