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

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

Issue 1132903002: [MediaRouter] Add implementation of PresentationServiceDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Derek's comments 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_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
new file mode 100644
index 0000000000000000000000000000000000000000..b6463e0f79d2e7f0a6fe38efd964f20dce3a5100
--- /dev/null
+++ b/chrome/browser/media/router/presentation_service_delegate_impl.h
@@ -0,0 +1,191 @@
+// 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.
+
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
+#define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
+
+#include <map>
+#include <string>
+#include <utility>
+
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "chrome/browser/media/router/media_router.h"
+#include "chrome/browser/media/router/media_source.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"
+
+namespace content {
+class RenderFrameHost;
+class PresentationScreenAvailabilityListener;
+class WebContents;
+struct PresentationSessionInfo;
+struct PresentationSessionMessage;
+}
+
+namespace media_router {
+
+class MediaRoute;
+class MediaSinksObserver;
+class PresentationFrameMap;
+
+using RenderFrameHostId = std::pair<int, int>;
+
+// Implementation of PresentationServiceDelegate that that interfaces an
+// instance of WebContents with the Chrome Media Router.
+// In addition to fulfilling Presentation requests, it also
+// provide tab-level information that is required for creating
+// browser-initiated sessions.
+class PresentationServiceDelegateImpl
+ : public content::WebContentsUserData<PresentationServiceDelegateImpl>,
+ public content::PresentationServiceDelegate {
+ public:
+ // Maximum number of sources that can be registered at a time.
+ static const size_t kMaxNumSources = 256;
imcheng (use chromium acct) 2015/05/19 20:03:29 This should be defined in PresentationFrameMap sin
haibinlu 2015/05/19 21:14:35 It is sort of public contract with the caller of t
+
+ ~PresentationServiceDelegateImpl() override;
+
+ // content::PresentationServiceDelegate implementation.
+ // PresentationScreenAvailabilityListener is one per
+ // (frame, presentation URL), while PresentationServiceDelegate::Observer
+ // is one per frame.
+ void AddObserver(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationServiceDelegate::Observer* observer) override;
+ void RemoveObserver(int render_process_id, int render_frame_id) override;
+ bool AddScreenAvailabilityListener(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationScreenAvailabilityListener* listener) override;
+ void RemoveScreenAvailabilityListener(
+ int render_process_id,
+ int render_frame_id,
+ content::PresentationScreenAvailabilityListener* listener) override;
+ void Reset(int render_process_id, int render_frame_id) override;
+ void SetDefaultPresentationUrl(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& default_presentation_url,
+ const std::string& default_presentation_id) override;
+ void StartSession(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 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 ListenForSessionMessages(
+ int render_process_id,
+ int render_frame_id,
+ const PresentationSessionMessageCallback& message_cb) override;
+ void SendMessage(
+ int render_process_id,
+ int render_frame_id,
+ scoped_ptr<content::PresentationSessionMessage> message_request,
+ const SendMessageCallback& send_message_cb) override;
+
+ // Notifies this object that |route| has been created or joined outside of a
+ // Presentation API request. The route could be due to
+ // browser action (e.g., browser initiated media router dialog) or
+ // a media route provider (e.g., autojoin).
+ void OnRouteCreated(const MediaRoute& route);
+
+ // Returns the default MediaSource for this tab if there is one.
+ // Returns an empty MediaSource otherwise.
+ MediaSource default_source() const { return default_source_; }
+
+ // Observer interface for listening to default MediaSource changes for the
+ // WebContents.
+ 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.
+ // |source_host|: Host name 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 std::string& source_host) = 0;
+ };
+
+ // Adds / removes an observer for listening to default MediaSource changes.
+ void AddDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
+ void RemoveDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
+
+ base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
+
+ private:
+ explicit PresentationServiceDelegateImpl(content::WebContents* web_contents);
+ friend class content::WebContentsUserData<PresentationServiceDelegateImpl>;
+
+ friend class PresentationServiceDelegateImplTest;
+ friend class PresentationServiceDelegateImplBrowserTest;
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
+ AddScreenAvailabilityListener);
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
+ MaxNumObservers);
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
+ AddListenerSameUrlTwice);
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, Reset);
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
+ DelegateObservers);
+ FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplBrowserTest,
+ RemoveObserversOnNavigation);
+
+ // Returns |listener|'s presentation URL as a MediaSource. If |listener| does
+ // not have a persentation URL, returns the tab mirroring MediaSource.
+ MediaSource GetMediaSourceFromListener(
+ content::PresentationScreenAvailabilityListener* listener);
+
+ // Returns |true| if frame |rfh_id| is the main frame of |web_contents_|.
+ bool IsMainFrame(RenderFrameHostId rfh_id) const;
+
+ // Updates tab-level default MediaSource and source host name. If either
+ // changed, notify the observers.
+ void UpdateDefaultMediaSourceAndNotifyObservers(
+ const MediaSource& new_default_source,
+ const std::string& new_default_source_host);
+
+ void SetMediaRouterForTest(MediaRouter* router);
+
+ bool HasScreenAvailabilityListenerForTest(
+ RenderFrameHostId rfh_id,
+ const MediaSourceId& source_id) const;
+
+ // Manages frames that are using presentation API.
+ scoped_ptr<PresentationFrameMap> frame_map_;
+
+ MediaSource default_source_;
+ std::string default_source_host_;
+
+ content::WebContents* web_contents_;
+
+ // Observers listening for changes to default media source. Not owned by
+ // this class.
+ ObserverList<DefaultMediaSourceObserver> default_media_source_observers_;
+
+ // Does not own this object.
+ MediaRouter* router_;
+
+ // NOTE: All WeakPtrs must be invalidated before member variables.
+ base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl);
+};
+
+} // namespace media_router
+
+#endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698