| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "ash/common/cast_config_client_proxy.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/public/common/service_names.mojom.h" |
| 9 #include "services/service_manager/public/cpp/connector.h" |
| 10 |
| 11 namespace ash { |
| 12 |
| 13 CastConfigClientProxy::CastConfigClientProxy( |
| 14 service_manager::Connector* connector) |
| 15 : connector_(connector) {} |
| 16 |
| 17 CastConfigClientProxy::~CastConfigClientProxy() {} |
| 18 |
| 19 void CastConfigClientProxy::AddObserverBinding( |
| 20 mojo::AssociatedBinding<mojom::CastConfigObserver>* observer_binding) { |
| 21 if (!ConnectToClient()) |
| 22 return; |
| 23 |
| 24 ash::mojom::CastConfigObserverAssociatedPtrInfo ptr_info; |
| 25 observer_binding->Bind(&ptr_info, client_.associated_group()); |
| 26 AddObserver(std::move(ptr_info)); |
| 27 } |
| 28 |
| 29 bool CastConfigClientProxy::CanConnect() { |
| 30 return ConnectToClient(); |
| 31 } |
| 32 |
| 33 void CastConfigClientProxy::RequestDeviceRefresh() { |
| 34 if (ConnectToClient()) |
| 35 client_->RequestDeviceRefresh(); |
| 36 } |
| 37 |
| 38 void CastConfigClientProxy::CastToSink(ash::mojom::CastSinkPtr sink) { |
| 39 if (ConnectToClient()) |
| 40 client_->CastToSink(std::move(sink)); |
| 41 } |
| 42 |
| 43 void CastConfigClientProxy::StopCasting(ash::mojom::CastRoutePtr route) { |
| 44 if (ConnectToClient()) |
| 45 client_->StopCasting(std::move(route)); |
| 46 } |
| 47 |
| 48 void CastConfigClientProxy::AddObserver( |
| 49 ash::mojom::CastConfigObserverAssociatedPtrInfo observer) { |
| 50 if (ConnectToClient()) |
| 51 client_->AddObserver(std::move(observer)); |
| 52 } |
| 53 |
| 54 bool CastConfigClientProxy::ConnectToClient() { |
| 55 // Unit tests may not have a connector. |
| 56 if (!connector_) |
| 57 return false; |
| 58 |
| 59 if (client_) |
| 60 return true; |
| 61 |
| 62 connector_->ConnectToInterface(content::mojom::kBrowserServiceName, &client_); |
| 63 client_.set_connection_error_handler(base::Bind( |
| 64 &CastConfigClientProxy::OnClientConnectionError, base::Unretained(this))); |
| 65 return true; |
| 66 } |
| 67 |
| 68 void CastConfigClientProxy::OnClientConnectionError() { |
| 69 client_.reset(); |
| 70 } |
| 71 |
| 72 } // namespace ash |
| OLD | NEW |