Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: ash/common/cast_config_controller.cc

Issue 2525563003: mash: Change CastConfigDelegate to a mojoified CastConfigClient. (Closed)
Patch Set: Add more RunAllPendingInMessageLoop to the tray tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 if (Connected())
James Cook 2016/12/02 04:15:52 I think if (client_) is a synonym for client_.is_b
Elliot Glaysher 2016/12/02 19:23:11 I can't remove Connected() entirely because it's u
27 client_->RequestDeviceRefresh();
James Cook 2016/12/02 04:15:52 It's a little weird that this is a side effect of
Elliot Glaysher 2016/12/02 19:23:11 Done.
28 }
29
30 void CastConfigController::RemoveObserver(
31 CastConfigControllerObserver* observer) {
32 observers_.RemoveObserver(observer);
33 }
34
35 void CastConfigController::BindRequest(mojom::CastConfigRequest request) {
36 bindings_.AddBinding(this, std::move(request));
37 }
38
39 void CastConfigController::SetClient(
40 mojom::CastConfigClientAssociatedPtrInfo client) {
41 client_.Bind(std::move(client));
42
43 // If we added observers before we were connected to, run them now.
44 if (observers_.might_have_observers())
45 client_->RequestDeviceRefresh();
46 }
47
48 void CastConfigController::OnDevicesUpdated(
49 std::vector<mojom::SinkAndRoutePtr> devices) {
50 for (auto& observer : observers_) {
51 std::vector<mojom::SinkAndRoutePtr> devices_copy;
52 for (auto& item : devices)
53 devices_copy.push_back(item.Clone());
54 observer.OnDevicesUpdated(std::move(devices_copy));
55 }
56 }
57
58 void CastConfigController::RequestDeviceRefresh() {
59 if (client_)
60 client_->RequestDeviceRefresh();
61 }
62
63 void CastConfigController::CastToSink(ash::mojom::CastSinkPtr sink) {
64 if (client_)
65 client_->CastToSink(std::move(sink));
66 }
67
68 void CastConfigController::StopCasting(ash::mojom::CastRoutePtr route) {
69 if (client_)
70 client_->StopCasting(std::move(route));
71 }
72
73 void CastConfigController::OnClientConnectionError() {
74 client_.reset();
75 }
76
77 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698