forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_config_controller.cc
84 lines (64 loc) · 2.2 KB
/
cast_config_controller.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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/cast_config_controller.h"
#include <utility>
#include <vector>
namespace ash {
CastConfigController::CastConfigController() = default;
CastConfigController::~CastConfigController() = default;
bool CastConfigController::Connected() {
return client_.is_bound();
}
void CastConfigController::AddObserver(CastConfigControllerObserver* observer) {
observers_.AddObserver(observer);
}
void CastConfigController::RemoveObserver(
CastConfigControllerObserver* observer) {
observers_.RemoveObserver(observer);
}
void CastConfigController::BindRequest(mojom::CastConfigRequest request) {
bindings_.AddBinding(this, std::move(request));
}
bool CastConfigController::HasSinksAndRoutes() const {
return !sinks_and_routes_.empty();
}
bool CastConfigController::HasActiveRoute() const {
for (const auto& sr : sinks_and_routes_) {
if (!sr->route->title.empty() && sr->route->is_local_source)
return true;
}
return false;
}
void CastConfigController::SetClient(
mojom::CastConfigClientAssociatedPtrInfo client) {
client_.Bind(std::move(client));
// If we added observers before we were connected to, run them now.
if (observers_.might_have_observers())
client_->RequestDeviceRefresh();
}
void CastConfigController::OnDevicesUpdated(
std::vector<mojom::SinkAndRoutePtr> devices) {
sinks_and_routes_.clear();
for (const auto& item : devices)
sinks_and_routes_.emplace_back(item.Clone());
for (auto& observer : observers_) {
std::vector<mojom::SinkAndRoutePtr> devices_copy;
for (const auto& item : devices)
devices_copy.emplace_back(item.Clone());
observer.OnDevicesUpdated(std::move(devices_copy));
}
}
void CastConfigController::RequestDeviceRefresh() {
if (client_)
client_->RequestDeviceRefresh();
}
void CastConfigController::CastToSink(ash::mojom::CastSinkPtr sink) {
if (client_)
client_->CastToSink(std::move(sink));
}
void CastConfigController::StopCasting(ash::mojom::CastRoutePtr route) {
if (client_)
client_->StopCasting(std::move(route));
}
} // namespace ash