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

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 BluetoothAdapterWinTest compile errors. 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), adapter_(adapter), weak_ptr_factory_(this) { 14 : active_(true), adapter_(adapter), weak_ptr_factory_(this) {
15 DCHECK(adapter_.get()); 15 DCHECK(adapter_.get());
16 } 16 }
17 17
18 BluetoothDiscoverySession::BluetoothDiscoverySession() 18 BluetoothDiscoverySession::BluetoothDiscoverySession()
19 : active_(false), weak_ptr_factory_(this) {} 19 : active_(false), weak_ptr_factory_(this) {}
20 20
21 BluetoothDiscoverySession::~BluetoothDiscoverySession() { 21 BluetoothDiscoverySession::~BluetoothDiscoverySession() {
22 // |adapter_| may be NULL if this instance was initialized as a mock. 22 // |adapter_| may be NULL if this instance was initialized as a mock.
23 if (!adapter_.get()) { 23 if (!adapter_.get()) {
24 DCHECK(!active_); 24 DCHECK(!active_);
25 return; 25 return;
26 } 26 }
27 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); 27 Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
28 adapter_->DiscoverySessionDestroyed(this); 28 MarkAsInactive();
29 } 29 }
30 30
31 bool BluetoothDiscoverySession::IsActive() const { 31 bool BluetoothDiscoverySession::IsActive() const {
32 return active_; 32 return active_;
33 } 33 }
34 34
35 void BluetoothDiscoverySession::Stop( 35 void BluetoothDiscoverySession::Stop(
36 const base::Closure& callback, 36 const base::Closure& callback,
37 const ErrorCallback& error_callback) { 37 const ErrorCallback& error_callback) {
38 if (!active_) { 38 if (!active_) {
39 LOG(WARNING) << "Discovery session not active. Cannot stop."; 39 LOG(WARNING) << "Discovery session not active. Cannot stop.";
40 error_callback.Run(); 40 error_callback.Run();
41 return; 41 return;
42 } 42 }
43 VLOG(1) << "Stopping device discovery session."; 43 VLOG(1) << "Stopping device discovery session.";
44 DCHECK(adapter_.get()); 44 DCHECK(adapter_.get());
45 adapter_->RemoveDiscoverySession( 45 adapter_->RemoveDiscoverySession(
46 base::Bind(&BluetoothDiscoverySession::OnStop, 46 base::Bind(&BluetoothDiscoverySession::OnStop,
47 weak_ptr_factory_.GetWeakPtr(), 47 weak_ptr_factory_.GetWeakPtr(),
48 callback), 48 callback),
49 error_callback); 49 error_callback);
50 } 50 }
51 51
52 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) { 52 void BluetoothDiscoverySession::OnStop(const base::Closure& callback) {
53 active_ = false; 53 MarkAsInactive();
54 callback.Run(); 54 callback.Run();
55 } 55 }
56 56
57 void BluetoothDiscoverySession::MarkAsInactive() { 57 void BluetoothDiscoverySession::MarkAsInactive() {
58 if (!active_)
59 return;
58 active_ = false; 60 active_ = false;
61 DCHECK(adapter_.get());
62 adapter_->DiscoverySessionBecameInactive(this);
59 } 63 }
60 64
61 } // namespace device 65 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_chromeos_unittest.cc ('k') | device/bluetooth/test/mock_bluetooth_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698