Chromium Code Reviews| Index: chromeos/dbus/fake_bluetooth_media_client.cc |
| diff --git a/chromeos/dbus/fake_bluetooth_media_client.cc b/chromeos/dbus/fake_bluetooth_media_client.cc |
| index a4a77d3a9294c822866fe231c7a1bb2c9ef4099f..13a39df2a8ce748d4ff3dda82b455f39d66ed6a2 100644 |
| --- a/chromeos/dbus/fake_bluetooth_media_client.cc |
| +++ b/chromeos/dbus/fake_bluetooth_media_client.cc |
| @@ -6,7 +6,9 @@ |
| #include <string> |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| +#include "chromeos/dbus/fake_bluetooth_media_transport_client.h" |
| using dbus::ObjectPath; |
| @@ -24,7 +26,9 @@ namespace chromeos { |
| // static |
| const uint8_t FakeBluetoothMediaClient::kDefaultCodec = 0x00; |
| -FakeBluetoothMediaClient::FakeBluetoothMediaClient() { |
| +FakeBluetoothMediaClient::FakeBluetoothMediaClient() |
| + : visible_(true), |
| + object_path_(ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) { |
| } |
| FakeBluetoothMediaClient::~FakeBluetoothMediaClient() { |
| @@ -51,17 +55,22 @@ void FakeBluetoothMediaClient::RegisterEndpoint( |
| const EndpointProperties& properties, |
| const base::Closure& callback, |
| const ErrorCallback& error_callback) { |
| - VLOG(1) << "RegisterEndpoint: " << endpoint_path.value(); |
| - |
| - // The object paths of the media client and adapter client should be the same. |
| - if (object_path != ObjectPath(FakeBluetoothAdapterClient::kAdapterPath) || |
| - properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID || |
| - properties.codec != kDefaultCodec || |
| - properties.capabilities.empty()) { |
| - error_callback.Run(kInvalidArgumentsError, ""); |
| - return; |
| + if (visible_) { |
| + VLOG(1) << "RegisterEndpoint: " << endpoint_path.value(); |
| + |
| + // The media client and adapter client should have the same object path. |
| + if (object_path != object_path_ || |
| + properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID || |
| + properties.codec != kDefaultCodec || properties.capabilities.empty()) { |
| + error_callback.Run(kInvalidArgumentsError, ""); |
| + return; |
| + } |
| + |
| + // Sets visible of a given endpoint path to true if it is registered. |
| + SetEndpointVisible(endpoint_path, true); |
| + |
| + callback.Run(); |
| } |
| - callback.Run(); |
| } |
| void FakeBluetoothMediaClient::UnregisterEndpoint( |
| @@ -73,4 +82,39 @@ void FakeBluetoothMediaClient::UnregisterEndpoint( |
| error_callback.Run(kFailedError, ""); |
| } |
| +void FakeBluetoothMediaClient::SetVisible(bool visible) { |
| + visible_ = visible; |
| + |
| + // If the media object becomes invisible, a update chain will remove all pairs |
|
armansito
2015/02/10 00:17:01
nit: s/a update/an update/
Miao
2015/02/10 22:15:21
Done.
|
| + // in |endpoints_| and update endpoints' visibility to the transport object. |
|
armansito
2015/02/10 00:17:01
Maybe rephrase the second part of the sentence her
Miao
2015/02/10 22:15:21
Done.
|
| + // Since all endpoint objects and the associated transport object will be |
| + // invalid if the media object is no longer visible. |
| + if (!visible_) { |
| + for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin(); |
| + it != endpoints_.end(); ++it) { |
| + SetEndpointVisible(it->first, visible_); |
| + } |
| + endpoints_.clear(); |
| + |
| + // Notifies observers about the change on |visible_|. |
| + FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_, |
| + MediaRemoved(object_path_)); |
| + } |
| +} |
| + |
| +void FakeBluetoothMediaClient::SetEndpointVisible( |
| + const ObjectPath& endpoint_path, |
| + bool visible) { |
| + if (visible) { |
| + endpoints_[endpoint_path] = visible; |
| + } else { |
| + // Once a media endpoint object becomes invisible, its visibility to the |
| + // transport object should be false. |
| + FakeBluetoothMediaTransportClient* transport = |
| + static_cast<FakeBluetoothMediaTransportClient*>( |
| + DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
| + transport->SetVisible(endpoint_path, visible); |
| + } |
| +} |
| + |
| } // namespace chromeos |