OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 91 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
92 MaxPendingJoinSessionRequests); | 92 MaxPendingJoinSessionRequests); |
93 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 93 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
94 ListenForSessionStateChange); | 94 ListenForSessionStateChange); |
95 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 95 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
96 ListenForSessionStateChangeFails); | 96 ListenForSessionStateChangeFails); |
97 | 97 |
98 // Maximum number of pending JoinSession requests at any given time. | 98 // Maximum number of pending JoinSession requests at any given time. |
99 static const int kMaxNumQueuedSessionRequests = 10; | 99 static const int kMaxNumQueuedSessionRequests = 10; |
100 | 100 |
101 using DefaultSessionMojoCallback = | 101 using PresentationSessionMojoCallback = |
102 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; | 102 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; |
103 using SessionStateCallback = | 103 using SessionStateCallback = |
104 mojo::Callback<void(presentation::PresentationSessionInfoPtr, | 104 mojo::Callback<void(presentation::PresentationSessionInfoPtr, |
105 presentation::PresentationSessionState)>; | 105 presentation::PresentationSessionState)>; |
106 using SessionMessagesCallback = | 106 using SessionMessagesCallback = |
107 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; | 107 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; |
108 using SendMessageMojoCallback = mojo::Callback<void(bool)>; | 108 using SendMessageMojoCallback = mojo::Callback<void(bool)>; |
109 | 109 |
110 // Listener implementation owned by PresentationServiceImpl. An instance of | 110 // Listener implementation owned by PresentationServiceImpl. An instance of |
111 // this is created when PresentationRequest.getAvailability() is resolved. | 111 // this is created when PresentationRequest.getAvailability() is resolved. |
(...skipping 26 matching lines...) Expand all Loading... |
138 | 138 |
139 // PresentationSessionStateListener implementation. | 139 // PresentationSessionStateListener implementation. |
140 const PresentationSessionInfo& GetSessionInfo() const override; | 140 const PresentationSessionInfo& GetSessionInfo() const override; |
141 void OnSessionStateChanged(PresentationSessionState state) override; | 141 void OnSessionStateChanged(PresentationSessionState state) override; |
142 | 142 |
143 private: | 143 private: |
144 const PresentationSessionInfo session_; | 144 const PresentationSessionInfo session_; |
145 PresentationServiceImpl* const service_; | 145 PresentationServiceImpl* const service_; |
146 }; | 146 }; |
147 | 147 |
148 class CONTENT_EXPORT DefaultSessionStartContext { | |
149 public: | |
150 DefaultSessionStartContext(); | |
151 ~DefaultSessionStartContext(); | |
152 | |
153 // Adds a callback. May invoke the callback immediately if |session| using | |
154 // default presentation URL was already started. | |
155 void AddCallback(const DefaultSessionMojoCallback& callback); | |
156 | |
157 // Sets the session info. Maybe invoke callbacks queued with AddCallback(). | |
158 void set_session(const PresentationSessionInfo& session); | |
159 | |
160 private: | |
161 // Flush all queued callbacks by invoking them with null | |
162 // PresentationSessionInfoPtr. | |
163 void Reset(); | |
164 | |
165 ScopedVector<DefaultSessionMojoCallback> callbacks_; | |
166 scoped_ptr<PresentationSessionInfo> session_; | |
167 }; | |
168 | |
169 // Ensures the provided NewSessionMojoCallback is invoked exactly once | 148 // Ensures the provided NewSessionMojoCallback is invoked exactly once |
170 // before it goes out of scope. | 149 // before it goes out of scope. |
171 class NewSessionMojoCallbackWrapper { | 150 class NewSessionMojoCallbackWrapper { |
172 public: | 151 public: |
173 explicit NewSessionMojoCallbackWrapper( | 152 explicit NewSessionMojoCallbackWrapper( |
174 const NewSessionMojoCallback& callback); | 153 const NewSessionMojoCallback& callback); |
175 ~NewSessionMojoCallbackWrapper(); | 154 ~NewSessionMojoCallbackWrapper(); |
176 | 155 |
177 void Run(presentation::PresentationSessionInfoPtr session, | 156 void Run(presentation::PresentationSessionInfoPtr session, |
178 presentation::PresentationErrorPtr error); | 157 presentation::PresentationErrorPtr error); |
(...skipping 11 matching lines...) Expand all Loading... |
190 PresentationServiceImpl( | 169 PresentationServiceImpl( |
191 RenderFrameHost* render_frame_host, | 170 RenderFrameHost* render_frame_host, |
192 WebContents* web_contents, | 171 WebContents* web_contents, |
193 PresentationServiceDelegate* delegate); | 172 PresentationServiceDelegate* delegate); |
194 | 173 |
195 // PresentationService implementation. | 174 // PresentationService implementation. |
196 void SetDefaultPresentationURL(const mojo::String& url) override; | 175 void SetDefaultPresentationURL(const mojo::String& url) override; |
197 void SetClient(presentation::PresentationServiceClientPtr client) override; | 176 void SetClient(presentation::PresentationServiceClientPtr client) override; |
198 void ListenForScreenAvailability(const mojo::String& url) override; | 177 void ListenForScreenAvailability(const mojo::String& url) override; |
199 void StopListeningForScreenAvailability(const mojo::String& url) override; | 178 void StopListeningForScreenAvailability(const mojo::String& url) override; |
200 void ListenForDefaultSessionStart( | |
201 const DefaultSessionMojoCallback& callback) override; | |
202 void StartSession( | 179 void StartSession( |
203 const mojo::String& presentation_url, | 180 const mojo::String& presentation_url, |
204 const NewSessionMojoCallback& callback) override; | 181 const NewSessionMojoCallback& callback) override; |
205 void JoinSession( | 182 void JoinSession( |
206 const mojo::String& presentation_url, | 183 const mojo::String& presentation_url, |
207 const mojo::String& presentation_id, | 184 const mojo::String& presentation_id, |
208 const NewSessionMojoCallback& callback) override; | 185 const NewSessionMojoCallback& callback) override; |
209 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, | 186 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, |
210 presentation::SessionMessagePtr session_message, | 187 presentation::SessionMessagePtr session_message, |
211 const SendMessageMojoCallback& callback) override; | 188 const SendMessageMojoCallback& callback) override; |
212 void CloseSession( | 189 void CloseSession( |
213 const mojo::String& presentation_url, | 190 const mojo::String& presentation_url, |
214 const mojo::String& presentation_id) override; | 191 const mojo::String& presentation_id) override; |
215 void ListenForSessionStateChange( | 192 void ListenForSessionStateChange( |
216 presentation::PresentationSessionInfoPtr session) override; | 193 presentation::PresentationSessionInfoPtr session) override; |
217 void ListenForSessionMessages( | 194 void ListenForSessionMessages( |
218 presentation::PresentationSessionInfoPtr session) override; | 195 presentation::PresentationSessionInfoPtr session) override; |
| 196 void GetPresentationReceiverSession( |
| 197 const PresentationSessionMojoCallback& callback) override; |
219 | 198 |
220 // Creates a binding between this object and |request|. | 199 // Creates a binding between this object and |request|. |
221 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); | 200 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); |
222 | 201 |
223 // WebContentsObserver override. | 202 // WebContentsObserver override. |
224 void DidNavigateAnyFrame( | 203 void DidNavigateAnyFrame( |
225 content::RenderFrameHost* render_frame_host, | 204 content::RenderFrameHost* render_frame_host, |
226 const content::LoadCommittedDetails& details, | 205 const content::LoadCommittedDetails& details, |
227 const content::FrameNavigateParams& params) override; | 206 const content::FrameNavigateParams& params) override; |
228 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 207 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
(...skipping 25 matching lines...) Expand all Loading... |
254 void OnStartSessionError( | 233 void OnStartSessionError( |
255 int request_session_id, | 234 int request_session_id, |
256 const PresentationError& error); | 235 const PresentationError& error); |
257 void OnJoinSessionSucceeded( | 236 void OnJoinSessionSucceeded( |
258 int request_session_id, | 237 int request_session_id, |
259 const PresentationSessionInfo& session_info); | 238 const PresentationSessionInfo& session_info); |
260 void OnJoinSessionError( | 239 void OnJoinSessionError( |
261 int request_session_id, | 240 int request_session_id, |
262 const PresentationError& error); | 241 const PresentationError& error); |
263 void OnSendMessageCallback(bool sent); | 242 void OnSendMessageCallback(bool sent); |
| 243 void OnGetPresentationReceiverSession( |
| 244 const content::PresentationSessionInfo* session_info); |
264 | 245 |
265 // Passed to embedder's implementation of PresentationServiceDelegate for | 246 // Passed to embedder's implementation of PresentationServiceDelegate for |
266 // later invocation when session messages arrive. | 247 // later invocation when session messages arrive. |
267 void OnSessionMessages( | 248 void OnSessionMessages( |
268 const content::PresentationSessionInfo& session, | 249 const content::PresentationSessionInfo& session, |
269 const ScopedVector<PresentationSessionMessage>& messages, | 250 const ScopedVector<PresentationSessionMessage>& messages, |
270 bool pass_ownership); | 251 bool pass_ownership); |
271 | 252 |
272 // Associates a JoinSession |callback| with a unique request ID and | 253 // Associates a JoinSession |callback| with a unique request ID and |
273 // stores it in a map. | 254 // stores it in a map. |
(...skipping 25 matching lines...) Expand all Loading... |
299 | 280 |
300 // For StartSession requests. | 281 // For StartSession requests. |
301 // Set to a positive value when a StartSession request is being processed. | 282 // Set to a positive value when a StartSession request is being processed. |
302 int start_session_request_id_; | 283 int start_session_request_id_; |
303 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_; | 284 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_; |
304 | 285 |
305 // For JoinSession requests. | 286 // For JoinSession requests. |
306 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>> | 287 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>> |
307 pending_join_session_cbs_; | 288 pending_join_session_cbs_; |
308 | 289 |
309 scoped_ptr<DefaultSessionStartContext> default_session_start_context_; | |
310 | |
311 // RAII binding of |this| to an Presentation interface request. | 290 // RAII binding of |this| to an Presentation interface request. |
312 // The binding is removed when binding_ is cleared or goes out of scope. | 291 // The binding is removed when binding_ is cleared or goes out of scope. |
313 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; | 292 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; |
314 | 293 |
315 // There can be only one send message request at a time. | 294 // There can be only one send message request at a time. |
316 scoped_ptr<SendMessageMojoCallback> send_message_callback_; | 295 scoped_ptr<SendMessageMojoCallback> send_message_callback_; |
317 | 296 |
318 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; | 297 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; |
319 | 298 |
| 299 PresentationSessionMojoCallback receiver_session_callback_; |
| 300 |
320 // ID of the RenderFrameHost this object is associated with. | 301 // ID of the RenderFrameHost this object is associated with. |
321 int render_process_id_; | 302 int render_process_id_; |
322 int render_frame_id_; | 303 int render_frame_id_; |
323 | 304 |
324 // NOTE: Weak pointers must be invalidated before all other member variables. | 305 // NOTE: Weak pointers must be invalidated before all other member variables. |
325 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 306 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
326 | 307 |
327 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 308 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
328 }; | 309 }; |
329 | 310 |
330 } // namespace content | 311 } // namespace content |
331 | 312 |
332 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 313 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |