OLD | NEW |
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 const base::Closure& success_callback, | 121 const base::Closure& success_callback, |
122 const ErrorCompletionCallback& error_callback) { | 122 const ErrorCompletionCallback& error_callback) { |
123 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 123 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
124 DCHECK(!profile_); | 124 DCHECK(!profile_); |
125 | 125 |
126 if (!uuid.IsValid()) { | 126 if (!uuid.IsValid()) { |
127 error_callback.Run(kInvalidUUID); | 127 error_callback.Run(kInvalidUUID); |
128 return; | 128 return; |
129 } | 129 } |
130 | 130 |
131 adapter_ = adapter; | 131 adapter->AddObserver(this); |
132 adapter_->AddObserver(this); | |
133 | 132 |
134 uuid_ = uuid; | 133 uuid_ = uuid; |
135 options_.reset(new BluetoothProfileManagerClient::Options()); | 134 options_.reset(new BluetoothProfileManagerClient::Options()); |
136 if (service_options.name) | 135 if (service_options.name) |
137 options_->name.reset(new std::string(*service_options.name)); | 136 options_->name.reset(new std::string(*service_options.name)); |
138 | 137 |
139 switch (socket_type) { | 138 switch (socket_type) { |
140 case kRfcomm: | 139 case kRfcomm: |
141 options_->channel.reset( | 140 options_->channel.reset( |
142 new uint16(service_options.channel ? *service_options.channel : 0)); | 141 new uint16(service_options.channel ? *service_options.channel : 0)); |
143 break; | 142 break; |
144 case kL2cap: | 143 case kL2cap: |
145 options_->psm.reset( | 144 options_->psm.reset( |
146 new uint16(service_options.psm ? *service_options.psm : 0)); | 145 new uint16(service_options.psm ? *service_options.psm : 0)); |
147 break; | 146 break; |
148 default: | 147 default: |
149 NOTREACHED(); | 148 NOTREACHED(); |
150 } | 149 } |
151 | 150 |
152 RegisterProfile(static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), | 151 RegisterProfile(static_cast<BluetoothAdapterChromeOS*>(adapter.get()), |
153 success_callback, error_callback); | 152 success_callback, error_callback); |
154 } | 153 } |
155 | 154 |
156 void BluetoothSocketChromeOS::Close() { | 155 void BluetoothSocketChromeOS::Close() { |
157 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 156 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
158 | 157 |
159 if (profile_) | 158 if (profile_) |
160 UnregisterProfile(); | 159 UnregisterProfile(); |
161 | 160 |
162 // In the case below, where an asynchronous task gets posted on the socket | 161 // In the case below, where an asynchronous task gets posted on the socket |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 214 } |
216 | 215 |
217 void BluetoothSocketChromeOS::RegisterProfile( | 216 void BluetoothSocketChromeOS::RegisterProfile( |
218 BluetoothAdapterChromeOS* adapter, | 217 BluetoothAdapterChromeOS* adapter, |
219 const base::Closure& success_callback, | 218 const base::Closure& success_callback, |
220 const ErrorCompletionCallback& error_callback) { | 219 const ErrorCompletionCallback& error_callback) { |
221 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 220 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
222 DCHECK(!profile_); | 221 DCHECK(!profile_); |
223 DCHECK(adapter); | 222 DCHECK(adapter); |
224 | 223 |
| 224 adapter_ = adapter; |
| 225 |
225 // 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 |
226 // adapter isn't running yet. Report success and carry on; | 227 // adapter isn't running yet. Report success and carry on; |
227 // the profile will be registered when the daemon becomes available. | 228 // the profile will be registered when the daemon becomes available. |
228 if (!adapter->IsPresent()) { | 229 if (!adapter_->IsPresent()) { |
229 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() | 230 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() |
230 << ": Delaying profile registration."; | 231 << ": Delaying profile registration."; |
231 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); | 232 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); |
232 return; | 233 return; |
233 } | 234 } |
234 | 235 |
235 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() | 236 VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() |
236 << ": Acquiring profile."; | 237 << ": Acquiring profile."; |
237 | 238 |
238 adapter->UseProfile( | 239 adapter->UseProfile( |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 void BluetoothSocketChromeOS::ReleaseProfile( | 559 void BluetoothSocketChromeOS::ReleaseProfile( |
559 BluetoothAdapterProfileChromeOS* profile) { | 560 BluetoothAdapterProfileChromeOS* profile) { |
560 if (adapter_) | 561 if (adapter_) |
561 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()) | 562 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()) |
562 ->ReleaseProfile(uuid_); | 563 ->ReleaseProfile(uuid_); |
563 else | 564 else |
564 delete profile; | 565 delete profile; |
565 } | 566 } |
566 | 567 |
567 } // namespace chromeos | 568 } // namespace chromeos |
OLD | NEW |