Index: device/bluetooth/bluetooth_task_manager_win.cc |
diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b9b0be95fe87992c2ea8a3b331b7a6d01041d066 |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_task_manager_win.cc |
@@ -0,0 +1,53 @@ |
+// 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. |
+ |
+#include "device/bluetooth/bluetooth_task_manager_win.h" |
+ |
+#include "base/bind.h" |
+#include "base/message_loop.h" |
+#include "device/bluetooth/bluetooth_polling_thread_win.h" |
+ |
+namespace device { |
+ |
+BluetoothTaskManagerWin::BluetoothTaskManagerWin() |
+ : ui_message_loop_(MessageLoop::current()), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(thread_(this)) { |
+ DCHECK(ui_message_loop_); |
+ DCHECK(ui_message_loop_->type() == MessageLoop::TYPE_UI); |
bryeung
2012/12/10 19:51:28
why have you switched to checking the message loop
youngki
2012/12/17 17:17:23
I was following the existing patterns from other f
|
+} |
+ |
+BluetoothTaskManagerWin::~BluetoothTaskManagerWin() { |
+} |
+ |
+void BluetoothTaskManagerWin::AddObserver(Observer* observer) { |
+ CHECK(observer); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void BluetoothTaskManagerWin::RemoveObserver(Observer* observer) { |
+ CHECK(observer); |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+void BluetoothTaskManagerWin::StartThread() { |
bryeung
2012/12/10 19:51:28
CHECKing for thread here would be good
youngki
2012/12/17 17:17:23
Done.
|
+ if (!thread_.message_loop()) { |
+ thread_.Start(); |
bryeung
2012/12/10 19:51:28
can thread_.Start() be overridden so that it posts
youngki
2012/12/17 17:17:23
Thread::Start() is not virtual, but I added Blueto
|
+ thread_.message_loop()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BluetoothPollingThreadWin::PollAdapter, |
+ base::Unretained(&thread_))); |
+ } |
+} |
+ |
+void BluetoothTaskManagerWin::StopThread() { |
bryeung
2012/12/10 19:51:28
CHECKing for thread here would be good
youngki
2012/12/17 17:17:23
Done.
|
+ thread_.Cancel(); |
+} |
+ |
+void BluetoothTaskManagerWin::OnAdapterStateChanged(const AdapterState* state) { |
+ DCHECK_EQ(ui_message_loop_, MessageLoop::current()); |
+ FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, |
+ AdapterStateChanged(*state)); |
+} |
+ |
+} // namespace device |