| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 // | 4 // | 
| 5 // TODO(youngki): Implement this file. | 5 // TODO(youngki): Implement this file. | 
| 6 | 6 | 
| 7 #include "device/bluetooth/bluetooth_adapter_win.h" | 7 #include "device/bluetooth/bluetooth_adapter_win.h" | 
| 8 | 8 | 
| 9 #include <string> | 9 #include <string> | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" | 
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" | 
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" | 
| 14 | 14 | 
| 15 namespace device { | 15 namespace device { | 
| 16 | 16 | 
| 17 BluetoothAdapterWin::BluetoothAdapterWin() | 17 BluetoothAdapterWin::BluetoothAdapterWin(const InitCallback& init_callback) | 
| 18     : BluetoothAdapter(), | 18     : BluetoothAdapter(), | 
|  | 19       init_callback_(init_callback), | 
|  | 20       initialized_(false), | 
| 19       powered_(false), | 21       powered_(false), | 
| 20       ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 22       ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 
| 21 } | 23 } | 
| 22 | 24 | 
| 23 BluetoothAdapterWin::~BluetoothAdapterWin() { | 25 BluetoothAdapterWin::~BluetoothAdapterWin() { | 
| 24   if (task_manager_) { | 26   if (task_manager_) { | 
| 25     task_manager_->RemoveObserver(this); | 27     task_manager_->RemoveObserver(this); | 
| 26     task_manager_->Shutdown(); | 28     task_manager_->Shutdown(); | 
| 27   } | 29   } | 
| 28 } | 30 } | 
| 29 | 31 | 
| 30 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { | 32 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { | 
| 31   DCHECK(observer); | 33   DCHECK(observer); | 
| 32   observers_.AddObserver(observer); | 34   observers_.AddObserver(observer); | 
| 33 } | 35 } | 
| 34 | 36 | 
| 35 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { | 37 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { | 
| 36   DCHECK(observer); | 38   DCHECK(observer); | 
| 37   observers_.RemoveObserver(observer); | 39   observers_.RemoveObserver(observer); | 
| 38 } | 40 } | 
| 39 | 41 | 
| 40 // TODO(youngki): Return true when |task_manager_| initializes the adapter | 42 // TODO(youngki): Return true when |task_manager_| initializes the adapter | 
| 41 // state. | 43 // state. | 
| 42 bool BluetoothAdapterWin::IsInitialized() const { | 44 bool BluetoothAdapterWin::IsInitialized() const { | 
| 43   return true; | 45   return initialized_; | 
| 44 } | 46 } | 
| 45 | 47 | 
| 46 bool BluetoothAdapterWin::IsPresent() const { | 48 bool BluetoothAdapterWin::IsPresent() const { | 
| 47   return !address_.empty(); | 49   return !address_.empty(); | 
| 48 } | 50 } | 
| 49 | 51 | 
| 50 bool BluetoothAdapterWin::IsPowered() const { | 52 bool BluetoothAdapterWin::IsPowered() const { | 
| 51   return powered_; | 53   return powered_; | 
| 52 } | 54 } | 
| 53 | 55 | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 91     const ErrorCallback& error_callback) { | 93     const ErrorCallback& error_callback) { | 
| 92   NOTIMPLEMENTED(); | 94   NOTIMPLEMENTED(); | 
| 93 } | 95 } | 
| 94 | 96 | 
| 95 void BluetoothAdapterWin::AdapterStateChanged( | 97 void BluetoothAdapterWin::AdapterStateChanged( | 
| 96     const BluetoothTaskManagerWin::AdapterState& state) { | 98     const BluetoothTaskManagerWin::AdapterState& state) { | 
| 97   DCHECK(thread_checker_.CalledOnValidThread()); | 99   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 98   name_ = state.name; | 100   name_ = state.name; | 
| 99   address_ = state.address; | 101   address_ = state.address; | 
| 100   powered_ = state.powered; | 102   powered_ = state.powered; | 
|  | 103   if (!initialized_) { | 
|  | 104     init_callback_.Run(); | 
|  | 105   } | 
|  | 106   initialized_ = true; | 
| 101 } | 107 } | 
| 102 | 108 | 
| 103 void BluetoothAdapterWin::TrackDefaultAdapter() { | 109 void BluetoothAdapterWin::TrackDefaultAdapter() { | 
| 104   task_manager_ = | 110   task_manager_ = | 
| 105       new BluetoothTaskManagerWin(base::ThreadTaskRunnerHandle::Get()); | 111       new BluetoothTaskManagerWin(base::ThreadTaskRunnerHandle::Get()); | 
| 106   task_manager_->AddObserver(this); | 112   task_manager_->AddObserver(this); | 
| 107   task_manager_->Initialize(); | 113   task_manager_->Initialize(); | 
| 108 } | 114 } | 
| 109 | 115 | 
| 110 }  // namespace device | 116 }  // namespace device | 
| OLD | NEW | 
|---|