blob: 0b0e547276ca23f236ac2704d5d28ff7a7625bbb [file] [log] [blame]
James Cookb0bf8e82017-04-09 17:01:441// 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/cast_config_controller.h"
6
7#include <utility>
8#include <vector>
9
10namespace ash {
11
James Cookede316a2017-12-14 22:38:4312CastConfigController::CastConfigController() = default;
James Cookb0bf8e82017-04-09 17:01:4413
Chris Watkinsc24daf62017-11-28 03:43:0914CastConfigController::~CastConfigController() = default;
James Cookb0bf8e82017-04-09 17:01:4415
16bool CastConfigController::Connected() {
17 return client_.is_bound();
18}
19
20void CastConfigController::AddObserver(CastConfigControllerObserver* observer) {
21 observers_.AddObserver(observer);
22}
23
24void CastConfigController::RemoveObserver(
25 CastConfigControllerObserver* observer) {
26 observers_.RemoveObserver(observer);
27}
28
29void CastConfigController::BindRequest(mojom::CastConfigRequest request) {
James Cookede316a2017-12-14 22:38:4330 bindings_.AddBinding(this, std::move(request));
James Cookb0bf8e82017-04-09 17:01:4431}
32
33void 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
42void 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
52void CastConfigController::RequestDeviceRefresh() {
53 if (client_)
54 client_->RequestDeviceRefresh();
55}
56
57void CastConfigController::CastToSink(ash::mojom::CastSinkPtr sink) {
58 if (client_)
59 client_->CastToSink(std::move(sink));
60}
61
62void CastConfigController::StopCasting(ash::mojom::CastRoutePtr route) {
63 if (client_)
64 client_->StopCasting(std::move(route));
65}
66
67} // namespace ash