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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 PresentationServiceImpl* const service_; | 145 PresentationServiceImpl* const service_; |
146 }; | 146 }; |
147 | 147 |
148 class CONTENT_EXPORT DefaultSessionStartContext { | 148 class CONTENT_EXPORT DefaultSessionStartContext { |
149 public: | 149 public: |
150 DefaultSessionStartContext(); | 150 DefaultSessionStartContext(); |
151 ~DefaultSessionStartContext(); | 151 ~DefaultSessionStartContext(); |
152 | 152 |
153 // Adds a callback. May invoke the callback immediately if |session| using | 153 // Adds a callback. May invoke the callback immediately if |session| using |
154 // default presentation URL was already started. | 154 // default presentation URL was already started. |
155 void AddCallback(const DefaultSessionMojoCallback& callback); | 155 void AddCallback(const PresentationSessionMojoCallback& callback); |
156 | 156 |
157 // Sets the session info. Maybe invoke callbacks queued with AddCallback(). | 157 // Sets the session info. Maybe invoke callbacks queued with AddCallback(). |
158 void set_session(const PresentationSessionInfo& session); | 158 void set_session(const PresentationSessionInfo& session); |
159 | 159 |
160 private: | 160 private: |
161 // Flush all queued callbacks by invoking them with null | 161 // Flush all queued callbacks by invoking them with null |
162 // PresentationSessionInfoPtr. | 162 // PresentationSessionInfoPtr. |
163 void Reset(); | 163 void Reset(); |
164 | 164 |
165 ScopedVector<DefaultSessionMojoCallback> callbacks_; | 165 ScopedVector<PresentationSessionMojoCallback> callbacks_; |
166 scoped_ptr<PresentationSessionInfo> session_; | 166 scoped_ptr<PresentationSessionInfo> session_; |
167 }; | 167 }; |
168 | 168 |
169 // Ensures the provided NewSessionMojoCallback is invoked exactly once | 169 // Ensures the provided NewSessionMojoCallback is invoked exactly once |
170 // before it goes out of scope. | 170 // before it goes out of scope. |
171 class NewSessionMojoCallbackWrapper { | 171 class NewSessionMojoCallbackWrapper { |
172 public: | 172 public: |
173 explicit NewSessionMojoCallbackWrapper( | 173 explicit NewSessionMojoCallbackWrapper( |
174 const NewSessionMojoCallback& callback); | 174 const NewSessionMojoCallback& callback); |
175 ~NewSessionMojoCallbackWrapper(); | 175 ~NewSessionMojoCallbackWrapper(); |
(...skipping 15 matching lines...) Expand all Loading... |
191 RenderFrameHost* render_frame_host, | 191 RenderFrameHost* render_frame_host, |
192 WebContents* web_contents, | 192 WebContents* web_contents, |
193 PresentationServiceDelegate* delegate); | 193 PresentationServiceDelegate* delegate); |
194 | 194 |
195 // PresentationService implementation. | 195 // PresentationService implementation. |
196 void SetDefaultPresentationURL(const mojo::String& url) override; | 196 void SetDefaultPresentationURL(const mojo::String& url) override; |
197 void SetClient(presentation::PresentationServiceClientPtr client) override; | 197 void SetClient(presentation::PresentationServiceClientPtr client) override; |
198 void ListenForScreenAvailability(const mojo::String& url) override; | 198 void ListenForScreenAvailability(const mojo::String& url) override; |
199 void StopListeningForScreenAvailability(const mojo::String& url) override; | 199 void StopListeningForScreenAvailability(const mojo::String& url) override; |
200 void ListenForDefaultSessionStart( | 200 void ListenForDefaultSessionStart( |
201 const DefaultSessionMojoCallback& callback) override; | 201 const PresentationSessionMojoCallback& callback) override; |
202 void StartSession( | 202 void StartSession( |
203 const mojo::String& presentation_url, | 203 const mojo::String& presentation_url, |
204 const NewSessionMojoCallback& callback) override; | 204 const NewSessionMojoCallback& callback) override; |
205 void JoinSession( | 205 void JoinSession( |
206 const mojo::String& presentation_url, | 206 const mojo::String& presentation_url, |
207 const mojo::String& presentation_id, | 207 const mojo::String& presentation_id, |
208 const NewSessionMojoCallback& callback) override; | 208 const NewSessionMojoCallback& callback) override; |
209 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, | 209 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, |
210 presentation::SessionMessagePtr session_message, | 210 presentation::SessionMessagePtr session_message, |
211 const SendMessageMojoCallback& callback) override; | 211 const SendMessageMojoCallback& callback) override; |
212 void CloseSession( | 212 void CloseSession( |
213 const mojo::String& presentation_url, | 213 const mojo::String& presentation_url, |
214 const mojo::String& presentation_id) override; | 214 const mojo::String& presentation_id) override; |
215 void ListenForSessionStateChange( | 215 void ListenForSessionStateChange( |
216 presentation::PresentationSessionInfoPtr session) override; | 216 presentation::PresentationSessionInfoPtr session) override; |
217 void ListenForSessionMessages( | 217 void ListenForSessionMessages( |
218 presentation::PresentationSessionInfoPtr session) override; | 218 presentation::PresentationSessionInfoPtr session) override; |
| 219 void GetPresentationReceiverSession( |
| 220 const PresentationSessionMojoCallback& callback) override; |
219 | 221 |
220 // Creates a binding between this object and |request|. | 222 // Creates a binding between this object and |request|. |
221 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); | 223 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); |
222 | 224 |
223 // WebContentsObserver override. | 225 // WebContentsObserver override. |
224 void DidNavigateAnyFrame( | 226 void DidNavigateAnyFrame( |
225 content::RenderFrameHost* render_frame_host, | 227 content::RenderFrameHost* render_frame_host, |
226 const content::LoadCommittedDetails& details, | 228 const content::LoadCommittedDetails& details, |
227 const content::FrameNavigateParams& params) override; | 229 const content::FrameNavigateParams& params) override; |
228 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 230 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
(...skipping 25 matching lines...) Expand all Loading... |
254 void OnStartSessionError( | 256 void OnStartSessionError( |
255 int request_session_id, | 257 int request_session_id, |
256 const PresentationError& error); | 258 const PresentationError& error); |
257 void OnJoinSessionSucceeded( | 259 void OnJoinSessionSucceeded( |
258 int request_session_id, | 260 int request_session_id, |
259 const PresentationSessionInfo& session_info); | 261 const PresentationSessionInfo& session_info); |
260 void OnJoinSessionError( | 262 void OnJoinSessionError( |
261 int request_session_id, | 263 int request_session_id, |
262 const PresentationError& error); | 264 const PresentationError& error); |
263 void OnSendMessageCallback(bool sent); | 265 void OnSendMessageCallback(bool sent); |
| 266 void OnGetPresentationReceiverSession( |
| 267 const content::PresentationSessionInfo* session_info); |
264 | 268 |
265 // Passed to embedder's implementation of PresentationServiceDelegate for | 269 // Passed to embedder's implementation of PresentationServiceDelegate for |
266 // later invocation when session messages arrive. | 270 // later invocation when session messages arrive. |
267 void OnSessionMessages( | 271 void OnSessionMessages( |
268 const content::PresentationSessionInfo& session, | 272 const content::PresentationSessionInfo& session, |
269 const ScopedVector<PresentationSessionMessage>& messages, | 273 const ScopedVector<PresentationSessionMessage>& messages, |
270 bool pass_ownership); | 274 bool pass_ownership); |
271 | 275 |
272 // Associates a JoinSession |callback| with a unique request ID and | 276 // Associates a JoinSession |callback| with a unique request ID and |
273 // stores it in a map. | 277 // stores it in a map. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 314 |
311 // RAII binding of |this| to an Presentation interface request. | 315 // RAII binding of |this| to an Presentation interface request. |
312 // The binding is removed when binding_ is cleared or goes out of scope. | 316 // The binding is removed when binding_ is cleared or goes out of scope. |
313 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; | 317 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; |
314 | 318 |
315 // There can be only one send message request at a time. | 319 // There can be only one send message request at a time. |
316 scoped_ptr<SendMessageMojoCallback> send_message_callback_; | 320 scoped_ptr<SendMessageMojoCallback> send_message_callback_; |
317 | 321 |
318 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; | 322 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; |
319 | 323 |
| 324 PresentationSessionMojoCallback receiver_session_callback_; |
| 325 |
320 // ID of the RenderFrameHost this object is associated with. | 326 // ID of the RenderFrameHost this object is associated with. |
321 int render_process_id_; | 327 int render_process_id_; |
322 int render_frame_id_; | 328 int render_frame_id_; |
323 | 329 |
324 // NOTE: Weak pointers must be invalidated before all other member variables. | 330 // NOTE: Weak pointers must be invalidated before all other member variables. |
325 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 331 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
326 | 332 |
327 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 333 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
328 }; | 334 }; |
329 | 335 |
330 } // namespace content | 336 } // namespace content |
331 | 337 |
332 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 338 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |