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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/fake_bluetooth_media_client.h" 5 #include "chromeos/dbus/fake_bluetooth_media_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
11 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
10 12
11 using dbus::ObjectPath; 13 using dbus::ObjectPath;
12 14
13 namespace { 15 namespace {
14 16
15 // Except for |kFailedError|, the other error is defined in BlueZ D-Bus Media 17 // Except for |kFailedError|, the other error is defined in BlueZ D-Bus Media
16 // API. 18 // API.
17 const char kFailedError[] = "org.chromium.Error.Failed"; 19 const char kFailedError[] = "org.chromium.Error.Failed";
18 const char kInvalidArgumentsError[] = "org.chromium.Error.InvalidArguments"; 20 const char kInvalidArgumentsError[] = "org.chromium.Error.InvalidArguments";
19 21
20 } // namespace 22 } // namespace
21 23
22 namespace chromeos { 24 namespace chromeos {
23 25
24 // static 26 // static
25 const uint8_t FakeBluetoothMediaClient::kDefaultCodec = 0x00; 27 const uint8_t FakeBluetoothMediaClient::kDefaultCodec = 0x00;
26 28
27 FakeBluetoothMediaClient::FakeBluetoothMediaClient() { 29 FakeBluetoothMediaClient::FakeBluetoothMediaClient()
30 : visible_(true),
31 object_path_(ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) {
28 } 32 }
29 33
30 FakeBluetoothMediaClient::~FakeBluetoothMediaClient() { 34 FakeBluetoothMediaClient::~FakeBluetoothMediaClient() {
31 } 35 }
32 36
33 void FakeBluetoothMediaClient::Init(dbus::Bus* bus) { 37 void FakeBluetoothMediaClient::Init(dbus::Bus* bus) {
34 } 38 }
35 39
36 void FakeBluetoothMediaClient::AddObserver( 40 void FakeBluetoothMediaClient::AddObserver(
37 BluetoothMediaClient::Observer* observer) { 41 BluetoothMediaClient::Observer* observer) {
38 DCHECK(observer); 42 DCHECK(observer);
39 observers_.AddObserver(observer); 43 observers_.AddObserver(observer);
40 } 44 }
41 45
42 void FakeBluetoothMediaClient::RemoveObserver( 46 void FakeBluetoothMediaClient::RemoveObserver(
43 BluetoothMediaClient::Observer* observer) { 47 BluetoothMediaClient::Observer* observer) {
44 DCHECK(observer); 48 DCHECK(observer);
45 observers_.RemoveObserver(observer); 49 observers_.RemoveObserver(observer);
46 } 50 }
47 51
48 void FakeBluetoothMediaClient::RegisterEndpoint( 52 void FakeBluetoothMediaClient::RegisterEndpoint(
49 const ObjectPath& object_path, 53 const ObjectPath& object_path,
50 const ObjectPath& endpoint_path, 54 const ObjectPath& endpoint_path,
51 const EndpointProperties& properties, 55 const EndpointProperties& properties,
52 const base::Closure& callback, 56 const base::Closure& callback,
53 const ErrorCallback& error_callback) { 57 const ErrorCallback& error_callback) {
54 VLOG(1) << "RegisterEndpoint: " << endpoint_path.value(); 58 if (!visible_)
59 return;
55 60
56 // The object paths of the media client and adapter client should be the same. 61 VLOG(1) << "RegisterEndpoint: " << endpoint_path.value();
57 if (object_path != ObjectPath(FakeBluetoothAdapterClient::kAdapterPath) || 62
63 // The media client and adapter client should have the same object path.
64 if (object_path != object_path_ ||
58 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID || 65 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID ||
59 properties.codec != kDefaultCodec || 66 properties.codec != kDefaultCodec || properties.capabilities.empty()) {
60 properties.capabilities.empty()) {
61 error_callback.Run(kInvalidArgumentsError, ""); 67 error_callback.Run(kInvalidArgumentsError, "");
62 return; 68 return;
63 } 69 }
70
71 // Sets the state of a given endpoint path to true if it is registered.
72 SetEndpointRegistered(endpoint_path, true);
73
64 callback.Run(); 74 callback.Run();
65 } 75 }
66 76
67 void FakeBluetoothMediaClient::UnregisterEndpoint( 77 void FakeBluetoothMediaClient::UnregisterEndpoint(
68 const ObjectPath& object_path, 78 const ObjectPath& object_path,
69 const ObjectPath& endpoint_path, 79 const ObjectPath& endpoint_path,
70 const base::Closure& callback, 80 const base::Closure& callback,
71 const ErrorCallback& error_callback) { 81 const ErrorCallback& error_callback) {
72 // TODO(mcchou): Come up with some corresponding actions. 82 // TODO(mcchou): Come up with some corresponding actions.
73 error_callback.Run(kFailedError, ""); 83 error_callback.Run(kFailedError, "");
74 } 84 }
75 85
86 void FakeBluetoothMediaClient::SetVisible(bool visible) {
87 visible_ = visible;
88
89 if (visible_)
90 return;
91
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);
98 }
99 endpoints_.clear();
100
101 // Notifies observers about the change on |visible_|.
102 FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_,
103 MediaRemoved(object_path_));
104 }
105
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);
118 }
119 }
120
76 } // namespace chromeos 121 } // 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