| 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( | 12 BluetoothDiscoverySession::BluetoothDiscoverySession(BluetoothAdapter* adapter) |
| 13 scoped_refptr<BluetoothAdapter> adapter) | |
| 14 : active_(true), | 13 : active_(true), |
| 15 adapter_(adapter), | 14 adapter_(adapter), |
| 16 weak_ptr_factory_(this) { | 15 weak_ptr_factory_(this) { |
| 17 DCHECK(adapter_.get()); | |
| 18 } | |
| 19 | |
| 20 BluetoothDiscoverySession::BluetoothDiscoverySession() | |
| 21 : active_(false), | |
| 22 weak_ptr_factory_(this) { | |
| 23 } | 16 } |
| 24 | 17 |
| 25 BluetoothDiscoverySession::~BluetoothDiscoverySession() { | 18 BluetoothDiscoverySession::~BluetoothDiscoverySession() { |
| 26 if (!active_) | |
| 27 return; | |
| 28 DCHECK(adapter_.get()); | |
| 29 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 19 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 30 adapter_->DiscoverySessionDestroyed(this); | 20 adapter_->DiscoverySessionDestroyed(this); |
| 31 } | 21 } |
| 32 | 22 |
| 33 bool BluetoothDiscoverySession::IsActive() const { | 23 bool BluetoothDiscoverySession::IsActive() const { |
| 34 return active_; | 24 return active_; |
| 35 } | 25 } |
| 36 | 26 |
| 37 void BluetoothDiscoverySession::Stop( | 27 void BluetoothDiscoverySession::Stop( |
| 38 const base::Closure& callback, | 28 const base::Closure& callback, |
| 39 const ErrorCallback& error_callback) { | 29 const ErrorCallback& error_callback) { |
| 40 if (!active_) { | 30 if (!active_) { |
| 41 LOG(WARNING) << "Discovery session not active. Cannot stop."; | 31 LOG(ERROR) << "Discovery session not active. Cannot stop."; |
| 42 error_callback.Run(); | 32 error_callback.Run(); |
| 43 return; | 33 return; |
| 44 } | 34 } |
| 45 VLOG(1) << "Stopping device discovery session."; | 35 VLOG(1) << "Stopping device discovery session."; |
| 46 DCHECK(adapter_.get()); | |
| 47 adapter_->RemoveDiscoverySession( | 36 adapter_->RemoveDiscoverySession( |
| 48 base::Bind(&BluetoothDiscoverySession::OnStop, | 37 base::Bind(&BluetoothDiscoverySession::OnStop, |
| 49 weak_ptr_factory_.GetWeakPtr(), | 38 weak_ptr_factory_.GetWeakPtr(), |
| 50 callback), | 39 callback), |
| 51 error_callback); | 40 error_callback); |
| 52 } | 41 } |
| 53 | 42 |
| 54 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { | 43 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { |
| 55 active_ = false; | 44 active_ = false; |
| 56 callback.Run(); | 45 callback.Run(); |
| 57 } | 46 } |
| 58 | 47 |
| 59 void BluetoothDiscoverySession::MarkAsInactive() { | 48 void BluetoothDiscoverySession::MarkAsInactive() { |
| 60 active_ = false; | 49 active_ = false; |
| 61 } | 50 } |
| 62 | 51 |
| 63 } // namespace device | 52 } // namespace device |
| OLD | NEW |