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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 using ScreenAvailabilityMojoCallback = | 57 using ScreenAvailabilityMojoCallback = |
58 mojo::Callback<void(mojo::String, bool)>; | 58 mojo::Callback<void(mojo::String, bool)>; |
59 using NewSessionMojoCallback = | 59 using NewSessionMojoCallback = |
60 mojo::Callback<void(presentation::PresentationSessionInfoPtr, | 60 mojo::Callback<void(presentation::PresentationSessionInfoPtr, |
61 presentation::PresentationErrorPtr)>; | 61 presentation::PresentationErrorPtr)>; |
62 using DefaultSessionMojoCallback = | 62 using DefaultSessionMojoCallback = |
63 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; | 63 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; |
64 using SessionStateCallback = | 64 using SessionStateCallback = |
65 mojo::Callback<void(presentation::PresentationSessionInfoPtr, | 65 mojo::Callback<void(presentation::PresentationSessionInfoPtr, |
66 presentation::PresentationSessionState)>; | 66 presentation::PresentationSessionState)>; |
| 67 using SendMessageMojoCallback = mojo::Callback<void()>; |
67 | 68 |
68 // A helper data class used by PresentationServiceImpl to do bookkeeping | 69 // A helper data class used by PresentationServiceImpl to do bookkeeping |
69 // of currently registered screen availability listeners. | 70 // of currently registered screen availability listeners. |
70 // An instance of this class is a simple state machine that waits for both | 71 // An instance of this class is a simple state machine that waits for both |
71 // the available bit and the Mojo callback to become available. | 72 // the available bit and the Mojo callback to become available. |
72 // Once this happens, the Mojo callback will be invoked with the available | 73 // Once this happens, the Mojo callback will be invoked with the available |
73 // bit, and the state machine will reset. | 74 // bit, and the state machine will reset. |
74 // The available bit is obtained from the embedder's media router. | 75 // The available bit is obtained from the embedder's media router. |
75 // The callback is obtained from the renderer via PresentationServiceImpl's | 76 // The callback is obtained from the renderer via PresentationServiceImpl's |
76 // ListenForScreenAvailability(). | 77 // ListenForScreenAvailability(). |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void ListenForDefaultSessionStart( | 160 void ListenForDefaultSessionStart( |
160 const DefaultSessionMojoCallback& callback) override; | 161 const DefaultSessionMojoCallback& callback) override; |
161 void StartSession( | 162 void StartSession( |
162 const mojo::String& presentation_url, | 163 const mojo::String& presentation_url, |
163 const mojo::String& presentation_id, | 164 const mojo::String& presentation_id, |
164 const NewSessionMojoCallback& callback) override; | 165 const NewSessionMojoCallback& callback) override; |
165 void JoinSession( | 166 void JoinSession( |
166 const mojo::String& presentation_url, | 167 const mojo::String& presentation_url, |
167 const mojo::String& presentation_id, | 168 const mojo::String& presentation_id, |
168 const NewSessionMojoCallback& callback) override; | 169 const NewSessionMojoCallback& callback) override; |
| 170 void SendStringMessage( |
| 171 const mojo::String& presentation_url, |
| 172 const mojo::String& presentation_id, |
| 173 const mojo::String& message, |
| 174 const SendMessageMojoCallback& callback) override; |
169 void CloseSession( | 175 void CloseSession( |
170 const mojo::String& presentation_url, | 176 const mojo::String& presentation_url, |
171 const mojo::String& presentation_id) override; | 177 const mojo::String& presentation_id) override; |
172 void ListenForSessionStateChange( | 178 void ListenForSessionStateChange( |
173 const SessionStateCallback& callback) override; | 179 const SessionStateCallback& callback) override; |
174 | 180 |
175 // Creates a binding between this object and |request|. | 181 // Creates a binding between this object and |request|. |
176 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); | 182 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); |
177 | 183 |
178 // mojo::ErrorHandler override. | 184 // mojo::ErrorHandler override. |
(...skipping 21 matching lines...) Expand all Loading... |
200 // Sets |default_presentation_url_| to |presentation_url| and informs the | 206 // Sets |default_presentation_url_| to |presentation_url| and informs the |
201 // delegate of new default presentation URL and ID. | 207 // delegate of new default presentation URL and ID. |
202 void DoSetDefaultPresentationUrl( | 208 void DoSetDefaultPresentationUrl( |
203 const std::string& presentation_url, | 209 const std::string& presentation_url, |
204 const std::string& presentation_id); | 210 const std::string& presentation_id); |
205 | 211 |
206 // Removes all listeners and resets default presentation URL on this instance | 212 // Removes all listeners and resets default presentation URL on this instance |
207 // and informs the PresentationServiceDelegate of such. | 213 // and informs the PresentationServiceDelegate of such. |
208 void Reset(); | 214 void Reset(); |
209 | 215 |
210 // These two functions are bound as base::Callbacks and passed to | 216 // These functions are bound as base::Callbacks and passed to |
211 // embedder's implementation of PresentationServiceDelegate for later | 217 // embedder's implementation of PresentationServiceDelegate for later |
212 // invocation. | 218 // invocation. |
213 void OnStartOrJoinSessionSucceeded( | 219 void OnStartOrJoinSessionSucceeded( |
214 bool is_start_session, | 220 bool is_start_session, |
215 int request_session_id, | 221 int request_session_id, |
216 const PresentationSessionInfo& session_info); | 222 const PresentationSessionInfo& session_info); |
217 void OnStartOrJoinSessionError( | 223 void OnStartOrJoinSessionError( |
218 bool is_start_session, | 224 bool is_start_session, |
219 int request_session_id, | 225 int request_session_id, |
220 const PresentationError& error); | 226 const PresentationError& error); |
| 227 void OnSendMessageCallback(); |
221 | 228 |
222 // Requests delegate to start a session. | 229 // Requests delegate to start a session. |
223 void DoStartSession( | 230 void DoStartSession( |
224 const std::string& presentation_url, | 231 const std::string& presentation_url, |
225 const std::string& presentation_id, | 232 const std::string& presentation_id, |
226 const NewSessionMojoCallback& callback); | 233 const NewSessionMojoCallback& callback); |
227 | 234 |
228 // Removes the head of the queue (which represents the request that has just | 235 // Removes the head of the queue (which represents the request that has just |
229 // been processed). | 236 // been processed). |
230 // Checks if there are any queued StartSession requests and if so, executes | 237 // Checks if there are any queued StartSession requests and if so, executes |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 int next_request_session_id_; | 269 int next_request_session_id_; |
263 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; | 270 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; |
264 | 271 |
265 // RAII binding of |this| to an Presentation interface request. | 272 // RAII binding of |this| to an Presentation interface request. |
266 // The binding is removed when binding_ is cleared or goes out of scope. | 273 // The binding is removed when binding_ is cleared or goes out of scope. |
267 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; | 274 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; |
268 | 275 |
269 // NOTE: Weak pointers must be invalidated before all other member variables. | 276 // NOTE: Weak pointers must be invalidated before all other member variables. |
270 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 277 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
271 | 278 |
| 279 // There could be be one send message request at a time. |
| 280 scoped_ptr<SendMessageMojoCallback> send_message_cb_ptr_; |
| 281 |
272 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 282 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
273 }; | 283 }; |
274 | 284 |
275 } // namespace content | 285 } // namespace content |
276 | 286 |
277 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 287 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |