Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: device/bluetooth/bluetooth_discovery_session.cc

Issue 179123008: Migrate chrome.bluetooth API backend to use device::BluetoothDiscoverySession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved constructors around a bit. Gonna try this time. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) {
17 DCHECK(adapter_.get());
18 }
19
20 BluetoothDiscoverySession::BluetoothDiscoverySession()
21 : active_(false),
22 weak_ptr_factory_(this) {
16 } 23 }
17 24
18 BluetoothDiscoverySession::~BluetoothDiscoverySession() { 25 BluetoothDiscoverySession::~BluetoothDiscoverySession() {
26 if (!active_)
27 return;
28 DCHECK(adapter_.get());
19 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); 29 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
20 adapter_->DiscoverySessionDestroyed(this); 30 adapter_->DiscoverySessionDestroyed(this);
21 } 31 }
22 32
23 bool BluetoothDiscoverySession::IsActive() const { 33 bool BluetoothDiscoverySession::IsActive() const {
24 return active_; 34 return active_;
25 } 35 }
26 36
27 void BluetoothDiscoverySession::Stop( 37 void BluetoothDiscoverySession::Stop(
28 const base::Closure& callback, 38 const base::Closure& callback,
29 const ErrorCallback& error_callback) { 39 const ErrorCallback& error_callback) {
30 if (!active_) { 40 if (!active_) {
31 LOG(ERROR) << "Discovery session not active. Cannot stop."; 41 LOG(WARNING) << "Discovery session not active. Cannot stop.";
32 error_callback.Run(); 42 error_callback.Run();
33 return; 43 return;
34 } 44 }
35 VLOG(1) << "Stopping device discovery session."; 45 VLOG(1) << "Stopping device discovery session.";
46 DCHECK(adapter_.get());
36 adapter_->RemoveDiscoverySession( 47 adapter_->RemoveDiscoverySession(
37 base::Bind(&BluetoothDiscoverySession::OnStop, 48 base::Bind(&BluetoothDiscoverySession::OnStop,
38 weak_ptr_factory_.GetWeakPtr(), 49 weak_ptr_factory_.GetWeakPtr(),
39 callback), 50 callback),
40 error_callback); 51 error_callback);
41 } 52 }
42 53
43 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { 54 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) {
44 active_ = false; 55 active_ = false;
45 callback.Run(); 56 callback.Run();
46 } 57 }
47 58
48 void BluetoothDiscoverySession::MarkAsInactive() { 59 void BluetoothDiscoverySession::MarkAsInactive() {
49 active_ = false; 60 active_ = false;
50 } 61 }
51 62
52 } // namespace device 63 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_discovery_session.h ('k') | device/bluetooth/test/mock_bluetooth_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698