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

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

Issue 935383003: Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for leak detected by LSAN Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_socket_chromeos.h" 5 #include "device/bluetooth/bluetooth_socket_chromeos.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return; 103 return;
104 } 104 }
105 105
106 device_address_ = device->GetAddress(); 106 device_address_ = device->GetAddress();
107 device_path_ = device->object_path(); 107 device_path_ = device->object_path();
108 uuid_ = uuid; 108 uuid_ = uuid;
109 options_.reset(new BluetoothProfileManagerClient::Options()); 109 options_.reset(new BluetoothProfileManagerClient::Options());
110 if (security_level == SECURITY_LEVEL_LOW) 110 if (security_level == SECURITY_LEVEL_LOW)
111 options_->require_authentication.reset(new bool(false)); 111 options_->require_authentication.reset(new bool(false));
112 112
113 adapter_ = device->adapter();
114
113 RegisterProfile(device->adapter(), success_callback, error_callback); 115 RegisterProfile(device->adapter(), success_callback, error_callback);
114 } 116 }
115 117
116 void BluetoothSocketChromeOS::Listen( 118 void BluetoothSocketChromeOS::Listen(
117 scoped_refptr<BluetoothAdapter> adapter, 119 scoped_refptr<BluetoothAdapter> adapter,
118 SocketType socket_type, 120 SocketType socket_type,
119 const BluetoothUUID& uuid, 121 const BluetoothUUID& uuid,
120 const BluetoothAdapter::ServiceOptions& service_options, 122 const BluetoothAdapter::ServiceOptions& service_options,
121 const base::Closure& success_callback, 123 const base::Closure& success_callback,
122 const ErrorCompletionCallback& error_callback) { 124 const ErrorCompletionCallback& error_callback) {
123 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 125 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
124 DCHECK(!profile_); 126 DCHECK(!profile_);
125 127
126 if (!uuid.IsValid()) { 128 if (!uuid.IsValid()) {
127 error_callback.Run(kInvalidUUID); 129 error_callback.Run(kInvalidUUID);
128 return; 130 return;
129 } 131 }
130 132
131 adapter->AddObserver(this); 133 adapter_ = adapter;
134 adapter_->AddObserver(this);
132 135
133 uuid_ = uuid; 136 uuid_ = uuid;
134 options_.reset(new BluetoothProfileManagerClient::Options()); 137 options_.reset(new BluetoothProfileManagerClient::Options());
135 if (service_options.name) 138 if (service_options.name)
136 options_->name.reset(new std::string(*service_options.name)); 139 options_->name.reset(new std::string(*service_options.name));
137 140
138 switch (socket_type) { 141 switch (socket_type) {
139 case kRfcomm: 142 case kRfcomm:
140 options_->channel.reset( 143 options_->channel.reset(
141 new uint16(service_options.channel ? *service_options.channel : 0)); 144 new uint16(service_options.channel ? *service_options.channel : 0));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 217 }
215 218
216 void BluetoothSocketChromeOS::RegisterProfile( 219 void BluetoothSocketChromeOS::RegisterProfile(
217 BluetoothAdapterChromeOS* adapter, 220 BluetoothAdapterChromeOS* adapter,
218 const base::Closure& success_callback, 221 const base::Closure& success_callback,
219 const ErrorCompletionCallback& error_callback) { 222 const ErrorCompletionCallback& error_callback) {
220 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 223 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
221 DCHECK(!profile_); 224 DCHECK(!profile_);
222 DCHECK(adapter); 225 DCHECK(adapter);
223 226
224 adapter_ = adapter;
225
226 // If the adapter is not present, this is a listening socket and the 227 // If the adapter is not present, this is a listening socket and the
227 // adapter isn't running yet. Report success and carry on; 228 // adapter isn't running yet. Report success and carry on;
228 // the profile will be registered when the daemon becomes available. 229 // the profile will be registered when the daemon becomes available.
229 if (!adapter_->IsPresent()) { 230 if (!adapter->IsPresent()) {
230 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 231 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
231 << ": Delaying profile registration."; 232 << ": Delaying profile registration.";
232 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); 233 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback);
233 return; 234 return;
234 } 235 }
235 236
236 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 237 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
237 << ": Acquiring profile."; 238 << ": Acquiring profile.";
238 239
239 adapter->UseProfile( 240 adapter->UseProfile(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 << error_message; 303 << error_message;
303 UnregisterProfile(); 304 UnregisterProfile();
304 error_callback.Run(error_message); 305 error_callback.Run(error_message);
305 } 306 }
306 307
307 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, 308 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter,
308 bool present) { 309 bool present) {
309 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 310 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
310 311
311 if (!present) { 312 if (!present) {
312 // Adapter removed, the profile is now invalid. 313 // Adapter removed, we can't use the profile anymore.
313 UnregisterProfile(); 314 UnregisterProfile();
314 return; 315 return;
315 } 316 }
316 317
317 DCHECK(!profile_); 318 DCHECK(!profile_);
318 319
319 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 320 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
320 << ": Acquiring profile."; 321 << ": Acquiring profile.";
321 322
322 static_cast<BluetoothAdapterChromeOS*>(adapter)->UseProfile( 323 static_cast<BluetoothAdapterChromeOS*>(adapter)->UseProfile(
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 connection_request_queue_.pop(); 543 connection_request_queue_.pop();
543 } 544 }
544 } 545 }
545 546
546 void BluetoothSocketChromeOS::UnregisterProfile() { 547 void BluetoothSocketChromeOS::UnregisterProfile() {
547 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 548 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
548 DCHECK(profile_); 549 DCHECK(profile_);
549 550
550 VLOG(1) << profile_->object_path().value() << ": Release profile"; 551 VLOG(1) << profile_->object_path().value() << ": Release profile";
551 552
552 profile_->RemoveDelegate( 553 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())
553 device_path_, 554 ->ReleaseProfile(device_path_, profile_);
554 base::Bind(&BluetoothSocketChromeOS::ReleaseProfile, this, profile_));
555
556 profile_ = nullptr; 555 profile_ = nullptr;
557 } 556 }
558 557
559 void BluetoothSocketChromeOS::ReleaseProfile(
560 BluetoothAdapterProfileChromeOS* profile) {
561 if (adapter_)
562 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())
563 ->ReleaseProfile(uuid_);
564 else
565 delete profile;
566 }
567
568 } // namespace chromeos 558 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_socket_chromeos.h ('k') | device/bluetooth/bluetooth_socket_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698