Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_media_client.cc
blob58c4fdffca7216a319e3292fc49e4f457677123e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_bluetooth_media_client.h"
7 #include <string>
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
11 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
13 using dbus::ObjectPath;
15 namespace {
17 // Except for |kFailedError|, the other error is defined in BlueZ D-Bus Media
18 // API.
19 const char kFailedError[] = "org.chromium.Error.Failed";
20 const char kInvalidArgumentsError[] = "org.chromium.Error.InvalidArguments";
22 } // namespace
24 namespace chromeos {
26 // static
27 const uint8_t FakeBluetoothMediaClient::kDefaultCodec = 0x00;
29 FakeBluetoothMediaClient::FakeBluetoothMediaClient()
30 : visible_(true),
31 object_path_(ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) {
34 FakeBluetoothMediaClient::~FakeBluetoothMediaClient() {
37 void FakeBluetoothMediaClient::Init(dbus::Bus* bus) {
40 void FakeBluetoothMediaClient::AddObserver(
41 BluetoothMediaClient::Observer* observer) {
42 DCHECK(observer);
43 observers_.AddObserver(observer);
46 void FakeBluetoothMediaClient::RemoveObserver(
47 BluetoothMediaClient::Observer* observer) {
48 DCHECK(observer);
49 observers_.RemoveObserver(observer);
52 void FakeBluetoothMediaClient::RegisterEndpoint(
53 const ObjectPath& object_path,
54 const ObjectPath& endpoint_path,
55 const EndpointProperties& properties,
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) {
58 if (!visible_)
59 return;
61 VLOG(1) << "RegisterEndpoint: " << endpoint_path.value();
63 // The media client and adapter client should have the same object path.
64 if (object_path != object_path_ ||
65 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID ||
66 properties.codec != kDefaultCodec || properties.capabilities.empty()) {
67 error_callback.Run(kInvalidArgumentsError, "");
68 return;
71 // Sets the state of a given endpoint path to true if it is registered.
72 SetEndpointRegistered(endpoint_path, true);
74 callback.Run();
77 void FakeBluetoothMediaClient::UnregisterEndpoint(
78 const ObjectPath& object_path,
79 const ObjectPath& endpoint_path,
80 const base::Closure& callback,
81 const ErrorCallback& error_callback) {
82 // TODO(mcchou): Come up with some corresponding actions.
83 error_callback.Run(kFailedError, "");
86 void FakeBluetoothMediaClient::SetVisible(bool visible) {
87 visible_ = visible;
89 if (visible_)
90 return;
92 // If the media object becomes invisible, an update chain will
93 // unregister all endpoints and set the associated transport
94 // objects to be invalid.
95 for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin();
96 it != endpoints_.end(); ++it) {
97 SetEndpointRegistered(it->first, false);
99 endpoints_.clear();
101 // Notifies observers about the change on |visible_|.
102 FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_,
103 MediaRemoved(object_path_));
106 void FakeBluetoothMediaClient::SetEndpointRegistered(
107 const ObjectPath& endpoint_path,
108 bool registered) {
109 if (registered) {
110 endpoints_[endpoint_path] = registered;
111 } else {
112 // Once a media endpoint object becomes invalid, the associated transport
113 // becomes invalid.
114 FakeBluetoothMediaTransportClient* transport =
115 static_cast<FakeBluetoothMediaTransportClient*>(
116 DBusThreadManager::Get()->GetBluetoothMediaTransportClient());
117 transport->SetValid(endpoint_path, true);
121 } // namespace chromeos