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

Unified Diff: chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: merge with master Created 4 years, 1 month 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: chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc
diff --git a/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc b/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0e64b1e539bc1cf43ab6c3407d574ba94d0fb82d
--- /dev/null
+++ b/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc
@@ -0,0 +1,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 "chrome/browser/media/router/receiver_presentation_service_delegate_impl.h"
+
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "url/gurl.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(
+ media_router::ReceiverPresentationServiceDelegateImpl);
+
+using content::RenderFrameHost;
+
+namespace media_router {
+
+// static
+void ReceiverPresentationServiceDelegateImpl::CreateForWebContents(
+ content::WebContents* web_contents,
+ const std::string& presentation_id) {
+ DCHECK(web_contents);
+
+ if (FromWebContents(web_contents))
+ return;
+
+ web_contents->SetUserData(UserDataKey(),
+ new ReceiverPresentationServiceDelegateImpl(
+ web_contents, presentation_id));
+}
+
+ReceiverPresentationServiceDelegateImpl::
+ ~ReceiverPresentationServiceDelegateImpl() {
+ for (auto& observer_pair : observers_)
+ observer_pair.second->OnDelegateDestroyed();
+}
+
+void ReceiverPresentationServiceDelegateImpl::AddObserver(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationServiceDelegateBase::Observer* observer) {
+ DCHECK(observer);
+
+ RenderFrameHostId rfh_id(render_process_id, render_frame_id);
+ DCHECK(!base::ContainsKey(observers_, rfh_id));
+ observers_[rfh_id] = observer;
+}
+
+void ReceiverPresentationServiceDelegateImpl::RemoveObserver(
+ int render_process_id,
+ int render_frame_id) {
+ observers_.erase(RenderFrameHostId(render_process_id, render_frame_id));
+}
+
+void ReceiverPresentationServiceDelegateImpl::Reset(int render_process_id,
+ int render_frame_id) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+ offscreen_presentation_manager_->OnOffscreenPresentationReceiverTerminated(
+ presentation_id_);
+}
+
+ReceiverPresentationServiceDelegateImpl::
+ ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents,
+ const std::string& presentation_id)
+ : web_contents_(web_contents),
+ presentation_id_(presentation_id),
+ offscreen_presentation_manager_(
+ OffscreenPresentationManagerFactory::
+ GetOrCreateForReceiverBrowserContext(web_contents_)) {
+ DCHECK(web_contents_);
+ DCHECK(!presentation_id.empty());
+ DCHECK(offscreen_presentation_manager_);
+}
+
+void ReceiverPresentationServiceDelegateImpl::
+ RegisterReceiverConnectionAvailableCallback(
+ const content::ReceiverConnectionAvailableCallback&
+ receiver_available_callback) {
+ offscreen_presentation_manager_->OnOffscreenPresentationReceiverCreated(
+ presentation_id_, web_contents_->GetLastCommittedURL(),
+ receiver_available_callback);
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698