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..4a836cc8eff882c3c8b6772bb0bf2ee2cb1aef82 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 the state of a given endpoint path to true if it is registered. |
| + SetEndpointRegistered(endpoint_path, true); |
| + |
| + callback.Run(); |
| } |
| - callback.Run(); |
| } |
| void FakeBluetoothMediaClient::UnregisterEndpoint( |
| @@ -73,4 +82,38 @@ void FakeBluetoothMediaClient::UnregisterEndpoint( |
| error_callback.Run(kFailedError, ""); |
| } |
| +void FakeBluetoothMediaClient::SetVisible(bool visible) { |
| + visible_ = visible; |
| + |
| + // If the media object becomes invisible, an update chain will |
| + // unregister all endpoints and set the associated transport |
| + // objects to be invalid. |
| + if (!visible_) { |
|
Ben Chan
2015/02/12 21:17:44
nit: you can do the following to save one indenta
Miao
2015/02/12 22:54:06
Done.
|
| + for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin(); |
| + it != endpoints_.end(); ++it) { |
| + SetEndpointRegistered(it->first, false); |
| + } |
| + endpoints_.clear(); |
| + |
| + // Notifies observers about the change on |visible_|. |
| + FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_, |
| + MediaRemoved(object_path_)); |
| + } |
| +} |
| + |
| +void FakeBluetoothMediaClient::SetEndpointRegistered( |
| + const ObjectPath& endpoint_path, |
| + bool registered) { |
| + if (registered) { |
| + endpoints_[endpoint_path] = registered; |
| + } else { |
| + // Once a media endpoint object becomes invalid, the associated transport |
| + // becomes invalid. |
| + FakeBluetoothMediaTransportClient* transport = |
| + static_cast<FakeBluetoothMediaTransportClient*>( |
| + DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
| + transport->SetValid(endpoint_path, true); |
| + } |
| +} |
| + |
| } // namespace chromeos |