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_OFFSCREEN_PRESENTATION_MANAGER_H_ | |
6 #define CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_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 class WebContents; | |
22 } | |
23 | |
24 namespace media_router { | |
25 | |
26 class OffscreenPresentationManager; | |
27 | |
28 // Exposes APIs to get presentation receiver sessions and operate on receiver | |
miu
2015/09/27 00:22:08
IMO, this class should be deleted. It adds too li
imcheng
2015/09/30 01:13:41
Done.
| |
29 // sessions for an offscreen presentation given by |presentation_id_| hosted in | |
30 // an offscreen tab given by |presenter_web_contents_|. | |
31 // Obtained by calling |OffscreenPresentationManager::RegisterPresenterTab|. | |
32 // When this class is destroyed, all presentation receiver sessions will | |
33 // be removed from its OffscreenPresentationManager. | |
34 // This class must not outlive OffscreenPresentationManager or | |
35 // |presenter_web_contents_|. | |
36 class OffscreenPresenterContext { | |
37 public: | |
38 ~OffscreenPresenterContext(); | |
39 | |
40 void GetPresentationReceiverSession( | |
miu
2015/09/27 00:22:08
These two methods have almost the exact same name,
imcheng
2015/09/30 01:13:41
I have removed these functions from here. I will d
| |
41 const RenderFrameHostId& frame_id, | |
42 const content::PresentationReceiverSessionAvailableCallback& | |
43 success_callback, | |
44 const base::Callback<void(const std::string&)>& error_callback); | |
45 std::vector<content::PresentationSessionInfo> GetPresentationReceiverSessions( | |
46 const RenderFrameHostId& frame_id) const; | |
47 | |
48 bool IsPresenterFrame(const RenderFrameHostId& frame_id) const; | |
49 | |
50 void SendMessage(const RenderFrameHostId& frame_id, | |
51 const content::PresentationSessionInfo& session, | |
52 scoped_ptr<content::PresentationSessionMessage> message, | |
53 const content::SendMessageCallback& callback); | |
54 void ListenForMessages( | |
55 const RenderFrameHostId& frame_id, | |
56 const content::PresentationSessionInfo& session, | |
57 const content::PresentationSessionMessageCallback& callback); | |
58 void ListenForStateChanges( | |
59 const RenderFrameHostId& frame_id, | |
60 content::PresentationSessionStateListener* listener); | |
61 | |
62 private: | |
63 friend class OffscreenPresentationManager; | |
64 | |
65 OffscreenPresenterContext(content::WebContents* presenter_web_contents, | |
66 const std::string& presentation_id, | |
67 OffscreenPresentationManager* manager); | |
68 | |
69 content::WebContents* const presenter_web_contents_; | |
70 const std::string presentation_id_; | |
71 | |
72 // Calls are delegated to manager. | |
73 OffscreenPresentationManager* const manager_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(OffscreenPresenterContext); | |
76 }; | |
77 | |
78 // Exposes APIs to operate on a single controller session for an offscreen | |
miu
2015/09/27 00:22:08
This class doesn't expose APIs. It declares publi
imcheng
2015/09/30 01:13:41
Updated comment.
| |
79 // presentation given by |session|_ in a frame given by |controller_frame_id_|. | |
80 // Obtained by calling |OffscreenPresentationManager::RegisterController|. | |
81 // When this class is destroyed, the controller session will be removed from | |
82 // its OffscreenPresentationManager. | |
83 // This class must not outlive OffscreenPresentationManager or the | |
84 // RenderFrameHost of |controller_frame_id|. | |
85 class OffscreenController { | |
miu
2015/09/27 00:22:08
This class doesn't include any control logic. It'
imcheng
2015/09/30 01:13:41
As discussed offline yesterday, I have reworked th
| |
86 public: | |
87 ~OffscreenController(); | |
88 | |
89 void SendMessage(scoped_ptr<content::PresentationSessionMessage> message, | |
90 const content::SendMessageCallback& callback); | |
91 void ListenForMessages( | |
92 const content::PresentationSessionMessageCallback& callback); | |
93 void ListenForStateChanges( | |
94 content::PresentationSessionStateListener* listener); | |
95 | |
96 private: | |
97 friend class OffscreenPresentationManager; | |
98 | |
99 OffscreenController(const RenderFrameHostId& controller_frame_id, | |
100 const content::PresentationSessionInfo& session, | |
101 OffscreenPresentationManager* manager); | |
102 | |
103 const RenderFrameHostId controller_frame_id_; | |
104 const content::PresentationSessionInfo session_; | |
105 | |
106 // Calls are delegated to manager. | |
107 OffscreenPresentationManager* const manager_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(OffscreenController); | |
110 }; | |
111 | |
112 class OffscreenPresentationManager : public KeyedService { | |
miu
2015/09/27 00:22:08
Naming: "Manager" is so abstract. How about "Offs
imcheng
2015/09/30 01:13:42
Not sure if it's a better name, since message exch
| |
113 public: | |
114 ~OffscreenPresentationManager() override; | |
115 | |
116 // Registers the presenter of a offscreen presentation given by | |
117 // |presentation_id| | |
118 // as the main frame of tab given by |presenter_web_contents|. | |
119 // Only 1 presenter may be registered for a given presentation. | |
120 // A given WebContents can be a presenter for at most one presentation. | |
121 void RegisterPresenterTab(const std::string& presentation_id, | |
122 content::WebContents* presenter_web_contents); | |
123 void UnregisterPresenterTab(content::WebContents* presenter_web_contents); | |
124 | |
125 // Returns an OffscreenPresenterContext that can be used to operate on | |
126 // presenter | |
127 // session objects on tab |presenter_web_contents| that have been connected | |
128 // to their corresponding controllers. | |
129 scoped_ptr<OffscreenPresenterContext> GetOffscreenPresenterContext( | |
130 content::WebContents* presenter_web_contents); | |
131 | |
132 // Registers a controller of a offscreen presentation given by | |
133 // |presentation_id| | |
134 // as the frame given by |controller_frame_id|. | |
135 // Note that each presentation may have multiple controller frames, and that | |
136 // a frame may be a controller for multiple presentations. | |
137 // Returns a OffscreenController object that can be used to operate | |
138 // on the registered controller of the offscreen presentation. | |
139 scoped_ptr<OffscreenController> RegisterController( | |
140 const content::PresentationSessionInfo& session, | |
141 const RenderFrameHostId& controller_frame_id); | |
142 | |
143 private: | |
144 friend class OffscreenPresenterContext; | |
145 friend class OffscreenController; | |
146 | |
147 private: | |
148 friend class OffscreenPresentationManagerFactory; | |
149 | |
150 // Represents a presentation session object. Contains information on the | |
151 // session object, including callbacks to be invoked for messages and state | |
152 // changes (which comes from the other side of the controller/presenter). | |
153 struct OffscreenPresentationSessionInfo { | |
miu
2015/09/27 00:22:08
Consider merging this into OffscreenController. T
imcheng
2015/09/30 01:13:41
I have moved the callback and listener fields what
| |
154 OffscreenPresentationSessionInfo( | |
155 const RenderFrameHostId& controller_frame_id, | |
156 const content::PresentationSessionInfo& session); | |
157 ~OffscreenPresentationSessionInfo(); | |
158 | |
159 const RenderFrameHostId controller_frame_id; | |
160 const content::PresentationSessionInfo session; | |
161 content::PresentationSessionMessageCallback message_callback; | |
162 content::PresentationSessionStateListener* state_change_listener; | |
163 }; | |
164 | |
165 // Represents a connection between a controller and the presentation. | |
166 // Contains the controller session object in the controller frame, and its | |
167 // corresponding presenter session object proxy in the presenter frame. | |
168 struct OffscreenPresentationRoute { | |
miu
2015/09/27 00:22:08
Suggestion: Delete this class, and move |presenter
imcheng
2015/09/30 01:13:42
I have added support for multiple controllers for
| |
169 OffscreenPresentationRoute(); | |
170 ~OffscreenPresentationRoute(); | |
171 | |
172 scoped_ptr<OffscreenPresentationSessionInfo> presenter; | |
173 scoped_ptr<OffscreenPresentationSessionInfo> controller; | |
174 }; | |
175 | |
176 // Represents a offscreen presentation. | |
177 // Contains information on the presenter frame, as well as list of controllers | |
178 // currently connected to presentation. | |
179 struct OffscreenPresentationInfo { | |
miu
2015/09/27 00:22:08
naming: "Info" isn't accurate.
imcheng
2015/09/30 01:13:42
Renamed to OffscreenPresentation.
| |
180 OffscreenPresentationInfo(); | |
181 ~OffscreenPresentationInfo(); | |
182 bool IsEmpty() const; | |
miu
2015/09/27 00:22:08
naming: How about HasRoutedPeers()? (This suggest
imcheng
2015/09/30 01:13:41
Removed function.
| |
183 | |
184 RenderFrameHostId presenter_frame_id; | |
185 | |
186 // Callback for getSession(). Must be made from |presenter_frame|. | |
187 content::PresentationReceiverSessionAvailableCallback session_callback; | |
188 | |
189 // TODO(imcheng): Support multiple controllers. | |
190 OffscreenPresentationRoute route; | |
191 }; | |
192 | |
193 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. | |
194 OffscreenPresentationManager(); | |
195 | |
196 void UnregisterController(const RenderFrameHostId& controller_frame_id, | |
197 const std::string& presentation_id); | |
198 | |
199 // Presenting API - must be a presenter frame to call. | |
200 // Obtains a presenter-side PresentationSessionInfo object that represents a | |
201 // proxy to its corresponding controller for the presentation session with | |
202 // presenter frame given by |presenter_frame_id|. | |
203 // |callback| will be invoked with the object once a controller has | |
204 // registered itself with the presentation. | |
205 void GetReceiverSession( | |
206 const RenderFrameHostId& presenter_frame_id, | |
207 const content::PresentationReceiverSessionAvailableCallback& callback); | |
208 | |
209 // TODO(imcheng): Support getSessions() once we can support multiple | |
210 // controllers. Currently we have no mechanism to distinguish one controller | |
211 // from another. | |
212 // Gets a list of presenter-side PresentationSessionInfo objects that | |
213 // represent proxies to their corresponding controllers for the presentation | |
214 // session with presenter frame given by |presenter_frame_id|. | |
215 std::vector<content::PresentationSessionInfo> GetPresentationReceiverSessions( | |
216 const RenderFrameHostId& presenter_frame_id) const; | |
217 | |
218 // Messaging - may be called by either presenter or controller frames. | |
219 void SendMessage(const content::PresentationSessionInfo& session, | |
220 scoped_ptr<content::PresentationSessionMessage> message, | |
221 const content::SendMessageCallback& callback); | |
222 void ListenForMessages( | |
223 const content::PresentationSessionInfo& session, | |
224 const content::PresentationSessionMessageCallback& callback); | |
225 | |
226 // State changes - may be called by either presenter or controller frames. | |
227 void ListenForStateChanges( | |
228 content::PresentationSessionStateListener* listener); | |
229 | |
230 // Remove the presenter/controller side from |presentation_info| and notify | |
231 // the other party of state change to "disconnected". | |
232 void RemovePresenterAndNotifyStateChange( | |
233 OffscreenPresentationInfo* presentation_info); | |
234 void RemoveControllerAndNotifyStateChange( | |
235 OffscreenPresentationInfo* presentation_info, | |
236 const RenderFrameHostId& controller_frame_id); | |
237 | |
238 OffscreenPresentationInfo* GetOrCreateOffscreenPresentationInfo( | |
239 const std::string& presentation_id); | |
240 OffscreenPresentationInfo* GetOffscreenPresentationInfo( | |
241 const std::string& presentation_id) const; | |
242 | |
243 // Maps from presentation ID to OffscreenPresentationInfo. | |
244 base::ScopedPtrMap<std::string, scoped_ptr<OffscreenPresentationInfo>> | |
245 offscreen_presentation_infos_; | |
246 | |
247 // Maps from presenter frame ID to presentation ID. | |
248 std::map<RenderFrameHostId, std::string> presenter_frames_; | |
249 | |
250 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); | |
251 }; | |
252 | |
253 } // namespace media_router | |
254 | |
255 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ | |
OLD | NEW |