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

Side by Side Diff: chromeos/dbus/fake_bluetooth_media_client.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chromeos/dbus/fake_bluetooth_media_client.h"
6
7 #include <string>
8
9 #include "base/stl_util.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
12 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h"
13 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
14
15 using dbus::ObjectPath;
16
17 namespace {
18
19 // Except for |kFailedError|, the other error is defined in BlueZ D-Bus Media
20 // API.
21 const char kFailedError[] = "org.chromium.Error.Failed";
22 const char kInvalidArgumentsError[] = "org.chromium.Error.InvalidArguments";
23
24 } // namespace
25
26 namespace chromeos {
27
28 // static
29 const uint8_t FakeBluetoothMediaClient::kDefaultCodec = 0x00;
30
31 FakeBluetoothMediaClient::FakeBluetoothMediaClient()
32 : visible_(true),
33 object_path_(ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) {
34 }
35
36 FakeBluetoothMediaClient::~FakeBluetoothMediaClient() {
37 }
38
39 void FakeBluetoothMediaClient::Init(dbus::Bus* bus) {
40 }
41
42 void FakeBluetoothMediaClient::AddObserver(
43 BluetoothMediaClient::Observer* observer) {
44 DCHECK(observer);
45 observers_.AddObserver(observer);
46 }
47
48 void FakeBluetoothMediaClient::RemoveObserver(
49 BluetoothMediaClient::Observer* observer) {
50 DCHECK(observer);
51 observers_.RemoveObserver(observer);
52 }
53
54 void FakeBluetoothMediaClient::RegisterEndpoint(
55 const ObjectPath& object_path,
56 const ObjectPath& endpoint_path,
57 const EndpointProperties& properties,
58 const base::Closure& callback,
59 const ErrorCallback& error_callback) {
60 if (!visible_)
61 return;
62
63 VLOG(1) << "RegisterEndpoint: " << endpoint_path.value();
64
65 // The media client and adapter client should have the same object path.
66 if (object_path != object_path_ ||
67 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID ||
68 properties.codec != kDefaultCodec || properties.capabilities.empty()) {
69 error_callback.Run(kInvalidArgumentsError, "");
70 return;
71 }
72
73 callback.Run();
74 }
75
76 void FakeBluetoothMediaClient::UnregisterEndpoint(
77 const ObjectPath& object_path,
78 const ObjectPath& endpoint_path,
79 const base::Closure& callback,
80 const ErrorCallback& error_callback) {
81 // TODO(mcchou): Come up with some corresponding actions.
82 VLOG(1) << "UnregisterEndpoint: " << endpoint_path.value();
83
84 if (!ContainsKey(endpoints_, endpoint_path)) {
85 error_callback.Run(kFailedError, "Unknown media endpoint");
86 return;
87 }
88
89 SetEndpointRegistered(endpoints_[endpoint_path], false);
90 callback.Run();
91 }
92
93 void FakeBluetoothMediaClient::SetVisible(bool visible) {
94 visible_ = visible;
95
96 if (visible_)
97 return;
98
99 // If the media object becomes invisible, an update chain will unregister all
100 // endpoints and set the associated transport objects to be invalid.
101 // SetEndpointRegistered will remove the endpoint entry from |endpoints_|.
102 while (endpoints_.begin() != endpoints_.end())
103 SetEndpointRegistered(endpoints_.begin()->second, false);
104
105 // Notifies observers about the change on |visible_|.
106 FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_,
107 MediaRemoved(object_path_));
108 }
109
110 void FakeBluetoothMediaClient::SetEndpointRegistered(
111 FakeBluetoothMediaEndpointServiceProvider* endpoint,
112 bool registered) {
113 if (registered) {
114 endpoints_[endpoint->object_path()] = endpoint;
115 return;
116 }
117
118 if (!IsRegistered(endpoint->object_path()))
119 return;
120
121 // Once a media endpoint object becomes invalid, invalidate the associated
122 // transport.
123 FakeBluetoothMediaTransportClient* transport =
124 static_cast<FakeBluetoothMediaTransportClient*>(
125 DBusThreadManager::Get()->GetBluetoothMediaTransportClient());
126 transport->SetValid(endpoint, false);
127
128 endpoints_.erase(endpoint->object_path());
129 endpoint->Released();
130 }
131
132 bool FakeBluetoothMediaClient::IsRegistered(
133 const dbus::ObjectPath& endpoint_path) {
134 return ContainsKey(endpoints_, endpoint_path);
135 }
136
137 } // namespace chromeos
OLDNEW
« 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