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

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

Issue 1314413005: [Presentation API] 1-UA presentation support + presenter APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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: chrome/browser/media/router/incognito_presentation_service_delegate.cc
diff --git a/chrome/browser/media/router/incognito_presentation_service_delegate.cc b/chrome/browser/media/router/incognito_presentation_service_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..65ce0d208c4b93afc5d8c1d40f508211825b92d7
--- /dev/null
+++ b/chrome/browser/media/router/incognito_presentation_service_delegate.cc
@@ -0,0 +1,198 @@
+// 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 "chrome/browser/media/router/incognito_presentation_service_delegate.h"
+
+#include "chrome/browser/media/router/one_ua_presentation_router.h"
+#include "chrome/browser/media/router/one_ua_presentation_router_factory.h"
+#include "chrome/browser/profiles/profile.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(
+ media_router::IncognitoPresentationServiceDelegate);
+
+using content::PresentationServiceDelegate;
+using content::RenderFrameHost;
+
+namespace media_router {
+
+// static
+IncognitoPresentationServiceDelegate*
+IncognitoPresentationServiceDelegate::GetOrCreateForWebContents(
+ content::WebContents* web_contents) {
+ DCHECK(web_contents);
+ // CreateForWebContents does nothing if the delegate instance already exists.
+ IncognitoPresentationServiceDelegate::CreateForWebContents(web_contents);
+ return IncognitoPresentationServiceDelegate::FromWebContents(web_contents);
+}
+
+IncognitoPresentationServiceDelegate::~IncognitoPresentationServiceDelegate() {
+ for (auto& observer_pair : observers_)
+ observer_pair.second->OnDelegateDestroyed();
+}
+
+void IncognitoPresentationServiceDelegate::AddObserver(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationServiceDelegate::Observer* observer) {
+ DCHECK(observer);
+
+ RenderFrameHostId rfh_id(render_process_id, render_frame_id);
+ DCHECK(!ContainsKey(observers_, rfh_id));
+ observers_[rfh_id] = observer;
+}
+
+void IncognitoPresentationServiceDelegate::RemoveObserver(int render_process_id,
+ int render_frame_id) {
+ observers_.erase(RenderFrameHostId(render_process_id, render_frame_id));
+}
+
+bool IncognitoPresentationServiceDelegate::AddScreenAvailabilityListener(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationScreenAvailabilityListener* listener) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void IncognitoPresentationServiceDelegate::RemoveScreenAvailabilityListener(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationScreenAvailabilityListener* listener) {
+ NOTIMPLEMENTED();
+}
+
+void IncognitoPresentationServiceDelegate::Reset(int render_process_id,
+ int render_frame_id) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+ one_ua_presentation_router_->Reset(
+ RenderFrameHostId(render_process_id, render_frame_id));
+}
+
+void IncognitoPresentationServiceDelegate::SetDefaultPresentationUrl(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& default_presentation_url) {
+ NOTIMPLEMENTED();
+}
+
+void IncognitoPresentationServiceDelegate::StartSession(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& presentation_url,
+ const PresentationSessionSuccessCallback& success_cb,
+ const PresentationSessionErrorCallback& error_cb) {
+ NOTIMPLEMENTED();
+ error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
+ "Not implemented"));
+}
+
+void IncognitoPresentationServiceDelegate::JoinSession(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& presentation_url,
+ const std::string& presentation_id,
+ const PresentationSessionSuccessCallback& success_cb,
+ const PresentationSessionErrorCallback& error_cb) {
+ NOTIMPLEMENTED();
+ error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
+ "Not implemented"));
+}
+
+void IncognitoPresentationServiceDelegate::CloseSession(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& presentation_id) {
+ NOTIMPLEMENTED();
+}
+
+void IncognitoPresentationServiceDelegate::ListenForSessionMessages(
+ int render_process_id,
+ int render_frame_id,
+ const content::PresentationSessionInfo& session,
+ const content::PresentationSessionMessageCallback& message_cb) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+ DCHECK(one_ua_presentation_router_->IsPresenter(
+ RenderFrameHostId(render_process_id, render_frame_id)));
+ DCHECK(session.presentation_url.empty());
+
+ one_ua_presentation_router_->ListenForMessages(session, message_cb);
+}
+
+void IncognitoPresentationServiceDelegate::SendMessage(
+ int render_process_id,
+ int render_frame_id,
+ const content::PresentationSessionInfo& session,
+ scoped_ptr<content::PresentationSessionMessage> message,
+ const content::SendMessageCallback& send_message_cb) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+ DCHECK(one_ua_presentation_router_->IsPresenter(
+ RenderFrameHostId(render_process_id, render_frame_id)));
+ DCHECK(session.presentation_url.empty());
+
+ one_ua_presentation_router_->SendMessage(session, message.Pass(),
+ send_message_cb);
+}
+
+void IncognitoPresentationServiceDelegate::ListenForSessionStateChange(
+ int render_process_id,
+ int render_frame_id,
+ const content::SessionStateChangedCallback& state_changed_cb) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+ NOTIMPLEMENTED();
+ // TODO(imcheng): Implement when ListenForSessionStateChange takes a
+ // PresentationSessionInfo as input.
+}
+
+void IncognitoPresentationServiceDelegate::GetPresenterSession(
+ int render_process_id,
+ int render_frame_id,
+ const content::PresenterSessionAvailableCallback& success_callback,
+ const base::Callback<void(const std::string&)>& error_callback) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+
+ RenderFrameHostId rfh_id(render_process_id, render_frame_id);
+ if (!one_ua_presentation_router_->IsPresenter(rfh_id)) {
+ DVLOG(1) << "Not a presenter: " << render_process_id << ", "
+ << render_frame_id;
+ error_callback.Run("Not a presenter frame");
+ return;
+ }
+
+ one_ua_presentation_router_->GetSinglePresenterSession(rfh_id,
+ success_callback);
+}
+
+std::vector<content::PresentationSessionInfo>
+IncognitoPresentationServiceDelegate::GetPresenterSessions(
+ int render_process_id,
+ int render_frame_id) {
+ DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
+
+ RenderFrameHostId rfh_id(render_process_id, render_frame_id);
+ if (!one_ua_presentation_router_->IsPresenter(rfh_id)) {
+ DVLOG(1) << "Not a presenter: " << render_process_id << ", "
+ << render_frame_id;
+ return std::vector<content::PresentationSessionInfo>();
+ }
+
+ return one_ua_presentation_router_->GetPresenterSessions(rfh_id);
+}
+
+IncognitoPresentationServiceDelegate::IncognitoPresentationServiceDelegate(
+ content::WebContents* web_contents)
+ : web_contents_(web_contents),
+ // Get the OneUAPresentationRouter keyed off the controller profile, since
+ // it is where the 1-UA presentation is registered.
+ // Per OffscreenPresentationsOwner, the controller profile is the
+ // presenter
+ // tab's original profile.
+ one_ua_presentation_router_(
+ OneUAPresentationRouterFactory::GetOrCreateForBrowserContext(
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext())
+ ->GetOriginalProfile())) {
+ DCHECK(web_contents_);
+ DCHECK(one_ua_presentation_router_);
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698