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