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

Unified Diff: chromeos/dbus/fake_bluetooth_media_client.cc

Issue 910023002: device/bluetooth:Implement BluetoothMediaEndpointServiceProvider delegate and media-related overrid… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved the addition/removal of all types of observer to constructor/destructor. 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 side-by-side diff with in-line comments
Download patch
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..58c4fdffca7216a319e3292fc49e4f457677123e 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,16 +55,22 @@ void FakeBluetoothMediaClient::RegisterEndpoint(
const EndpointProperties& properties,
const base::Closure& callback,
const ErrorCallback& error_callback) {
- VLOG(1) << "RegisterEndpoint: " << endpoint_path.value();
+ if (!visible_)
+ return;
+
+ 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) ||
+ // 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()) {
+ 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();
}
@@ -73,4 +83,39 @@ void FakeBluetoothMediaClient::UnregisterEndpoint(
error_callback.Run(kFailedError, "");
}
+void FakeBluetoothMediaClient::SetVisible(bool visible) {
+ visible_ = visible;
+
+ if (visible_)
+ return;
+
+ // 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);
+ }
+ 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
« no previous file with comments | « chromeos/dbus/fake_bluetooth_media_client.h ('k') | chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698