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

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

Issue 1132903002: [MediaRouter] Add implementation of PresentationServiceDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/presentation_frame.cc
diff --git a/chrome/browser/media/router/presentation_frame.cc b/chrome/browser/media/router/presentation_frame.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fc37f114a25d1f39e13ec5bd7c0435af6c543f57
--- /dev/null
+++ b/chrome/browser/media/router/presentation_frame.cc
@@ -0,0 +1,85 @@
+// 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/presentation_frame.h"
+
+#include "chrome/browser/media/router/media_router.h"
+#include "chrome/browser/media/router/media_router_impl_factory.h"
+#include "chrome/browser/media/router/presentation_media_sinks_observer.h"
+
+namespace media_router {
+
+PresentationFrame::PresentationFrame(content::WebContents* web_contents)
+ : web_contents_(web_contents),
+ router_(MediaRouterImplFactory::GetMediaRouterForBrowserContext(
+ web_contents_->GetBrowserContext())) {
+ DCHECK(router_);
+}
+
+PresentationFrame::~PresentationFrame() {
+ DCHECK(sink_observers_.empty());
+ if (delegate_observer_) {
+ delegate_observer_->OnDelegateDestroyed();
+ }
+}
+
+bool PresentationFrame::AddScreenAvailabilityListener(
+ content::PresentationScreenAvailabilityListener* listener) {
+ MediaSource source(GetMediaSourceFromListener(listener));
+ if (sink_observers_.contains(source.id()))
+ return false;
+
+ scoped_ptr<PresentationMediaSinksObserver> observer(
mark a. foltz 2015/05/14 22:20:44 make_scoped_ptr
haibinlu 2015/05/15 23:32:29 Done.
+ new PresentationMediaSinksObserver(router_, listener, source));
+ sink_observers_.add(source.id(), observer.Pass());
+ return true;
+}
+
+bool PresentationFrame::RemoveScreenAvailabilityListener(
+ content::PresentationScreenAvailabilityListener* listener) {
+ MediaSource source(GetMediaSourceFromListener(listener));
+ return sink_observers_.erase(source.id()) == 1;
+}
+
+void PresentationFrame::Reset() {
+ sink_observers_.clear();
+ default_presentation_info_.reset();
+}
+
+void PresentationFrame::SetDefaultPresentationInfo(
+ const std::string& default_presentation_url,
+ const std::string& default_presentation_id) {
+ if (default_presentation_url.empty() && default_presentation_id.empty()) {
+ default_presentation_info_.reset();
+ } else {
+ default_presentation_info_.reset(new content::PresentationSessionInfo(
+ default_presentation_url, default_presentation_id));
+ }
+}
+
+std::string PresentationFrame::GetDefaultPresentationId() const {
+ return default_presentation_info_
+ ? default_presentation_info_->presentation_id
+ : "";
+}
+
+void PresentationFrame::SetDelegateObserver(DelegateObserver* observer) {
+ delegate_observer_ = observer;
mark a. foltz 2015/05/14 22:20:44 This is a one-time operation correct? DCHECK(obser
+}
+
+DelegateObserver* PresentationFrame::GetDelegateObserver() const {
+ return delegate_observer_;
+}
+
+MediaSource PresentationFrame::GetMediaSourceFromListener(
+ content::PresentationScreenAvailabilityListener* listener) {
+ // If the default presentation URL is empty then fall back to 1-UA mode,
+ // i.e. offscreeen tab rendering.
+ std::string presentation_url(listener->GetPresentationUrl());
+ return presentation_url.empty()
+ ? ForTabMediaSource(SessionTabHelper::IdForTab(web_contents_))
mark a. foltz 2015/05/14 22:20:45 We might want to define a media source specificall
+ : ForPresentationUrl(presentation_url);
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698