| 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_controller.h" |
| 6 |
| 7 #include <utility> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "content/public/common/service_names.mojom.h" |
| 12 #include "services/service_manager/public/cpp/connector.h" |
| 13 |
| 14 namespace ash { |
| 15 |
| 16 CastConfigController::CastConfigController() {} |
| 17 |
| 18 CastConfigController::~CastConfigController() {} |
| 19 |
| 20 bool CastConfigController::Connected() { |
| 21 return client_.is_bound(); |
| 22 } |
| 23 |
| 24 void CastConfigController::AddObserver(CastConfigControllerObserver* observer) { |
| 25 observers_.AddObserver(observer); |
| 26 } |
| 27 |
| 28 void CastConfigController::RemoveObserver( |
| 29 CastConfigControllerObserver* observer) { |
| 30 observers_.RemoveObserver(observer); |
| 31 } |
| 32 |
| 33 void CastConfigController::BindRequest(mojom::CastConfigRequest request) { |
| 34 bindings_.AddBinding(this, std::move(request)); |
| 35 } |
| 36 |
| 37 void CastConfigController::SetClient( |
| 38 mojom::CastConfigClientAssociatedPtrInfo client) { |
| 39 client_.Bind(std::move(client)); |
| 40 |
| 41 // If we added observers before we were connected to, run them now. |
| 42 if (observers_.might_have_observers()) |
| 43 client_->RequestDeviceRefresh(); |
| 44 } |
| 45 |
| 46 void CastConfigController::OnDevicesUpdated( |
| 47 std::vector<mojom::SinkAndRoutePtr> devices) { |
| 48 for (auto& observer : observers_) { |
| 49 std::vector<mojom::SinkAndRoutePtr> devices_copy; |
| 50 for (auto& item : devices) |
| 51 devices_copy.push_back(item.Clone()); |
| 52 observer.OnDevicesUpdated(std::move(devices_copy)); |
| 53 } |
| 54 } |
| 55 |
| 56 void CastConfigController::RequestDeviceRefresh() { |
| 57 if (client_) |
| 58 client_->RequestDeviceRefresh(); |
| 59 } |
| 60 |
| 61 void CastConfigController::CastToSink(ash::mojom::CastSinkPtr sink) { |
| 62 if (client_) |
| 63 client_->CastToSink(std::move(sink)); |
| 64 } |
| 65 |
| 66 void CastConfigController::StopCasting(ash::mojom::CastRoutePtr route) { |
| 67 if (client_) |
| 68 client_->StopCasting(std::move(route)); |
| 69 } |
| 70 |
| 71 } // namespace ash |
| OLD | NEW |