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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/cast_config_controller.cc
diff --git a/ash/common/cast_config_controller.cc b/ash/common/cast_config_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ffea8059d07dc2a8d361361eabddc4e6562692bc
--- /dev/null
+++ b/ash/common/cast_config_controller.cc
@@ -0,0 +1,77 @@
+// 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/common/cast_config_controller.h"
+
+#include <utility>
+#include <vector>
+
+#include "base/logging.h"
+#include "content/public/common/service_names.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
+
+namespace ash {
+
+CastConfigController::CastConfigController() {}
+
+CastConfigController::~CastConfigController() {}
+
+bool CastConfigController::Connected() {
+ return client_.is_bound();
+}
+
+void CastConfigController::AddObserver(CastConfigControllerObserver* observer) {
+ observers_.AddObserver(observer);
+ 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
+ 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.
+}
+
+void CastConfigController::RemoveObserver(
+ CastConfigControllerObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void CastConfigController::BindRequest(mojom::CastConfigRequest request) {
+ bindings_.AddBinding(this, std::move(request));
+}
+
+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) {
+ for (auto& observer : observers_) {
+ std::vector<mojom::SinkAndRoutePtr> devices_copy;
+ for (auto& item : devices)
+ devices_copy.push_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));
+}
+
+void CastConfigController::OnClientConnectionError() {
+ client_.reset();
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698