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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ListenForDefaultSessionStartAfterSet); | 83 ListenForDefaultSessionStartAfterSet); |
84 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 84 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
85 DefaultSessionStartReset); | 85 DefaultSessionStartReset); |
86 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 86 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
87 ReceiveSessionMessagesAfterReset); | 87 ReceiveSessionMessagesAfterReset); |
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
89 MaxPendingStartSessionRequests); | 89 MaxPendingStartSessionRequests); |
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
91 MaxPendingJoinSessionRequests); | 91 MaxPendingJoinSessionRequests); |
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
93 ListenForSessionStateChange); | 93 ListenForConnectionStateChange); |
| 94 |
94 // Maximum number of pending JoinSession requests at any given time. | 95 // Maximum number of pending JoinSession requests at any given time. |
95 static const int kMaxNumQueuedSessionRequests = 10; | 96 static const int kMaxNumQueuedSessionRequests = 10; |
96 | 97 |
97 using PresentationSessionMojoCallback = | 98 using PresentationSessionMojoCallback = |
98 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; | 99 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; |
99 using SessionStateCallback = | |
100 mojo::Callback<void(presentation::PresentationSessionInfoPtr, | |
101 presentation::PresentationConnectionState)>; | |
102 using SessionMessagesCallback = | 100 using SessionMessagesCallback = |
103 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; | 101 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; |
104 using SendMessageMojoCallback = mojo::Callback<void(bool)>; | 102 using SendMessageMojoCallback = mojo::Callback<void(bool)>; |
105 | 103 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 104 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 105 // this is created when PresentationRequest.getAvailability() is resolved. |
108 // The instance receives screen availability results from the embedder and | 106 // The instance receives screen availability results from the embedder and |
109 // propagates results back to PresentationServiceImpl. | 107 // propagates results back to PresentationServiceImpl. |
110 class CONTENT_EXPORT ScreenAvailabilityListenerImpl | 108 class CONTENT_EXPORT ScreenAvailabilityListenerImpl |
111 : public PresentationScreenAvailabilityListener { | 109 : public PresentationScreenAvailabilityListener { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void JoinSession( | 160 void JoinSession( |
163 const mojo::String& presentation_url, | 161 const mojo::String& presentation_url, |
164 const mojo::String& presentation_id, | 162 const mojo::String& presentation_id, |
165 const NewSessionMojoCallback& callback) override; | 163 const NewSessionMojoCallback& callback) override; |
166 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, | 164 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, |
167 presentation::SessionMessagePtr session_message, | 165 presentation::SessionMessagePtr session_message, |
168 const SendMessageMojoCallback& callback) override; | 166 const SendMessageMojoCallback& callback) override; |
169 void CloseSession( | 167 void CloseSession( |
170 const mojo::String& presentation_url, | 168 const mojo::String& presentation_url, |
171 const mojo::String& presentation_id) override; | 169 const mojo::String& presentation_id) override; |
172 void ListenForSessionStateChange() override; | |
173 void ListenForSessionMessages( | 170 void ListenForSessionMessages( |
174 presentation::PresentationSessionInfoPtr session) override; | 171 presentation::PresentationSessionInfoPtr session) override; |
175 | 172 |
176 // Creates a binding between this object and |request|. | 173 // Creates a binding between this object and |request|. |
177 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); | 174 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); |
178 | 175 |
179 // WebContentsObserver override. | 176 // WebContentsObserver override. |
180 void DidNavigateAnyFrame( | 177 void DidNavigateAnyFrame( |
181 content::RenderFrameHost* render_frame_host, | 178 content::RenderFrameHost* render_frame_host, |
182 const content::LoadCommittedDetails& details, | 179 const content::LoadCommittedDetails& details, |
183 const content::FrameNavigateParams& params) override; | 180 const content::FrameNavigateParams& params) override; |
184 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 181 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
185 | 182 |
186 // PresentationServiceDelegate::Observer | 183 // PresentationServiceDelegate::Observer |
187 void OnDelegateDestroyed() override; | 184 void OnDelegateDestroyed() override; |
188 | 185 |
189 // Passed to embedder's implementation of PresentationServiceDelegate for | 186 // Passed to embedder's implementation of PresentationServiceDelegate for |
190 // later invocation when default presentation has started. | 187 // later invocation when default presentation has started. |
191 void OnDefaultPresentationStarted( | 188 void OnDefaultPresentationStarted( |
192 const PresentationSessionInfo& session_info); | 189 const PresentationSessionInfo& session_info); |
193 | 190 |
194 // Finds the callback from |pending_join_session_cbs_| using | 191 // Finds the callback from |pending_join_session_cbs_| using |
195 // |request_session_id|. | 192 // |request_session_id|. |
196 // If it exists, invoke it with |session| and |error|, then erase it from | 193 // If it exists, invoke it with |session| and |error|, then erase it from |
197 // |pending_join_session_cbs_|. | 194 // |pending_join_session_cbs_|. |
198 void RunAndEraseJoinSessionMojoCallback( | 195 // Returns true if the callback was found. |
| 196 bool RunAndEraseJoinSessionMojoCallback( |
199 int request_session_id, | 197 int request_session_id, |
200 presentation::PresentationSessionInfoPtr session, | 198 presentation::PresentationSessionInfoPtr session, |
201 presentation::PresentationErrorPtr error); | 199 presentation::PresentationErrorPtr error); |
202 | 200 |
203 // Removes all listeners and resets default presentation URL on this instance | 201 // Removes all listeners and resets default presentation URL on this instance |
204 // and informs the PresentationServiceDelegate of such. | 202 // and informs the PresentationServiceDelegate of such. |
205 void Reset(); | 203 void Reset(); |
206 | 204 |
207 // These functions are bound as base::Callbacks and passed to | 205 // These functions are bound as base::Callbacks and passed to |
208 // embedder's implementation of PresentationServiceDelegate for later | 206 // embedder's implementation of PresentationServiceDelegate for later |
209 // invocation. | 207 // invocation. |
210 void OnStartSessionSucceeded( | 208 void OnStartSessionSucceeded( |
211 int request_session_id, | 209 int request_session_id, |
212 const PresentationSessionInfo& session_info); | 210 const PresentationSessionInfo& session_info); |
213 void OnStartSessionError( | 211 void OnStartSessionError( |
214 int request_session_id, | 212 int request_session_id, |
215 const PresentationError& error); | 213 const PresentationError& error); |
216 void OnJoinSessionSucceeded( | 214 void OnJoinSessionSucceeded( |
217 int request_session_id, | 215 int request_session_id, |
218 const PresentationSessionInfo& session_info); | 216 const PresentationSessionInfo& session_info); |
219 void OnJoinSessionError( | 217 void OnJoinSessionError( |
220 int request_session_id, | 218 int request_session_id, |
221 const PresentationError& error); | 219 const PresentationError& error); |
222 void OnSendMessageCallback(bool sent); | 220 void OnSendMessageCallback(bool sent); |
223 | 221 |
| 222 // Calls to |delegate_| to start listening for state changes for |connection|. |
| 223 // State changes will be returned via |OnConnectionStateChanged|. |
| 224 void ListenForConnectionStateChange( |
| 225 const PresentationSessionInfo& connection); |
| 226 |
224 // Passed to embedder's implementation of PresentationServiceDelegate for | 227 // Passed to embedder's implementation of PresentationServiceDelegate for |
225 // later invocation when session messages arrive. | 228 // later invocation when session messages arrive. |
226 void OnSessionMessages( | 229 void OnSessionMessages( |
227 const content::PresentationSessionInfo& session, | 230 const content::PresentationSessionInfo& session, |
228 const ScopedVector<PresentationSessionMessage>& messages, | 231 const ScopedVector<PresentationSessionMessage>& messages, |
229 bool pass_ownership); | 232 bool pass_ownership); |
230 | 233 |
231 // Associates a JoinSession |callback| with a unique request ID and | 234 // Associates a JoinSession |callback| with a unique request ID and |
232 // stores it in a map. | 235 // stores it in a map. |
233 // Returns a positive value on success. | 236 // Returns a positive value on success. |
234 int RegisterJoinSessionCallback(const NewSessionMojoCallback& callback); | 237 int RegisterJoinSessionCallback(const NewSessionMojoCallback& callback); |
235 | 238 |
236 // Invoked by the embedder's PresentationServiceDelegate when a | 239 // Invoked by the embedder's PresentationServiceDelegate when a |
237 // presentation session's state has changed. | 240 // PresentationConnection's state has changed. |
238 void OnSessionStateChanged(const PresentationSessionInfo& session_info, | 241 void OnConnectionStateChanged(const PresentationSessionInfo& connection, |
239 PresentationConnectionState session_state); | 242 PresentationConnectionState state); |
240 | 243 |
241 // Returns true if this object is associated with |render_frame_host|. | 244 // Returns true if this object is associated with |render_frame_host|. |
242 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; | 245 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; |
243 | 246 |
244 // Embedder-specific delegate to forward Presentation requests to. | 247 // Embedder-specific delegate to forward Presentation requests to. |
245 // May be null if embedder does not support Presentation API. | 248 // May be null if embedder does not support Presentation API. |
246 PresentationServiceDelegate* delegate_; | 249 PresentationServiceDelegate* delegate_; |
247 | 250 |
248 // Proxy to the PresentationServiceClient to send results (e.g., screen | 251 // Proxy to the PresentationServiceClient to send results (e.g., screen |
249 // availability) to. | 252 // availability) to. |
(...skipping 29 matching lines...) Expand all Loading... |
279 | 282 |
280 // NOTE: Weak pointers must be invalidated before all other member variables. | 283 // NOTE: Weak pointers must be invalidated before all other member variables. |
281 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 284 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
282 | 285 |
283 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 286 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
284 }; | 287 }; |
285 | 288 |
286 } // namespace content | 289 } // namespace content |
287 | 290 |
288 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 291 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |