| Index: ash/common/cast_config_client_proxy.cc
|
| diff --git a/ash/common/cast_config_client_proxy.cc b/ash/common/cast_config_client_proxy.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c51a0d4d11449b8881222bbfcc4ef72f3a593d2b
|
| --- /dev/null
|
| +++ b/ash/common/cast_config_client_proxy.cc
|
| @@ -0,0 +1,72 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/common/cast_config_client_proxy.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "content/public/common/service_names.mojom.h"
|
| +#include "services/service_manager/public/cpp/connector.h"
|
| +
|
| +namespace ash {
|
| +
|
| +CastConfigClientProxy::CastConfigClientProxy(
|
| + service_manager::Connector* connector)
|
| + : connector_(connector) {}
|
| +
|
| +CastConfigClientProxy::~CastConfigClientProxy() {}
|
| +
|
| +void CastConfigClientProxy::AddObserverBinding(
|
| + mojo::AssociatedBinding<mojom::CastConfigObserver>* observer_binding) {
|
| + if (!ConnectToClient())
|
| + return;
|
| +
|
| + ash::mojom::CastConfigObserverAssociatedPtrInfo ptr_info;
|
| + observer_binding->Bind(&ptr_info, client_.associated_group());
|
| + AddObserver(std::move(ptr_info));
|
| +}
|
| +
|
| +bool CastConfigClientProxy::CanConnect() {
|
| + return ConnectToClient();
|
| +}
|
| +
|
| +void CastConfigClientProxy::RequestDeviceRefresh() {
|
| + if (ConnectToClient())
|
| + client_->RequestDeviceRefresh();
|
| +}
|
| +
|
| +void CastConfigClientProxy::CastToSink(ash::mojom::CastSinkPtr sink) {
|
| + if (ConnectToClient())
|
| + client_->CastToSink(std::move(sink));
|
| +}
|
| +
|
| +void CastConfigClientProxy::StopCasting(ash::mojom::CastRoutePtr route) {
|
| + if (ConnectToClient())
|
| + client_->StopCasting(std::move(route));
|
| +}
|
| +
|
| +void CastConfigClientProxy::AddObserver(
|
| + ash::mojom::CastConfigObserverAssociatedPtrInfo observer) {
|
| + if (ConnectToClient())
|
| + client_->AddObserver(std::move(observer));
|
| +}
|
| +
|
| +bool CastConfigClientProxy::ConnectToClient() {
|
| + // Unit tests may not have a connector.
|
| + if (!connector_)
|
| + return false;
|
| +
|
| + if (client_)
|
| + return true;
|
| +
|
| + connector_->ConnectToInterface(content::mojom::kBrowserServiceName, &client_);
|
| + client_.set_connection_error_handler(base::Bind(
|
| + &CastConfigClientProxy::OnClientConnectionError, base::Unretained(this)));
|
| + return true;
|
| +}
|
| +
|
| +void CastConfigClientProxy::OnClientConnectionError() {
|
| + client_.reset();
|
| +}
|
| +
|
| +} // namespace ash
|
|
|