| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "device/bluetooth/bluetooth_discovery_session.h" | 5 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "device/bluetooth/bluetooth_adapter.h" | 8 #include "device/bluetooth/bluetooth_adapter.h" |
| 9 | 9 |
| 10 namespace device { | 10 namespace device { |
| 11 | 11 |
| 12 BluetoothDiscoverySession::BluetoothDiscoverySession(BluetoothAdapter* adapter) | 12 BluetoothDiscoverySession::BluetoothDiscoverySession( |
| 13 scoped_refptr<BluetoothAdapter> adapter) |
| 13 : active_(true), | 14 : active_(true), |
| 14 adapter_(adapter), | 15 adapter_(adapter), |
| 15 weak_ptr_factory_(this) { | 16 weak_ptr_factory_(this) { |
| 16 } | 17 } |
| 17 | 18 |
| 18 BluetoothDiscoverySession::~BluetoothDiscoverySession() { | 19 BluetoothDiscoverySession::~BluetoothDiscoverySession() { |
| 19 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 20 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 21 DCHECK(adapter_.get()); |
| 20 adapter_->DiscoverySessionDestroyed(this); | 22 adapter_->DiscoverySessionDestroyed(this); |
| 21 } | 23 } |
| 22 | 24 |
| 23 void BluetoothDiscoverySession::Stop( | 25 void BluetoothDiscoverySession::Stop( |
| 24 const base::Closure& callback, | 26 const base::Closure& callback, |
| 25 const ErrorCallback& error_callback) { | 27 const ErrorCallback& error_callback) { |
| 26 if (!active_) { | 28 if (!active_) { |
| 27 LOG(ERROR) << "Discovery session not active. Cannot stop."; | 29 LOG(WARNING) << "Discovery session not active. Cannot stop."; |
| 28 error_callback.Run(); | 30 error_callback.Run(); |
| 29 return; | 31 return; |
| 30 } | 32 } |
| 31 VLOG(1) << "Stopping device discovery session."; | 33 VLOG(1) << "Stopping device discovery session."; |
| 34 DCHECK(adapter_.get()); |
| 32 adapter_->RemoveDiscoverySession( | 35 adapter_->RemoveDiscoverySession( |
| 33 base::Bind(&BluetoothDiscoverySession::OnStop, | 36 base::Bind(&BluetoothDiscoverySession::OnStop, |
| 34 weak_ptr_factory_.GetWeakPtr(), | 37 weak_ptr_factory_.GetWeakPtr(), |
| 35 callback), | 38 callback), |
| 36 error_callback); | 39 error_callback); |
| 37 } | 40 } |
| 38 | 41 |
| 39 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { | 42 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { |
| 40 active_ = false; | 43 active_ = false; |
| 41 callback.Run(); | 44 callback.Run(); |
| 42 } | 45 } |
| 43 | 46 |
| 44 void BluetoothDiscoverySession::MarkAsInactive() { | 47 void BluetoothDiscoverySession::MarkAsInactive() { |
| 45 active_ = false; | 48 active_ = false; |
| 46 } | 49 } |
| 47 | 50 |
| 48 } // namespace device | 51 } // namespace device |
| OLD | NEW |