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 58c4fdffca7216a319e3292fc49e4f457677123e..206ee82bf61d12fccc964c51b6b57dcbe8d61070 100644 |
| --- a/chromeos/dbus/fake_bluetooth_media_client.cc |
| +++ b/chromeos/dbus/fake_bluetooth_media_client.cc |
| @@ -6,8 +6,10 @@ |
| #include <string> |
| +#include "base/stl_util.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| +#include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h" |
| #include "chromeos/dbus/fake_bluetooth_media_transport_client.h" |
| using dbus::ObjectPath; |
| @@ -68,9 +70,6 @@ void FakeBluetoothMediaClient::RegisterEndpoint( |
| return; |
| } |
| - // Sets the state of a given endpoint path to true if it is registered. |
| - SetEndpointRegistered(endpoint_path, true); |
| - |
| callback.Run(); |
| } |
| @@ -80,7 +79,15 @@ void FakeBluetoothMediaClient::UnregisterEndpoint( |
| const base::Closure& callback, |
| const ErrorCallback& error_callback) { |
| // TODO(mcchou): Come up with some corresponding actions. |
| - error_callback.Run(kFailedError, ""); |
| + VLOG(1) << "UnregisterEndpoint: " << endpoint_path.value(); |
| + |
| + if (!ContainsKey(endpoints_, endpoint_path)) { |
| + error_callback.Run(kFailedError, "Unknown media endpoint"); |
| + return; |
| + } |
| + |
| + SetEndpointRegistered(endpoints_[endpoint_path], false); |
| + callback.Run(); |
| } |
| void FakeBluetoothMediaClient::SetVisible(bool visible) { |
| @@ -92,11 +99,9 @@ void FakeBluetoothMediaClient::SetVisible(bool visible) { |
| // If the media object becomes invisible, an update chain will |
| // unregister all endpoints and set the associated transport |
| // objects to be invalid. |
| - for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin(); |
| - it != endpoints_.end(); ++it) { |
| - SetEndpointRegistered(it->first, false); |
| + while (endpoints_.begin() != endpoints_.end()) { |
|
armansito
2015/02/23 22:07:06
Please describe in a comment why this code works.
armansito
2015/02/23 22:07:06
nit: no need for curly braces.
Miao
2015/02/24 01:12:12
Done.
|
| + SetEndpointRegistered(endpoints_.begin()->second, false); |
| } |
| - endpoints_.clear(); |
| // Notifies observers about the change on |visible_|. |
| FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_, |
| @@ -104,18 +109,29 @@ void FakeBluetoothMediaClient::SetVisible(bool visible) { |
| } |
| void FakeBluetoothMediaClient::SetEndpointRegistered( |
| - const ObjectPath& endpoint_path, |
| + FakeBluetoothMediaEndpointServiceProvider* endpoint, |
| 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); |
| + endpoints_[endpoint->object_path()] = endpoint; |
| + return; |
| } |
| + |
| + if (!IsRegistered(endpoint->object_path())) |
| + return; |
| + |
| + // Once a media endpoint object becomes invalid, invalidate the associated |
| + // transport. |
| + FakeBluetoothMediaTransportClient* transport = |
| + static_cast<FakeBluetoothMediaTransportClient*>( |
| + DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
| + transport->SetValid(endpoint, false); |
| + |
| + endpoints_.erase(endpoint->object_path()); |
| + endpoint->Released(); |
| +} |
| + |
| +bool FakeBluetoothMediaClient::IsRegistered(dbus::ObjectPath endpoint_path) { |
| + return ContainsKey(endpoints_, endpoint_path); |
| } |
| } // namespace chromeos |