PlzNavigate: send history params at commit time to the renderer
[chromium-blink-merge.git] / device / bluetooth / bluetooth_discovery_session.cc
blobbfcc59f8a0c0fe2b9071af5288fb7d7a791cfe29
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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_discovery_session.h"
7 #include "base/bind.h"
8 #include "device/bluetooth/bluetooth_adapter.h"
10 namespace device {
12 BluetoothDiscoverySession::BluetoothDiscoverySession(
13 scoped_refptr<BluetoothAdapter> adapter)
14 : active_(true), adapter_(adapter), weak_ptr_factory_(this) {
15 DCHECK(adapter_.get());
18 BluetoothDiscoverySession::~BluetoothDiscoverySession() {
19 if (active_) {
20 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
21 MarkAsInactive();
25 bool BluetoothDiscoverySession::IsActive() const {
26 return active_;
29 void BluetoothDiscoverySession::Stop(
30 const base::Closure& callback,
31 const ErrorCallback& error_callback) {
32 if (!active_) {
33 LOG(WARNING) << "Discovery session not active. Cannot stop.";
34 error_callback.Run();
35 return;
37 VLOG(1) << "Stopping device discovery session.";
38 adapter_->RemoveDiscoverySession(
39 base::Bind(&BluetoothDiscoverySession::OnStop,
40 weak_ptr_factory_.GetWeakPtr(),
41 callback),
42 error_callback);
45 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) {
46 MarkAsInactive();
47 callback.Run();
50 void BluetoothDiscoverySession::MarkAsInactive() {
51 if (!active_)
52 return;
53 active_ = false;
54 adapter_->DiscoverySessionBecameInactive(this);
57 } // namespace device