Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 VLOG(1) << "RegisterEndpoint: " << endpoint_path.value(); | |
| 55 | 60 |
| 56 // The object paths of the media client and adapter client should be the same. | 61 // The media client and adapter client should have the same object path. |
| 57 if (object_path != ObjectPath(FakeBluetoothAdapterClient::kAdapterPath) || | 62 if (object_path != object_path_ || |
| 58 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID || | 63 properties.uuid != BluetoothMediaClient::kBluetoothAudioSinkUUID || |
| 59 properties.codec != kDefaultCodec || | 64 properties.codec != kDefaultCodec || properties.capabilities.empty()) { |
| 60 properties.capabilities.empty()) { | 65 error_callback.Run(kInvalidArgumentsError, ""); |
| 61 error_callback.Run(kInvalidArgumentsError, ""); | 66 return; |
| 62 return; | 67 } |
| 68 | |
| 69 // Sets visible of a given endpoint path to true if it is registered. | |
| 70 SetEndpointVisible(endpoint_path, true); | |
| 71 | |
| 72 callback.Run(); | |
| 63 } | 73 } |
| 64 callback.Run(); | |
| 65 } | 74 } |
| 66 | 75 |
| 67 void FakeBluetoothMediaClient::UnregisterEndpoint( | 76 void FakeBluetoothMediaClient::UnregisterEndpoint( |
| 68 const ObjectPath& object_path, | 77 const ObjectPath& object_path, |
| 69 const ObjectPath& endpoint_path, | 78 const ObjectPath& endpoint_path, |
| 70 const base::Closure& callback, | 79 const base::Closure& callback, |
| 71 const ErrorCallback& error_callback) { | 80 const ErrorCallback& error_callback) { |
| 72 // TODO(mcchou): Come up with some corresponding actions. | 81 // TODO(mcchou): Come up with some corresponding actions. |
| 73 error_callback.Run(kFailedError, ""); | 82 error_callback.Run(kFailedError, ""); |
| 74 } | 83 } |
| 75 | 84 |
| 85 void FakeBluetoothMediaClient::SetVisible(bool visible) { | |
| 86 visible_ = visible; | |
| 87 | |
| 88 // If the media object becomes invisible, a update chain will remove all pairs | |
|
armansito
2015/02/10 00:17:01
nit: s/a update/an update/
Miao
2015/02/10 22:15:21
Done.
| |
| 89 // in |endpoints_| and update endpoints' visibility to the transport object. | |
|
armansito
2015/02/10 00:17:01
Maybe rephrase the second part of the sentence her
Miao
2015/02/10 22:15:21
Done.
| |
| 90 // Since all endpoint objects and the associated transport object will be | |
| 91 // invalid if the media object is no longer visible. | |
| 92 if (!visible_) { | |
| 93 for (std::map<ObjectPath, bool>::iterator it = endpoints_.begin(); | |
| 94 it != endpoints_.end(); ++it) { | |
| 95 SetEndpointVisible(it->first, visible_); | |
| 96 } | |
| 97 endpoints_.clear(); | |
| 98 | |
| 99 // Notifies observers about the change on |visible_|. | |
| 100 FOR_EACH_OBSERVER(BluetoothMediaClient::Observer, observers_, | |
| 101 MediaRemoved(object_path_)); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 void FakeBluetoothMediaClient::SetEndpointVisible( | |
| 106 const ObjectPath& endpoint_path, | |
| 107 bool visible) { | |
| 108 if (visible) { | |
| 109 endpoints_[endpoint_path] = visible; | |
| 110 } else { | |
| 111 // Once a media endpoint object becomes invisible, its visibility to the | |
| 112 // transport object should be false. | |
| 113 FakeBluetoothMediaTransportClient* transport = | |
| 114 static_cast<FakeBluetoothMediaTransportClient*>( | |
| 115 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); | |
| 116 transport->SetVisible(endpoint_path, visible); | |
| 117 } | |
| 118 } | |
| 119 | |
| 76 } // namespace chromeos | 120 } // namespace chromeos |
| OLD | NEW |