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

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

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/one_ua_presentation_router.h
diff --git a/chrome/browser/media/router/one_ua_presentation_router.h b/chrome/browser/media/router/one_ua_presentation_router.h
new file mode 100644
index 0000000000000000000000000000000000000000..67fac66193c4bbb2c3285c38d1ca950bf10e1cd2
--- /dev/null
+++ b/chrome/browser/media/router/one_ua_presentation_router.h
@@ -0,0 +1,159 @@
+// 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_ONE_UA_PRESENTATION_ROUTER_H_
+#define CHROME_BROWSER_MEDIA_ROUTER_ONE_UA_PRESENTATION_ROUTER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/containers/scoped_ptr_map.h"
+#include "base/macros.h"
+#include "chrome/browser/media/router/render_frame_host_helper.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "content/public/browser/presentation_service_delegate.h"
+#include "content/public/browser/presentation_session.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace media_router {
+
+class OneUAPresentationRouter : public KeyedService {
mark a. foltz 2015/09/11 23:24:20 Naming nitpicks: The term "One-UA" comes from the
miu 2015/09/17 00:09:20 Random OTOH replacements for the term "One UA Pres
imcheng 2015/09/26 01:21:57 On 2015/09/11 23:24:20, mark a. foltz wrote: > Nam
imcheng 2015/09/26 01:21:57 Went with OffscreenPresentationManager so it's con
miu 2015/09/27 00:22:08 Yes, because I am going to rename the OffscreenPre
imcheng 2015/09/30 01:13:41 Acknowledged.
+ public:
+ ~OneUAPresentationRouter() override;
+
+ // Registers the presenter of a 1-UA presentation given by |presentation_id|
+ // as the frame given by |presenter_frame_id|.
+ // Only 1 presenter frame may be registered for a given presentation.
+ void RegisterPresenter(const std::string& presentation_id,
+ const RenderFrameHostId& presenter_frame_id);
+ void UnregisterPresenter(const RenderFrameHostId& presenter_frame_id);
+
+ // Registers a controller of a 1-UA presentation given by |presentation_id|
+ // as the frame given by |controller_frame_id|.
+ // Note that each presentation may have multiple controller frames, and that
+ // a frame may be a controller for multiple presentations.
+ void RegisterController(const content::PresentationSessionInfo& session,
+ const RenderFrameHostId& controller_frame_id);
+ void UnregisterController(const std::string& presentation_id,
+ const RenderFrameHostId& controller_frame_id);
+
+ // Returns true if the frame given by |frame_id| is a presenter frame.
mark a. foltz 2015/09/11 23:24:20 ISTM that registering a controller or presenter sh
imcheng 2015/09/26 01:21:57 I think we can do that for controllers. but we mig
+ bool IsPresenter(const RenderFrameHostId& frame_id) const;
+
+ // Returns true if the frame given by |frame_id| is a controller frame for
+ // presentation given by |presentation_id|.
+ bool IsController(const std::string& presentation_id,
+ const RenderFrameHostId& frame_id) const;
+
+ // Presenting API - must be a presenter frame to call.
+ // Obtains a presenter-side PresentationSessionInfo object that represents a
+ // proxy to its corresponding controller for the presentation session with
+ // presenter frame given by |presenter_frame_id|.
+ // |callback| will be invoked with the object once a controller has
+ // registered itself with the presentation.
+ void GetSinglePresenterSession(
mark a. foltz 2015/09/11 23:24:20 Can the Presenter object (I mentioned above) get a
imcheng 2015/09/26 01:21:57 What I have is the that the Presenter object will
+ const RenderFrameHostId& presenter_frame_id,
+ const content::PresenterSessionAvailableCallback& callback);
+
+ // TODO(imcheng): Support getSessions() once we can support multiple
+ // controllers. Currently we have no mechanism to distinguish one controller
+ // from another.
+ // Gets a list of presenter-side PresentationSessionInfo objects that
+ // represent proxies to their corresponding controllers for the presentation
+ // session with presenter frame given by |presenter_frame_id|.
+ std::vector<content::PresentationSessionInfo> GetPresenterSessions(
mark a. foltz 2015/09/11 23:24:20 The Presenter would know which sessions are connec
imcheng 2015/09/26 01:21:57 Created Presenter object and exposed this API. But
+ const RenderFrameHostId& presenter_frame_id) const;
+
+ // Messaging - may be called by either presenter or controller frames.
+ void SendMessage(const content::PresentationSessionInfo& session,
+ scoped_ptr<content::PresentationSessionMessage> message,
+ const content::SendMessageCallback& callback);
+ void ListenForMessages(
+ const content::PresentationSessionInfo& session,
+ const content::PresentationSessionMessageCallback& callback);
+
+ // State changes - may be called by either presenter or controller frames.
+ void ListenForStateChanges(
+ const content::PresentationSessionInfo& session,
+ const content::SessionStateChangedCallback& callback);
+
+ // Unregisters mapping/callbacks, etc., associated with |frame_id|.
+ void Reset(const RenderFrameHostId& frame_id);
+
+ private:
+ friend class OneUAPresentationRouterFactory;
+
+ // Represents a presentation session object. Contains information on the
+ // session object, including callbacks to be invoked for messages and state
+ // changes (which comes from the other side of the controller/presenter).
+ struct OneUAPresentationSession {
+ OneUAPresentationSession(const RenderFrameHostId& controller_frame_id,
+ const content::PresentationSessionInfo& session);
+ ~OneUAPresentationSession();
+
+ const RenderFrameHostId controller_frame_id;
+ const content::PresentationSessionInfo session;
+ content::PresentationSessionMessageCallback message_callback;
+ content::SessionStateChangedCallback state_change_callback;
+ };
+
+ // Represents a connection between a controller and the presentation.
+ // Contains the controller session object in the controller frame, and its
+ // corresponding presenter session object proxy in the presenter frame.
+ struct OneUAPresentationRoute {
mark a. foltz 2015/09/11 23:24:20 Perhaps the OffscreenPresenter owns a list of Offs
imcheng 2015/09/26 01:21:57 So my model here is (name changed after this patch
+ OneUAPresentationRoute();
+ ~OneUAPresentationRoute();
+
+ scoped_ptr<OneUAPresentationSession> presenter;
+ scoped_ptr<OneUAPresentationSession> controller;
+ };
+
+ // Represents a 1-UA presentation.
+ // Contains information on the presenter frame, as well as list of controllers
+ // currently connected to presentation.
+ struct OneUAPresentationInfo {
+ OneUAPresentationInfo();
+ ~OneUAPresentationInfo();
+ bool IsEmpty() const;
+
+ RenderFrameHostId presenter_frame_id;
+
+ // Callback for getSession(). Must be made from |presenter_frame|.
+ content::PresenterSessionAvailableCallback session_callback;
+
+ // TODO(imcheng): Support multiple controllers.
+ OneUAPresentationRoute route;
+ };
+
+ // Used by OneUAPresentationRouterFactory::GetOrCreateForBrowserContext.
+ OneUAPresentationRouter();
+
+ // Remove the presenter/controller side from |presentation_info| and notify
+ // the other party of state change to "disconnected".
+ void RemovePresenterAndNotifyStateChange(
+ OneUAPresentationInfo* presentation_info);
+ void RemoveControllerAndNotifyStateChange(
+ OneUAPresentationInfo* presentation_info);
+
+ OneUAPresentationInfo* GetOrCreateOneUAPresentationInfo(
+ const std::string& presentation_id);
+ OneUAPresentationInfo* GetOneUAPresentationInfo(
+ const std::string& presentation_id) const;
+
+ base::ScopedPtrMap<std::string, scoped_ptr<OneUAPresentationInfo>>
+ one_ua_presentations_;
+
+ // Maps from presenter frame ID to presentation ID.
+ std::map<RenderFrameHostId, std::string> presenter_frames_;
+
+ DISALLOW_COPY_AND_ASSIGN(OneUAPresentationRouter);
+};
+
+} // namespace media_router
+
+#endif // CHROME_BROWSER_MEDIA_ROUTER_ONE_UA_PRESENTATION_ROUTER_H_

Powered by Google App Engine
This is Rietveld 408576698