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

Unified Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 839773002: Plumbing from WebPresentationClient to the Presentation Mojo service for (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Swapped handling the event and requesting a new one Created 5 years, 11 months 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: content/renderer/presentation/presentation_dispatcher.cc
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca0411bd9e3c9868dc354df24e2f0bae91ed3e0f
--- /dev/null
+++ b/content/renderer/presentation/presentation_dispatcher.cc
@@ -0,0 +1,55 @@
+// Copyright 2015 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 "content/renderer/presentation/presentation_dispatcher.h"
+
+#include "content/common/presentation/presentation_service.mojom.h"
+#include "content/public/common/service_registry.h"
+#include "content/public/renderer/render_frame.h"
+#include "third_party/WebKit/public/platform/WebPresentationController.h"
+
+namespace content {
+
+PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
+ : RenderFrameObserver(render_frame) {}
+
+PresentationDispatcher::~PresentationDispatcher() {}
mark a. foltz 2015/01/27 21:56:09 Is it okay to drop the ptr to presentation_service
whywhat 2015/01/28 01:52:37 presentation_service_ is a smart pointer (mojo::In
+
+void PresentationDispatcher::setController(
+ blink::WebPresentationController* controller) {
+ // Provide the service with the callback to get the next |availablechange|
mark a. foltz 2015/01/27 21:56:09 Should we CHECK that controller_ == nullptr - assu
whywhat 2015/01/28 01:52:37 You mean that either controller_ or controller is
+ // event if needed. Ignore a null or the same controller though.
+ if (controller != nullptr && controller_ != controller)
+ updateAvailableChangeWatched(controller->isAvailableChangeWatched());
+ controller_ = controller;
+}
+
+void PresentationDispatcher::updateAvailableChangeWatched(bool watched) {
+ ConnectToPresentationServiceIfNeeded();
+ if (watched) {
+ presentation_service_->GetScreenAvailability(
mark a. foltz 2015/01/27 21:56:09 The lifetime of the PresentationDispatcher is tied
whywhat 2015/01/28 01:52:38 I don't know for sure. But my guess is that the ca
qsr 2015/01/28 15:41:10 The callback is stored on the persentation_service
+ base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged,
+ base::Unretained(this)));
+ }
+}
+
+void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
+ if (!controller_)
+ return;
+
+ // Reset the callback to get the next event.
+ updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
+
+ controller_->didChangeAvailability(available);
+}
+
+void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
+ if (presentation_service_.get())
+ return;
+
+ render_frame()->GetServiceRegistry()->ConnectToRemoteService(
+ &presentation_service_);
mark a. foltz 2015/01/27 21:56:09 Can this ever fail? Do we need to CHECK the resul
whywhat 2015/01/28 01:52:37 This either calls the service's CreateService imme
qsr 2015/01/28 15:41:10 It depends a lot what you mean by fail. After this
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698