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

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

Powered by Google App Engine
This is Rietveld 408576698