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