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

Side by Side Diff: device/bluetooth/bluetooth_adapter.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
« no previous file with comments | « device/bluetooth/bluetooth_adapter.h ('k') | device/bluetooth/bluetooth_chromeos_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_adapter.h" 5 #include "device/bluetooth/bluetooth_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "device/bluetooth/bluetooth_device.h" 9 #include "device/bluetooth/bluetooth_device.h"
10 #include "device/bluetooth/bluetooth_discovery_session.h" 10 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 11 matching lines...) Expand all
22 void BluetoothAdapter::StartDiscoverySession( 22 void BluetoothAdapter::StartDiscoverySession(
23 const DiscoverySessionCallback& callback, 23 const DiscoverySessionCallback& callback,
24 const ErrorCallback& error_callback) { 24 const ErrorCallback& error_callback) {
25 AddDiscoverySession( 25 AddDiscoverySession(
26 base::Bind(&BluetoothAdapter::OnStartDiscoverySession, 26 base::Bind(&BluetoothAdapter::OnStartDiscoverySession,
27 weak_ptr_factory_.GetWeakPtr(), 27 weak_ptr_factory_.GetWeakPtr(),
28 callback), 28 callback),
29 error_callback); 29 error_callback);
30 } 30 }
31 31
32 void BluetoothAdapter::StartDiscovering(const base::Closure& callback,
33 const ErrorCallback& error_callback) {
34 AddDiscoverySession(callback, error_callback);
35 }
36
37 void BluetoothAdapter::StopDiscovering(const base::Closure& callback,
38 const ErrorCallback& error_callback) {
39 RemoveDiscoverySession(callback, error_callback);
40 }
41
42 BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { 32 BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() {
43 ConstDeviceList const_devices = 33 ConstDeviceList const_devices =
44 const_cast<const BluetoothAdapter *>(this)->GetDevices(); 34 const_cast<const BluetoothAdapter *>(this)->GetDevices();
45 35
46 DeviceList devices; 36 DeviceList devices;
47 for (ConstDeviceList::const_iterator i = const_devices.begin(); 37 for (ConstDeviceList::const_iterator i = const_devices.begin();
48 i != const_devices.end(); ++i) 38 i != const_devices.end(); ++i)
49 devices.push_back(const_cast<BluetoothDevice *>(*i)); 39 devices.push_back(const_cast<BluetoothDevice *>(*i));
50 40
51 return devices; 41 return devices;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 discovery_sessions_.insert(discovery_session.get()); 107 discovery_sessions_.insert(discovery_session.get());
118 callback.Run(discovery_session.Pass()); 108 callback.Run(discovery_session.Pass());
119 } 109 }
120 110
121 void BluetoothAdapter::MarkDiscoverySessionsAsInactive() { 111 void BluetoothAdapter::MarkDiscoverySessionsAsInactive() {
122 for (std::set<BluetoothDiscoverySession*>::iterator 112 for (std::set<BluetoothDiscoverySession*>::iterator
123 iter = discovery_sessions_.begin(); 113 iter = discovery_sessions_.begin();
124 iter != discovery_sessions_.end(); ++iter) { 114 iter != discovery_sessions_.end(); ++iter) {
125 (*iter)->MarkAsInactive(); 115 (*iter)->MarkAsInactive();
126 } 116 }
117 // At this point, all sessions have been marked as inactive. Just remove them
118 // from our list as they are no longer relevant.
119 discovery_sessions_.clear();
keybuk 2014/03/06 18:42:36 This seems to contradict the comment in the header
armansito 2014/03/06 23:55:48 Well, it doesn't really contradict it, as discover
keybuk 2014/03/06 23:57:39 because we're dealing with object lifetime, I thin
armansito 2014/03/07 19:22:16 Actually they weren't removed when an individual o
127 } 120 }
128 121
129 void BluetoothAdapter::DiscoverySessionDestroyed( 122 void BluetoothAdapter::DiscoverySessionDestroyed(
130 BluetoothDiscoverySession* discovery_session) { 123 BluetoothDiscoverySession* discovery_session) {
131 discovery_sessions_.erase(discovery_session); 124 discovery_sessions_.erase(discovery_session);
132 } 125 }
133 126
134 } // namespace device 127 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter.h ('k') | device/bluetooth/bluetooth_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698