| 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..612ebb5f53d00381290d4f47fd23c2ce1cbb21c9 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.
|
| + SetEndpointState(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_) {
|
| + for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin();
|
| + it != endpoints_.end(); ++it) {
|
| + SetEndpointState(it->first, false);
|
| + }
|
| + endpoints_.clear();
|
| +
|
| + // Notifies observers about the change on |visible_|.
|
| + FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_,
|
| + MediaRemoved(object_path_));
|
| + }
|
| +}
|
| +
|
| +void FakeBluetoothMediaClient::SetEndpointState(
|
| + 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
|
|
|