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

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

Issue 975323002: Revert of Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
115 RegisterProfile(device->adapter(), success_callback, error_callback); 113 RegisterProfile(device->adapter(), success_callback, error_callback);
116 } 114 }
117 115
118 void BluetoothSocketChromeOS::Listen( 116 void BluetoothSocketChromeOS::Listen(
119 scoped_refptr<BluetoothAdapter> adapter, 117 scoped_refptr<BluetoothAdapter> adapter,
120 SocketType socket_type, 118 SocketType socket_type,
121 const BluetoothUUID& uuid, 119 const BluetoothUUID& uuid,
122 const BluetoothAdapter::ServiceOptions& service_options, 120 const BluetoothAdapter::ServiceOptions& service_options,
123 const base::Closure& success_callback, 121 const base::Closure& success_callback,
124 const ErrorCompletionCallback& error_callback) { 122 const ErrorCompletionCallback& error_callback) {
125 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 123 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
126 DCHECK(!profile_); 124 DCHECK(!profile_);
127 125
128 if (!uuid.IsValid()) { 126 if (!uuid.IsValid()) {
129 error_callback.Run(kInvalidUUID); 127 error_callback.Run(kInvalidUUID);
130 return; 128 return;
131 } 129 }
132 130
133 adapter_ = adapter; 131 adapter->AddObserver(this);
134 adapter_->AddObserver(this);
135 132
136 uuid_ = uuid; 133 uuid_ = uuid;
137 options_.reset(new BluetoothProfileManagerClient::Options()); 134 options_.reset(new BluetoothProfileManagerClient::Options());
138 if (service_options.name) 135 if (service_options.name)
139 options_->name.reset(new std::string(*service_options.name)); 136 options_->name.reset(new std::string(*service_options.name));
140 137
141 switch (socket_type) { 138 switch (socket_type) {
142 case kRfcomm: 139 case kRfcomm:
143 options_->channel.reset( 140 options_->channel.reset(
144 new uint16(service_options.channel ? *service_options.channel : 0)); 141 new uint16(service_options.channel ? *service_options.channel : 0));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 214 }
218 215
219 void BluetoothSocketChromeOS::RegisterProfile( 216 void BluetoothSocketChromeOS::RegisterProfile(
220 BluetoothAdapterChromeOS* adapter, 217 BluetoothAdapterChromeOS* adapter,
221 const base::Closure& success_callback, 218 const base::Closure& success_callback,
222 const ErrorCompletionCallback& error_callback) { 219 const ErrorCompletionCallback& error_callback) {
223 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 220 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
224 DCHECK(!profile_); 221 DCHECK(!profile_);
225 DCHECK(adapter); 222 DCHECK(adapter);
226 223
224 adapter_ = adapter;
225
227 // If the adapter is not present, this is a listening socket and the 226 // If the adapter is not present, this is a listening socket and the
228 // adapter isn't running yet. Report success and carry on; 227 // adapter isn't running yet. Report success and carry on;
229 // the profile will be registered when the daemon becomes available. 228 // the profile will be registered when the daemon becomes available.
230 if (!adapter->IsPresent()) { 229 if (!adapter_->IsPresent()) {
231 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 230 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
232 << ": Delaying profile registration."; 231 << ": Delaying profile registration.";
233 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); 232 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback);
234 return; 233 return;
235 } 234 }
236 235
237 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 236 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
238 << ": Acquiring profile."; 237 << ": Acquiring profile.";
239 238
240 adapter->UseProfile( 239 adapter->UseProfile(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 << error_message; 302 << error_message;
304 UnregisterProfile(); 303 UnregisterProfile();
305 error_callback.Run(error_message); 304 error_callback.Run(error_message);
306 } 305 }
307 306
308 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, 307 void BluetoothSocketChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter,
309 bool present) { 308 bool present) {
310 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 309 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
311 310
312 if (!present) { 311 if (!present) {
313 // Adapter removed, we can't use the profile anymore. 312 // Adapter removed, the profile is now invalid.
314 UnregisterProfile(); 313 UnregisterProfile();
315 return; 314 return;
316 } 315 }
317 316
318 DCHECK(!profile_); 317 DCHECK(!profile_);
319 318
320 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() 319 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value()
321 << ": Acquiring profile."; 320 << ": Acquiring profile.";
322 321
323 static_cast<BluetoothAdapterChromeOS*>(adapter)->UseProfile( 322 static_cast<BluetoothAdapterChromeOS*>(adapter)->UseProfile(
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 connection_request_queue_.pop(); 542 connection_request_queue_.pop();
544 } 543 }
545 } 544 }
546 545
547 void BluetoothSocketChromeOS::UnregisterProfile() { 546 void BluetoothSocketChromeOS::UnregisterProfile() {
548 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); 547 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
549 DCHECK(profile_); 548 DCHECK(profile_);
550 549
551 VLOG(1) << profile_->object_path().value() << ": Release profile"; 550 VLOG(1) << profile_->object_path().value() << ": Release profile";
552 551
553 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()) 552 profile_->RemoveDelegate(
554 ->ReleaseProfile(device_path_, profile_); 553 device_path_,
554 base::Bind(&BluetoothSocketChromeOS::ReleaseProfile, this, profile_));
555
555 profile_ = nullptr; 556 profile_ = nullptr;
556 } 557 }
557 558
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
558 } // namespace chromeos 568 } // 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