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

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

Issue 188473002: device/bluetooth: Remove BluetoothAdapter::Start|StopDiscovering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed potential invalid access in BluetoothDiscoverySession destructor. 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( 12 BluetoothDiscoverySession::BluetoothDiscoverySession(
13 scoped_refptr<BluetoothAdapter> adapter) 13 scoped_refptr<BluetoothAdapter> adapter)
14 : active_(true), 14 : active_(true),
15 adapter_(adapter), 15 adapter_(adapter),
16 weak_ptr_factory_(this) { 16 weak_ptr_factory_(this) {
17 DCHECK(adapter_.get()); 17 DCHECK(adapter_.get());
18 } 18 }
19 19
20 BluetoothDiscoverySession::BluetoothDiscoverySession() 20 BluetoothDiscoverySession::BluetoothDiscoverySession()
21 : active_(false), 21 : active_(false),
22 weak_ptr_factory_(this) { 22 weak_ptr_factory_(this) {
23 } 23 }
24 24
25 BluetoothDiscoverySession::~BluetoothDiscoverySession() { 25 BluetoothDiscoverySession::~BluetoothDiscoverySession() {
26 if (!active_) 26 // |adapter_| may be NULL if this instance was initialized as a mock.
27 if (!adapter_.get()) {
28 DCHECK(!active_);
27 return; 29 return;
28 DCHECK(adapter_.get()); 30 }
29 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); 31 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
30 adapter_->DiscoverySessionDestroyed(this); 32 adapter_->DiscoverySessionDestroyed(this);
31 } 33 }
32 34
33 bool BluetoothDiscoverySession::IsActive() const { 35 bool BluetoothDiscoverySession::IsActive() const {
34 return active_; 36 return active_;
35 } 37 }
36 38
37 void BluetoothDiscoverySession::Stop( 39 void BluetoothDiscoverySession::Stop(
38 const base::Closure& callback, 40 const base::Closure& callback,
(...skipping 15 matching lines...) Expand all
54 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { 56 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) {
55 active_ = false; 57 active_ = false;
56 callback.Run(); 58 callback.Run();
57 } 59 }
58 60
59 void BluetoothDiscoverySession::MarkAsInactive() { 61 void BluetoothDiscoverySession::MarkAsInactive() {
60 active_ = false; 62 active_ = false;
61 } 63 }
62 64
63 } // namespace device 65 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698