Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_ONE_UA_PRESENTATION_ROUTER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_ONE_UA_PRESENTATION_ROUTER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/containers/scoped_ptr_map.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "chrome/browser/media/router/render_frame_host_helper.h" | |
| 15 #include "components/keyed_service/core/keyed_service.h" | |
| 16 #include "content/public/browser/presentation_service_delegate.h" | |
| 17 #include "content/public/browser/presentation_session.h" | |
| 18 | |
| 19 namespace content { | |
| 20 class BrowserContext; | |
| 21 } | |
| 22 | |
| 23 namespace media_router { | |
| 24 | |
| 25 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.
| |
| 26 public: | |
| 27 ~OneUAPresentationRouter() override; | |
| 28 | |
| 29 // Registers the presenter of a 1-UA presentation given by |presentation_id| | |
| 30 // as the frame given by |presenter_frame_id|. | |
| 31 // Only 1 presenter frame may be registered for a given presentation. | |
| 32 void RegisterPresenter(const std::string& presentation_id, | |
| 33 const RenderFrameHostId& presenter_frame_id); | |
| 34 void UnregisterPresenter(const RenderFrameHostId& presenter_frame_id); | |
| 35 | |
| 36 // Registers a controller of a 1-UA presentation given by |presentation_id| | |
| 37 // as the frame given by |controller_frame_id|. | |
| 38 // Note that each presentation may have multiple controller frames, and that | |
| 39 // a frame may be a controller for multiple presentations. | |
| 40 void RegisterController(const content::PresentationSessionInfo& session, | |
| 41 const RenderFrameHostId& controller_frame_id); | |
| 42 void UnregisterController(const std::string& presentation_id, | |
| 43 const RenderFrameHostId& controller_frame_id); | |
| 44 | |
| 45 // 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
| |
| 46 bool IsPresenter(const RenderFrameHostId& frame_id) const; | |
| 47 | |
| 48 // Returns true if the frame given by |frame_id| is a controller frame for | |
| 49 // presentation given by |presentation_id|. | |
| 50 bool IsController(const std::string& presentation_id, | |
| 51 const RenderFrameHostId& frame_id) const; | |
| 52 | |
| 53 // Presenting API - must be a presenter frame to call. | |
| 54 // Obtains a presenter-side PresentationSessionInfo object that represents a | |
| 55 // proxy to its corresponding controller for the presentation session with | |
| 56 // presenter frame given by |presenter_frame_id|. | |
| 57 // |callback| will be invoked with the object once a controller has | |
| 58 // registered itself with the presentation. | |
| 59 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
| |
| 60 const RenderFrameHostId& presenter_frame_id, | |
| 61 const content::PresenterSessionAvailableCallback& callback); | |
| 62 | |
| 63 // TODO(imcheng): Support getSessions() once we can support multiple | |
| 64 // controllers. Currently we have no mechanism to distinguish one controller | |
| 65 // from another. | |
| 66 // Gets a list of presenter-side PresentationSessionInfo objects that | |
| 67 // represent proxies to their corresponding controllers for the presentation | |
| 68 // session with presenter frame given by |presenter_frame_id|. | |
| 69 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
| |
| 70 const RenderFrameHostId& presenter_frame_id) const; | |
| 71 | |
| 72 // Messaging - may be called by either presenter or controller frames. | |
| 73 void SendMessage(const content::PresentationSessionInfo& session, | |
| 74 scoped_ptr<content::PresentationSessionMessage> message, | |
| 75 const content::SendMessageCallback& callback); | |
| 76 void ListenForMessages( | |
| 77 const content::PresentationSessionInfo& session, | |
| 78 const content::PresentationSessionMessageCallback& callback); | |
| 79 | |
| 80 // State changes - may be called by either presenter or controller frames. | |
| 81 void ListenForStateChanges( | |
| 82 const content::PresentationSessionInfo& session, | |
| 83 const content::SessionStateChangedCallback& callback); | |
| 84 | |
| 85 // Unregisters mapping/callbacks, etc., associated with |frame_id|. | |
| 86 void Reset(const RenderFrameHostId& frame_id); | |
| 87 | |
| 88 private: | |
| 89 friend class OneUAPresentationRouterFactory; | |
| 90 | |
| 91 // Represents a presentation session object. Contains information on the | |
| 92 // session object, including callbacks to be invoked for messages and state | |
| 93 // changes (which comes from the other side of the controller/presenter). | |
| 94 struct OneUAPresentationSession { | |
| 95 OneUAPresentationSession(const RenderFrameHostId& controller_frame_id, | |
| 96 const content::PresentationSessionInfo& session); | |
| 97 ~OneUAPresentationSession(); | |
| 98 | |
| 99 const RenderFrameHostId controller_frame_id; | |
| 100 const content::PresentationSessionInfo session; | |
| 101 content::PresentationSessionMessageCallback message_callback; | |
| 102 content::SessionStateChangedCallback state_change_callback; | |
| 103 }; | |
| 104 | |
| 105 // Represents a connection between a controller and the presentation. | |
| 106 // Contains the controller session object in the controller frame, and its | |
| 107 // corresponding presenter session object proxy in the presenter frame. | |
| 108 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
| |
| 109 OneUAPresentationRoute(); | |
| 110 ~OneUAPresentationRoute(); | |
| 111 | |
| 112 scoped_ptr<OneUAPresentationSession> presenter; | |
| 113 scoped_ptr<OneUAPresentationSession> controller; | |
| 114 }; | |
| 115 | |
| 116 // Represents a 1-UA presentation. | |
| 117 // Contains information on the presenter frame, as well as list of controllers | |
| 118 // currently connected to presentation. | |
| 119 struct OneUAPresentationInfo { | |
| 120 OneUAPresentationInfo(); | |
| 121 ~OneUAPresentationInfo(); | |
| 122 bool IsEmpty() const; | |
| 123 | |
| 124 RenderFrameHostId presenter_frame_id; | |
| 125 | |
| 126 // Callback for getSession(). Must be made from |presenter_frame|. | |
| 127 content::PresenterSessionAvailableCallback session_callback; | |
| 128 | |
| 129 // TODO(imcheng): Support multiple controllers. | |
| 130 OneUAPresentationRoute route; | |
| 131 }; | |
| 132 | |
| 133 // Used by OneUAPresentationRouterFactory::GetOrCreateForBrowserContext. | |
| 134 OneUAPresentationRouter(); | |
| 135 | |
| 136 // Remove the presenter/controller side from |presentation_info| and notify | |
| 137 // the other party of state change to "disconnected". | |
| 138 void RemovePresenterAndNotifyStateChange( | |
| 139 OneUAPresentationInfo* presentation_info); | |
| 140 void RemoveControllerAndNotifyStateChange( | |
| 141 OneUAPresentationInfo* presentation_info); | |
| 142 | |
| 143 OneUAPresentationInfo* GetOrCreateOneUAPresentationInfo( | |
| 144 const std::string& presentation_id); | |
| 145 OneUAPresentationInfo* GetOneUAPresentationInfo( | |
| 146 const std::string& presentation_id) const; | |
| 147 | |
| 148 base::ScopedPtrMap<std::string, scoped_ptr<OneUAPresentationInfo>> | |
| 149 one_ua_presentations_; | |
| 150 | |
| 151 // Maps from presenter frame ID to presentation ID. | |
| 152 std::map<RenderFrameHostId, std::string> presenter_frames_; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(OneUAPresentationRouter); | |
| 155 }; | |
| 156 | |
| 157 } // namespace media_router | |
| 158 | |
| 159 #endif // CHROME_BROWSER_MEDIA_ROUTER_ONE_UA_PRESENTATION_ROUTER_H_ | |
| OLD | NEW |