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..24adf4359086f2f2cd96a86a9bec19659d29bb7d |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_polling_thread_win.h |
@@ -0,0 +1,76 @@ |
+// 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/threading/thread.h" |
+ |
+namespace base { |
+ |
+class CancellationFlag; |
+class ThreadChecker; |
+ |
+} // namespace base |
+ |
+namespace device { |
+ |
+// A thread dedicated to perform blocking bluetooth APIs on Windows. |
+class BluetoothPollingThreadWin : public base::Thread { |
+ public: |
+ struct Properties { |
+ std::string name; |
+ std::string address; |
+ bool powered; |
+ }; |
keybuk
2012/11/26 18:36:13
Confused about this - it appears to "emulate" a D-
youngki
2012/11/26 23:01:26
Renamed this to AdapterState.
|
+ |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // This will always be called on the UI thread. |
+ virtual void AdapterPropertyChanged(const Properties& properties) {} |
+ }; |
+ |
+ BluetoothPollingThreadWin(); |
+ virtual ~BluetoothPollingThreadWin(); |
+ |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ void Init(); |
+ |
+ private: |
+ // Populates bluetooth adapter properties using adapter_handle. |
+ static void GetAdapterProperties(const HANDLE adapter_handle, |
+ Properties* properties); |
+ |
+ // Polls Windows Bluetooth API on BluetoothPollingThread. |
+ void PollAdapter(base::WeakPtr<BluetoothPollingThreadWin> weak_ptr); |
+ |
+ // Callback to be run on the UI thread. |
+ void OnAdapterPropertyChanged(const Properties* properties); |
+ |
+ static const int kPollIntervalMs; |
+ |
+ // Polling will be canceled when BluetoothPollingThread terminates. |
+ scoped_ptr<base::CancellationFlag> cancellation_flag_; |
+ |
+ // Checks that PollAdapter runs on BluetoothPollingThread. |
+ scoped_ptr<base::ThreadChecker> thread_checker_; |
+ |
+ // List of observers interested in event notifications from us. |
+ 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_ |