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

Unified Diff: chrome/browser/media/router/presentation_service_delegate_impl.h

Issue 1436703002: Revert of [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/presentation_service_delegate_impl.h
diff --git a/chrome/browser/media/router/presentation_service_delegate_impl.h b/chrome/browser/media/router/presentation_service_delegate_impl.h
index 0e6b63322a86d0ff53924c21e1925c3194895df7..03ad8c7a74ae47865cb040ff0acb6d97b85e1b14 100644
--- a/chrome/browser/media/router/presentation_service_delegate_impl.h
+++ b/chrome/browser/media/router/presentation_service_delegate_impl.h
@@ -16,8 +16,6 @@
#include "base/observer_list.h"
#include "chrome/browser/media/router/media_router.h"
#include "chrome/browser/media/router/media_source.h"
-#include "chrome/browser/media/router/presentation_request.h"
-#include "chrome/browser/media/router/render_frame_host_id.h"
#include "content/public/browser/presentation_service_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
@@ -36,6 +34,8 @@
class MediaSinksObserver;
class PresentationFrameManager;
class PresentationSessionStateObserver;
+
+using RenderFrameHostId = std::pair<int, int>;
// Implementation of PresentationServiceDelegate that interfaces an
// instance of WebContents with the Chrome Media Router. It uses the Media
@@ -49,23 +49,6 @@
: public content::WebContentsUserData<PresentationServiceDelegateImpl>,
public content::PresentationServiceDelegate {
public:
- // Observer interface for listening to default presentation request
- // changes for the WebContents.
- class DefaultPresentationRequestObserver {
- public:
- virtual ~DefaultPresentationRequestObserver() = default;
-
- // Called when default presentation request for the corresponding
- // WebContents is set or changed.
- // |default_presentation_info|: New default presentation request.
- virtual void OnDefaultPresentationChanged(
- const PresentationRequest& default_presentation_request) = 0;
-
- // Called when default presentation request for the corresponding
- // WebContents has been removed.
- virtual void OnDefaultPresentationRemoved() = 0;
- };
-
// Retrieves the instance of PresentationServiceDelegateImpl that was attached
// to the specified WebContents. If no instance was attached, creates one,
// and attaches it to the specified WebContents.
@@ -92,21 +75,18 @@
void SetDefaultPresentationUrl(
int render_process_id,
int render_frame_id,
- const std::string& default_presentation_url,
- const content::PresentationSessionStartedCallback& callback) override;
- void StartSession(
- int render_process_id,
- int render_frame_id,
- const std::string& presentation_url,
- const content::PresentationSessionStartedCallback& success_cb,
- const content::PresentationSessionErrorCallback& error_cb) override;
- void JoinSession(
- int render_process_id,
- int render_frame_id,
- const std::string& presentation_url,
- const std::string& presentation_id,
- const content::PresentationSessionStartedCallback& success_cb,
- const content::PresentationSessionErrorCallback& error_cb) override;
+ const std::string& default_presentation_url) override;
+ void StartSession(int render_process_id,
+ int render_frame_id,
+ const std::string& presentation_url,
+ const PresentationSessionSuccessCallback& success_cb,
+ const PresentationSessionErrorCallback& error_cb) override;
+ void 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) override;
void CloseSession(int render_process_id,
int render_frame_id,
const std::string& presentation_id) override;
@@ -125,51 +105,52 @@
int render_frame_id,
const content::SessionStateChangedCallback& state_changed_cb) override;
- // Callback invoked when a default PresentationRequest is started from a
- // browser-initiated dialog.
- void OnRouteResponse(const PresentationRequest& request,
- const MediaRoute* route,
+ // Callback invoked when there is a route response from CreateRoute/JoinRoute
+ // outside of a Presentation API request. This could be due to
+ // browser action (e.g., browser initiated media router dialog) or
+ // a media route provider (e.g., autojoin).
+ void OnRouteResponse(const MediaRoute* route,
const std::string& presentation_id,
const std::string& error);
- // Adds / removes an observer for listening to default PresentationRequest
- // changes. This class does not own |observer|. When |observer| is about to
- // be destroyed, |RemoveDefaultPresentationRequestObserver| must be called.
- void AddDefaultPresentationRequestObserver(
- DefaultPresentationRequestObserver* observer);
- void RemoveDefaultPresentationRequestObserver(
- DefaultPresentationRequestObserver* observer);
-
- // Gets the default presentation request for the owning tab WebContents. It
- // is an error to call this method if the default presentation request does
- // not exist.
- PresentationRequest GetDefaultPresentationRequest() const;
-
- // Returns true if there is a default presentation request for the owning tab
+ // Returns the default MediaSource for this tab if there is one.
+ // Returns an empty MediaSource otherwise.
+ MediaSource default_source() const { return default_source_; }
+
+ content::WebContents* web_contents() const { return web_contents_; }
+ const GURL& default_frame_url() const { return default_frame_url_; }
+
+ // Observer interface for listening to default MediaSource changes for the
// WebContents.
- bool HasDefaultPresentationRequest() const;
-
- // Returns the WebContents that owns this instance.
- content::WebContents* web_contents() const { return web_contents_; }
-
- base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
+ class DefaultMediaSourceObserver {
+ public:
+ virtual ~DefaultMediaSourceObserver() {}
+
+ // Called when default media source for the corresponding WebContents has
+ // changed.
+ // |source|: New default MediaSource, or empty if default was removed.
+ // |frame_url|: URL of the frame that contains the default media
+ // source, or empty if there is no default media source.
+ virtual void OnDefaultMediaSourceChanged(const MediaSource& source,
+ const GURL& frame_url) = 0;
+ };
+
+ // Adds / removes an observer for listening to default MediaSource changes.
+ void AddDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
+ void RemoveDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
void SetMediaRouterForTest(MediaRouter* router);
bool HasScreenAvailabilityListenerForTest(
int render_process_id,
int render_frame_id,
const MediaSource::Id& source_id) const;
+
+ base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
private:
friend class content::WebContentsUserData<PresentationServiceDelegateImpl>;
FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
DelegateObservers);
- FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
- SetDefaultPresentationUrl);
- FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
- DefaultPresentationRequestObserver);
- FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
- DefaultPresentationUrlCallback);
explicit PresentationServiceDelegateImpl(content::WebContents* web_contents);
@@ -178,26 +159,47 @@
MediaSource GetMediaSourceFromListener(
content::PresentationScreenAvailabilityListener* listener);
- void OnJoinRouteResponse(
- int render_process_id,
- int render_frame_id,
- const content::PresentationSessionInfo& session,
- const content::PresentationSessionStartedCallback& success_cb,
- const content::PresentationSessionErrorCallback& error_cb,
- const MediaRoute* route,
- const std::string& presentation_id,
- const std::string& error_text);
+ void OnJoinRouteResponse(int render_process_id,
+ int render_frame_id,
+ const content::PresentationSessionInfo& session,
+ const PresentationSessionSuccessCallback& success_cb,
+ const PresentationSessionErrorCallback& error_cb,
+ const MediaRoute* route,
+ const std::string& presentation_id,
+ const std::string& error_text);
void OnStartSessionSucceeded(
int render_process_id,
int render_frame_id,
- const content::PresentationSessionStartedCallback& success_cb,
+ const PresentationSessionSuccessCallback& success_cb,
const content::PresentationSessionInfo& new_session,
const MediaRoute::Id& route_id);
+ // Returns |true| if the frame is the main frame of |web_contents_|.
+ bool IsMainFrame(int render_process_id, int render_frame_id) const;
+
+ // Updates tab-level default MediaSource, default frame URL, and the
+ // originating frame. If the source or frame URL changed, notify the
+ // observers.
+ void UpdateDefaultMediaSourceAndNotifyObservers(
+ const RenderFrameHostId& render_frame_host_id,
+ const MediaSource& new_default_source,
+ const GURL& new_default_frame_url);
+
+ // ID of RenderFrameHost that contains the default presentation.
+ RenderFrameHostId default_presentation_render_frame_host_id_;
+ // Default MediaSource for the tab associated with this instance.
+ MediaSource default_source_;
+ // URL of the frame that contains the default MediaSource.
+ GURL default_frame_url_;
+
+ // References to the observers listening for changes to default media source.
+ base::ObserverList<
+ DefaultMediaSourceObserver> default_media_source_observers_;
+
// References to the WebContents that owns this instance, and associated
// browser profile's MediaRouter instance.
- content::WebContents* const web_contents_;
+ content::WebContents* web_contents_;
MediaRouter* router_;
scoped_ptr<PresentationFrameManager> frame_manager_;

Powered by Google App Engine
This is Rietveld 408576698