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

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

Issue 939753004: device/bluetooth: Implement Unregister() of BlueotoothAudioSinkChromeOS and disconnection-related c… (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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_audio_sink_chromeos.h" 5 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h"
6 6
7 #include <algorithm>
7 #include <sstream> 8 #include <sstream>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/debug/stack_trace.h" 11 #include "base/debug/stack_trace.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "dbus/message.h" 14 #include "dbus/message.h"
14 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
15 16
17 using dbus::ObjectPath;
18 using device::BluetoothAudioSink;
19
16 namespace { 20 namespace {
17 21
18 // TODO(mcchou): Add the constant to dbus/service_constants.h. 22 // TODO(mcchou): Add the constant to dbus/service_constants.h.
19 const char kBluetoothAudioSinkServicePath[] = "/org/chromium/AudioSink"; 23 const char kBluetoothAudioSinkServicePath[] = "/org/chromium/AudioSink";
20 24
21 dbus::ObjectPath GenerateEndpointPath() { 25 ObjectPath GenerateEndpointPath() {
22 static unsigned int sequence_number = 0; 26 static unsigned int sequence_number = 0;
23 ++sequence_number; 27 ++sequence_number;
24 std::stringstream path; 28 std::stringstream path;
25 path << kBluetoothAudioSinkServicePath << "/endpoint" << sequence_number; 29 path << kBluetoothAudioSinkServicePath << "/endpoint" << sequence_number;
26 return dbus::ObjectPath(path.str()); 30 return ObjectPath(path.str());
31 }
32
33 // A dummy error callback for calling Unregister() in destructor.
34 void UnregisterErrorCallback(
35 device::BluetoothAudioSink::ErrorCode error_code) {
36 VLOG(1) << "Bluetooth audio sink: Error code: " << error_code;
27 } 37 }
28 38
29 } // namespace 39 } // namespace
30 40
31 namespace chromeos { 41 namespace chromeos {
32 42
33 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS( 43 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS(
34 scoped_refptr<device::BluetoothAdapter> adapter) 44 scoped_refptr<device::BluetoothAdapter> adapter)
35 : state_(device::BluetoothAudioSink::STATE_INVALID), 45 : state_(BluetoothAudioSink::STATE_INVALID),
36 volume_(0), 46 volume_(BluetoothAudioSink::kInvalidVolume),
37 read_mtu_(0), 47 read_mtu_(nullptr),
38 write_mtu_(0), 48 write_mtu_(nullptr),
39 adapter_(adapter), 49 adapter_(adapter),
40 weak_ptr_factory_(this) { 50 weak_ptr_factory_(this) {
41 DCHECK(adapter_.get()); 51 DCHECK(adapter_.get());
42 DCHECK(adapter_->IsPresent()); 52 DCHECK(adapter_->IsPresent());
43 53
44 adapter_->AddObserver(this); 54 adapter_->AddObserver(this);
45 55
46 chromeos::BluetoothMediaClient* media = 56 chromeos::BluetoothMediaClient* media =
47 DBusThreadManager::Get()->GetBluetoothMediaClient(); 57 DBusThreadManager::Get()->GetBluetoothMediaClient();
48 DCHECK(media); 58 DCHECK(media);
49 media->AddObserver(this); 59 media->AddObserver(this);
50 60
51 chromeos::BluetoothMediaTransportClient *transport = 61 chromeos::BluetoothMediaTransportClient *transport =
52 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); 62 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient();
53 DCHECK(transport); 63 DCHECK(transport);
54 transport->AddObserver(this); 64 transport->AddObserver(this);
55 65
56 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); 66 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED);
57 } 67 }
58 68
59 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() { 69 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() {
60 DCHECK(adapter_.get()); 70 DCHECK(adapter_.get());
71
72 if (state_ != BluetoothAudioSink::STATE_INVALID && media_endpoint_.get()) {
73 Unregister(base::Bind(&base::DoNothing),
74 base::Bind(&UnregisterErrorCallback));
75 }
76
61 adapter_->RemoveObserver(this); 77 adapter_->RemoveObserver(this);
62 78
63 chromeos::BluetoothMediaClient* media = 79 chromeos::BluetoothMediaClient* media =
64 DBusThreadManager::Get()->GetBluetoothMediaClient(); 80 DBusThreadManager::Get()->GetBluetoothMediaClient();
65 DCHECK(media); 81 DCHECK(media);
66 media->RemoveObserver(this); 82 media->RemoveObserver(this);
67 83
68 chromeos::BluetoothMediaTransportClient *transport = 84 chromeos::BluetoothMediaTransportClient *transport =
69 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); 85 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient();
70 DCHECK(transport); 86 DCHECK(transport);
71 transport->RemoveObserver(this); 87 transport->RemoveObserver(this);
72
73 // TODO(mcchou): BUG=441581
74 // Unregister() should be called while media and media endpoint are still
75 // valid.
76 } 88 }
77 89
78 void BluetoothAudioSinkChromeOS::Unregister( 90 void BluetoothAudioSinkChromeOS::Unregister(
79 const base::Closure& callback, 91 const base::Closure& callback,
80 const device::BluetoothAudioSink::ErrorCallback& error_callback) { 92 const device::BluetoothAudioSink::ErrorCallback& error_callback) {
81 // TODO(mcchou): BUG=441581 93 if (!DBusThreadManager::IsInitialized())
82 // Call UnregisterEndpoint on the media object with |media_path_| and clean 94 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED);
83 // |observers_| and transport_path_ and reset state_ and volume. 95
84 // Check whether the media endpoint is registered before invoking 96 chromeos::BluetoothMediaClient* media =
85 // UnregisterEndpoint. 97 DBusThreadManager::Get()->GetBluetoothMediaClient();
98 DCHECK(media);
99
100 media->UnregisterEndpoint(
101 media_path_,
102 endpoint_path_,
103 base::Bind(&BluetoothAudioSinkChromeOS::OnUnregisterSucceeded,
104 weak_ptr_factory_.GetWeakPtr(), callback),
105 base::Bind(&BluetoothAudioSinkChromeOS::OnUnregisterFailed,
106 weak_ptr_factory_.GetWeakPtr(), error_callback));
86 } 107 }
87 108
88 void BluetoothAudioSinkChromeOS::AddObserver( 109 void BluetoothAudioSinkChromeOS::AddObserver(
89 device::BluetoothAudioSink::Observer* observer) { 110 BluetoothAudioSink::Observer* observer) {
90 DCHECK(observer); 111 DCHECK(observer);
91 observers_.AddObserver(observer); 112 observers_.AddObserver(observer);
92 } 113 }
93 114
94 void BluetoothAudioSinkChromeOS::RemoveObserver( 115 void BluetoothAudioSinkChromeOS::RemoveObserver(
95 device::BluetoothAudioSink::Observer* observer) { 116 BluetoothAudioSink::Observer* observer) {
96 DCHECK(observer); 117 DCHECK(observer);
97 observers_.RemoveObserver(observer); 118 observers_.RemoveObserver(observer);
98 } 119 }
99 120
100 device::BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const { 121 BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const {
101 return state_; 122 return state_;
102 } 123 }
103 124
104 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const { 125 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const {
105 return volume_; 126 return volume_;
106 } 127 }
107 128
108 void BluetoothAudioSinkChromeOS::AdapterPresentChanged( 129 void BluetoothAudioSinkChromeOS::AdapterPresentChanged(
109 device::BluetoothAdapter* adapter, 130 device::BluetoothAdapter* adapter, bool present) {
110 bool present) {
111 VLOG(1) << "Bluetooth audio sink: Bluetooth adapter present changed: " 131 VLOG(1) << "Bluetooth audio sink: Bluetooth adapter present changed: "
112 << present; 132 << present;
113 133
114 if (adapter->IsPresent()) { 134 if (adapter->IsPresent()) {
115 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); 135 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED);
116 } else { 136 } else {
117 StateChanged(device::BluetoothAudioSink::STATE_INVALID); 137 adapter_->RemoveObserver(this);
138 StateChanged(BluetoothAudioSink::STATE_INVALID);
118 } 139 }
119 } 140 }
120 141
121 void BluetoothAudioSinkChromeOS::MediaRemoved( 142 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged(
122 const dbus::ObjectPath& object_path) { 143 device::BluetoothAdapter* adapter, bool powered) {
123 // TODO(mcchou): BUG=441581 144 VLOG(1) << "Bluetooth audio sink: Bluetooth adapter powered changed: "
124 // Changes |state_| to STATE_INVALID or STATE_DISCONNECTED? 145 << powered;
146
147 // Regardless of the new powered state, |state_| goes to STATE_DISCONNECTED.
148 // If false, the transport is closed, but the endpoint is still valid for use.
149 // If true, the previous transport has been torn down, so the |state_| has to
150 // be disconnected before SetConfigruation is called.
151 if (state_ != BluetoothAudioSink::STATE_INVALID)
152 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED);
153 }
154
155 void BluetoothAudioSinkChromeOS::MediaRemoved(const ObjectPath& object_path) {
125 if (object_path == media_path_) { 156 if (object_path == media_path_) {
126 StateChanged(device::BluetoothAudioSink::STATE_INVALID); 157 StateChanged(BluetoothAudioSink::STATE_INVALID);
127 } 158 }
128 } 159 }
129 160
130 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( 161 void BluetoothAudioSinkChromeOS::MediaTransportRemoved(
131 const dbus::ObjectPath& object_path) { 162 const ObjectPath& object_path) {
132 // Whenever powered of |adapter_| turns false while present stays true, media 163 // Whenever powered of |adapter_| turns false while present stays true, media
133 // transport object should be removed accordingly, and the state should be 164 // transport object should be removed accordingly, and the state should be
134 // changed to STATE_DISCONNECTED. 165 // changed to STATE_DISCONNECTED.
135 if (object_path == transport_path_) { 166 if (object_path == transport_path_) {
136 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); 167 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED);
137 } 168 }
138 } 169 }
139 170
140 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( 171 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged(
141 const dbus::ObjectPath& object_path, 172 const ObjectPath& object_path,
142 const std::string& property_name) { 173 const std::string& property_name) {
143 if (object_path != transport_path_) 174 if (object_path != transport_path_)
144 return; 175 return;
145 176
146 // Retrieves the property set of the transport object with |object_path|. 177 // Retrieves the property set of the transport object with |object_path|.
147 chromeos::BluetoothMediaTransportClient::Properties* properties = 178 chromeos::BluetoothMediaTransportClient::Properties* properties =
148 DBusThreadManager::Get() 179 DBusThreadManager::Get()
149 ->GetBluetoothMediaTransportClient() 180 ->GetBluetoothMediaTransportClient()
150 ->GetProperties(object_path); 181 ->GetProperties(object_path);
151 182
152 // Dispatches a property changed event to the corresponding handler. 183 // Dispatches a property changed event to the corresponding handler.
153 if (property_name == properties->state.name()) { 184 if (property_name == properties->state.name()) {
154 if (properties->state.value() == 185 if (properties->state.value() ==
155 BluetoothMediaTransportClient::kStateIdle) { 186 BluetoothMediaTransportClient::kStateIdle) {
156 StateChanged(device::BluetoothAudioSink::STATE_IDLE); 187 StateChanged(BluetoothAudioSink::STATE_IDLE);
157 } else if (properties->state.value() == 188 } else if (properties->state.value() ==
158 BluetoothMediaTransportClient::kStatePending) { 189 BluetoothMediaTransportClient::kStatePending) {
159 StateChanged(device::BluetoothAudioSink::STATE_PENDING); 190 StateChanged(BluetoothAudioSink::STATE_PENDING);
160 } else if (properties->state.value() == 191 } else if (properties->state.value() ==
161 BluetoothMediaTransportClient::kStateActive) { 192 BluetoothMediaTransportClient::kStateActive) {
162 StateChanged(device::BluetoothAudioSink::STATE_ACTIVE); 193 StateChanged(BluetoothAudioSink::STATE_ACTIVE);
163 } 194 }
164 } else if (property_name == properties->volume.name()) { 195 } else if (property_name == properties->volume.name()) {
165 VolumeChanged(properties->volume.value()); 196 VolumeChanged(properties->volume.value());
166 } else { 197 } else {
167 VLOG(1) << "Bluetooth audio sink: transport property " << property_name 198 VLOG(1) << "Bluetooth audio sink: transport property " << property_name
168 << " changed"; 199 << " changed";
169 } 200 }
170 } 201 }
171 202
172 void BluetoothAudioSinkChromeOS::SetConfiguration( 203 void BluetoothAudioSinkChromeOS::SetConfiguration(
173 const dbus::ObjectPath& transport_path, 204 const ObjectPath& transport_path,
174 const TransportProperties& properties) { 205 const TransportProperties& properties) {
175 VLOG(1) << "Bluetooth audio sink: SetConfiguration called"; 206 VLOG(1) << "Bluetooth audio sink: SetConfiguration called";
176 transport_path_ = transport_path; 207 transport_path_ = transport_path;
177 208
178 // The initial state for a connection should be "idle". 209 // The initial state for a connection should be "idle".
179 if (properties.state != BluetoothMediaTransportClient::kStateIdle) { 210 if (properties.state != BluetoothMediaTransportClient::kStateIdle) {
180 VLOG(1) << "Bluetooth Audio Sink: unexpected state " << properties.state; 211 VLOG(1) << "Bluetooth Audio Sink: unexpected state " << properties.state;
181 return; 212 return;
182 } 213 }
183 214
184 // Updates |volume_| if the volume level is provided in |properties|. 215 // Updates |volume_| if the volume level is provided in |properties|.
185 if (properties.volume.get() != nullptr) 216 if (properties.volume.get()) {
186 VolumeChanged(*properties.volume); 217 VolumeChanged(*properties.volume);
218 }
187 219
188 StateChanged(device::BluetoothAudioSink::STATE_IDLE); 220 StateChanged(BluetoothAudioSink::STATE_IDLE);
189 } 221 }
190 222
191 void BluetoothAudioSinkChromeOS::SelectConfiguration( 223 void BluetoothAudioSinkChromeOS::SelectConfiguration(
192 const std::vector<uint8_t>& capabilities, 224 const std::vector<uint8_t>& capabilities,
193 const SelectConfigurationCallback& callback) { 225 const SelectConfigurationCallback& callback) {
194 VLOG(1) << "Bluetooth audio sink: SelectConfiguration called"; 226 VLOG(1) << "Bluetooth audio sink: SelectConfiguration called";
195 callback.Run(options_.capabilities); 227 callback.Run(options_.capabilities);
196 } 228 }
197 229
198 void BluetoothAudioSinkChromeOS::ClearConfiguration( 230 void BluetoothAudioSinkChromeOS::ClearConfiguration(
199 const dbus::ObjectPath& transport_path) { 231 const ObjectPath& transport_path) {
232 if (transport_path != transport_path_)
233 return;
200 VLOG(1) << "Bluetooth audio sink: ClearConfiguration called"; 234 VLOG(1) << "Bluetooth audio sink: ClearConfiguration called";
201 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); 235 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED);
202 } 236 }
203 237
204 void BluetoothAudioSinkChromeOS::Released() { 238 void BluetoothAudioSinkChromeOS::Released() {
205 VLOG(1) << "Bluetooth audio sink: Released called"; 239 VLOG(1) << "Bluetooth audio sink: Released called";
206 StateChanged(device::BluetoothAudioSink::STATE_INVALID); 240 StateChanged(BluetoothAudioSink::STATE_INVALID);
207 } 241 }
208 242
209 void BluetoothAudioSinkChromeOS::Register( 243 void BluetoothAudioSinkChromeOS::Register(
210 const device::BluetoothAudioSink::Options& options, 244 const BluetoothAudioSink::Options& options,
211 const base::Closure& callback, 245 const base::Closure& callback,
212 const device::BluetoothAudioSink::ErrorCallback& error_callback) { 246 const BluetoothAudioSink::ErrorCallback& error_callback) {
213 DCHECK(adapter_.get()); 247 DCHECK(adapter_.get());
214 DCHECK_EQ(state_, device::BluetoothAudioSink::STATE_DISCONNECTED); 248 DCHECK_EQ(state_, BluetoothAudioSink::STATE_DISCONNECTED);
215 249
216 // Gets system bus. 250 // Gets system bus.
217 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); 251 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
218 252
219 // Creates a Media Endpoint with newly-generated path. 253 // Creates a Media Endpoint with newly-generated path.
220 endpoint_path_ = GenerateEndpointPath(); 254 endpoint_path_ = GenerateEndpointPath();
221 media_endpoint_.reset( 255 media_endpoint_.reset(
222 BluetoothMediaEndpointServiceProvider::Create( 256 BluetoothMediaEndpointServiceProvider::Create(
223 system_bus, endpoint_path_, this)); 257 system_bus, endpoint_path_, this));
224 258
(...skipping 21 matching lines...) Expand all
246 base::Bind(&BluetoothAudioSinkChromeOS::OnRegisterFailed, 280 base::Bind(&BluetoothAudioSinkChromeOS::OnRegisterFailed,
247 weak_ptr_factory_.GetWeakPtr(), error_callback)); 281 weak_ptr_factory_.GetWeakPtr(), error_callback));
248 } 282 }
249 283
250 BluetoothMediaEndpointServiceProvider* 284 BluetoothMediaEndpointServiceProvider*
251 BluetoothAudioSinkChromeOS::GetEndpointServiceProvider() { 285 BluetoothAudioSinkChromeOS::GetEndpointServiceProvider() {
252 return media_endpoint_.get(); 286 return media_endpoint_.get();
253 } 287 }
254 288
255 void BluetoothAudioSinkChromeOS::StateChanged( 289 void BluetoothAudioSinkChromeOS::StateChanged(
256 device::BluetoothAudioSink::State state) { 290 BluetoothAudioSink::State state) {
257 if (state == state_) 291 if (state == state_)
258 return; 292 return;
259 293
260 VLOG(1) << "Bluetooth audio sink state changed: " << state; 294 VLOG(1) << "Bluetooth audio sink state changed: " << state;
261
262 switch (state) { 295 switch (state) {
263 case device::BluetoothAudioSink::STATE_INVALID: { 296 case BluetoothAudioSink::STATE_INVALID:
264 // TODO(mcchou): BUG=441581
265 ResetMedia(); 297 ResetMedia();
266 ResetTransport();
267 ResetEndpoint(); 298 ResetEndpoint();
268 break; 299 case BluetoothAudioSink::STATE_DISCONNECTED:
269 }
270 case device::BluetoothAudioSink::STATE_DISCONNECTED: {
271 // TODO(mcchou): BUG=441581
272 // Clean media transport and remove the audio sink from its observer list.
273 ResetTransport(); 300 ResetTransport();
274 break; 301 break;
275 } 302 case BluetoothAudioSink::STATE_IDLE:
276 case device::BluetoothAudioSink::STATE_IDLE: {
277 // TODO(mcchou): BUG=441581 303 // TODO(mcchou): BUG=441581
278 // Triggered by MediaTransportPropertyChanged and SetConfiguration. 304 // Triggered by MediaTransportPropertyChanged and SetConfiguration.
279 // Stop watching on file descriptor if there is one. 305 // Stop watching on file descriptor if there is one.
280 break; 306 break;
281 } 307 case BluetoothAudioSink::STATE_PENDING:
282 case device::BluetoothAudioSink::STATE_PENDING: {
283 // TODO(mcchou): BUG=441581 308 // TODO(mcchou): BUG=441581
284 // Call BluetoothMediaTransportClient::Acquire() to get fd and mtus. 309 // Call BluetoothMediaTransportClient::Acquire() to get fd and mtus.
285 break; 310 break;
286 } 311 case BluetoothAudioSink::STATE_ACTIVE:
287 case device::BluetoothAudioSink::STATE_ACTIVE: {
288 // TODO(mcchou): BUG=441581 312 // TODO(mcchou): BUG=441581
289 // Read from fd and call DataAvailable. 313 // Read from fd and call DataAvailable.
290 ReadFromFD(); 314 ReadFromFD();
291 break; 315 break;
292 }
293 default: 316 default:
294 break; 317 break;
295 } 318 }
296 319
297 state_ = state; 320 state_ = state;
298 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, 321 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_,
299 BluetoothAudioSinkStateChanged(this, state_)); 322 BluetoothAudioSinkStateChanged(this, state_));
300 } 323 }
301 324
302 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { 325 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) {
303 DCHECK_NE(volume, volume_); 326 if (volume == volume_)
327 return;
328
304 VLOG(1) << "Bluetooth audio sink volume changed: " << volume; 329 VLOG(1) << "Bluetooth audio sink volume changed: " << volume;
305 volume_ = volume; 330 volume_ = std::min(volume, BluetoothAudioSink::kInvalidVolume);
306 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, 331
332 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_,
307 BluetoothAudioSinkVolumeChanged(this, volume_)); 333 BluetoothAudioSinkVolumeChanged(this, volume_));
308 } 334 }
309 335
310 void BluetoothAudioSinkChromeOS::OnRegisterSucceeded( 336 void BluetoothAudioSinkChromeOS::OnRegisterSucceeded(
311 const base::Closure& callback) { 337 const base::Closure& callback) {
338 DCHECK(media_endpoint_.get());
312 VLOG(1) << "Bluetooth audio sink registerd"; 339 VLOG(1) << "Bluetooth audio sink registerd";
313 340
314 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); 341 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED);
315 callback.Run(); 342 callback.Run();
316 } 343 }
317 344
318 void BluetoothAudioSinkChromeOS::OnRegisterFailed( 345 void BluetoothAudioSinkChromeOS::OnRegisterFailed(
319 const BluetoothAudioSink::ErrorCallback& error_callback, 346 const BluetoothAudioSink::ErrorCallback& error_callback,
320 const std::string& error_name, 347 const std::string& error_name,
321 const std::string& error_message) { 348 const std::string& error_message) {
322 DCHECK(media_endpoint_.get());
323 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message; 349 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message;
324 350
325 ResetEndpoint(); 351 ResetEndpoint();
326 error_callback.Run(device::BluetoothAudioSink::ERROR_NOT_REGISTERED); 352 error_callback.Run(BluetoothAudioSink::ERROR_NOT_REGISTERED);
353 }
354
355 void BluetoothAudioSinkChromeOS::OnUnregisterSucceeded(
356 const base::Closure& callback) {
357 VLOG(1) << "Bluetooth audio sink unregisterd";
358
359 // Once the state becomes STATE_INVALID, media, media transport and media
360 // endpoint will be reset.
361 StateChanged(BluetoothAudioSink::STATE_INVALID);
362 callback.Run();
363 }
364
365 void BluetoothAudioSinkChromeOS::OnUnregisterFailed(
366 const device::BluetoothAudioSink::ErrorCallback& error_callback,
367 const std::string& error_name,
368 const std::string& error_message) {
369 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message;
370 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED);
327 } 371 }
328 372
329 void BluetoothAudioSinkChromeOS::ReadFromFD() { 373 void BluetoothAudioSinkChromeOS::ReadFromFD() {
330 DCHECK_GE(fd_.value(), 0); 374 DCHECK_GE(fd_.value(), 0);
331 375
332 // TODO(mcchou): BUG=441581 376 // TODO(mcchou): BUG=441581
333 // Read from file descriptor using watcher and create a buffer to contain the 377 // Read from file descriptor using watcher and create a buffer to contain the
334 // data. Notify |Observers_| while there is audio data available. 378 // data. Notify |Observers_| while there is audio data available.
335 } 379 }
336 380
337 void BluetoothAudioSinkChromeOS::ResetMedia() { 381 void BluetoothAudioSinkChromeOS::ResetMedia() {
338 media_path_ = dbus::ObjectPath(""); 382 media_path_ = dbus::ObjectPath("");
339 } 383 }
340 384
341 void BluetoothAudioSinkChromeOS::ResetTransport() { 385 void BluetoothAudioSinkChromeOS::ResetTransport() {
386 if (transport_path_.value() == "")
387 return;
342 transport_path_ = dbus::ObjectPath(""); 388 transport_path_ = dbus::ObjectPath("");
343 volume_ = 0; 389 VolumeChanged(BluetoothAudioSink::kInvalidVolume);
344 read_mtu_ = 0; 390 read_mtu_ = 0;
345 write_mtu_ = 0; 391 write_mtu_ = 0;
346 fd_.PutValue(-1); 392 fd_.PutValue(-1);
347 } 393 }
348 394
349 void BluetoothAudioSinkChromeOS::ResetEndpoint() { 395 void BluetoothAudioSinkChromeOS::ResetEndpoint() {
350 endpoint_path_ = dbus::ObjectPath(""); 396 endpoint_path_ = ObjectPath("");
351 media_endpoint_ = nullptr; 397 media_endpoint_ = nullptr;
352 } 398 }
353 399
354 } // namespace chromeos 400 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_audio_sink_chromeos.h ('k') | device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698