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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ListenForSessionStateChange); |
94 // Maximum number of pending JoinSession requests at any given time. | 94 // Maximum number of pending JoinSession requests at any given time. |
95 static const int kMaxNumQueuedSessionRequests = 10; | 95 static const int kMaxNumQueuedSessionRequests = 10; |
96 | 96 |
97 using PresentationSessionMojoCallback = | 97 using DefaultSessionMojoCallback = |
98 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; | 98 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; |
99 using SessionStateCallback = | 99 using SessionStateCallback = |
100 mojo::Callback<void(presentation::PresentationSessionInfoPtr, | 100 mojo::Callback<void(presentation::PresentationSessionInfoPtr, |
101 presentation::PresentationConnectionState)>; | 101 presentation::PresentationConnectionState)>; |
102 using SessionMessagesCallback = | 102 using SessionMessagesCallback = |
103 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; | 103 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; |
104 using SendMessageMojoCallback = mojo::Callback<void(bool)>; | 104 using SendMessageMojoCallback = mojo::Callback<void(bool)>; |
105 | 105 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 106 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 107 // this is created when PresentationRequest.getAvailability() is resolved. |
(...skipping 10 matching lines...) Expand all Loading... |
118 // PresentationScreenAvailabilityListener implementation. | 118 // PresentationScreenAvailabilityListener implementation. |
119 std::string GetAvailabilityUrl() const override; | 119 std::string GetAvailabilityUrl() const override; |
120 void OnScreenAvailabilityChanged(bool available) override; | 120 void OnScreenAvailabilityChanged(bool available) override; |
121 void OnScreenAvailabilityNotSupported() override; | 121 void OnScreenAvailabilityNotSupported() override; |
122 | 122 |
123 private: | 123 private: |
124 const std::string availability_url_; | 124 const std::string availability_url_; |
125 PresentationServiceImpl* const service_; | 125 PresentationServiceImpl* const service_; |
126 }; | 126 }; |
127 | 127 |
| 128 class CONTENT_EXPORT DefaultSessionStartContext { |
| 129 public: |
| 130 DefaultSessionStartContext(); |
| 131 ~DefaultSessionStartContext(); |
| 132 |
| 133 // Adds a callback. May invoke the callback immediately if |session| using |
| 134 // default presentation URL was already started. |
| 135 void AddCallback(const DefaultSessionMojoCallback& callback); |
| 136 |
| 137 // Sets the session info. Maybe invoke callbacks queued with AddCallback(). |
| 138 void set_session(const PresentationSessionInfo& session); |
| 139 |
| 140 private: |
| 141 // Flush all queued callbacks by invoking them with null |
| 142 // PresentationSessionInfoPtr. |
| 143 void Reset(); |
| 144 |
| 145 ScopedVector<DefaultSessionMojoCallback> callbacks_; |
| 146 scoped_ptr<PresentationSessionInfo> session_; |
| 147 }; |
| 148 |
128 // Ensures the provided NewSessionMojoCallback is invoked exactly once | 149 // Ensures the provided NewSessionMojoCallback is invoked exactly once |
129 // before it goes out of scope. | 150 // before it goes out of scope. |
130 class NewSessionMojoCallbackWrapper { | 151 class NewSessionMojoCallbackWrapper { |
131 public: | 152 public: |
132 explicit NewSessionMojoCallbackWrapper( | 153 explicit NewSessionMojoCallbackWrapper( |
133 const NewSessionMojoCallback& callback); | 154 const NewSessionMojoCallback& callback); |
134 ~NewSessionMojoCallbackWrapper(); | 155 ~NewSessionMojoCallbackWrapper(); |
135 | 156 |
136 void Run(presentation::PresentationSessionInfoPtr session, | 157 void Run(presentation::PresentationSessionInfoPtr session, |
137 presentation::PresentationErrorPtr error); | 158 presentation::PresentationErrorPtr error); |
(...skipping 11 matching lines...) Expand all Loading... |
149 PresentationServiceImpl( | 170 PresentationServiceImpl( |
150 RenderFrameHost* render_frame_host, | 171 RenderFrameHost* render_frame_host, |
151 WebContents* web_contents, | 172 WebContents* web_contents, |
152 PresentationServiceDelegate* delegate); | 173 PresentationServiceDelegate* delegate); |
153 | 174 |
154 // PresentationService implementation. | 175 // PresentationService implementation. |
155 void SetDefaultPresentationURL(const mojo::String& url) override; | 176 void SetDefaultPresentationURL(const mojo::String& url) override; |
156 void SetClient(presentation::PresentationServiceClientPtr client) override; | 177 void SetClient(presentation::PresentationServiceClientPtr client) override; |
157 void ListenForScreenAvailability(const mojo::String& url) override; | 178 void ListenForScreenAvailability(const mojo::String& url) override; |
158 void StopListeningForScreenAvailability(const mojo::String& url) override; | 179 void StopListeningForScreenAvailability(const mojo::String& url) override; |
| 180 void ListenForDefaultSessionStart( |
| 181 const DefaultSessionMojoCallback& callback) override; |
159 void StartSession( | 182 void StartSession( |
160 const mojo::String& presentation_url, | 183 const mojo::String& presentation_url, |
161 const NewSessionMojoCallback& callback) override; | 184 const NewSessionMojoCallback& callback) override; |
162 void JoinSession( | 185 void JoinSession( |
163 const mojo::String& presentation_url, | 186 const mojo::String& presentation_url, |
164 const mojo::String& presentation_id, | 187 const mojo::String& presentation_id, |
165 const NewSessionMojoCallback& callback) override; | 188 const NewSessionMojoCallback& callback) override; |
166 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, | 189 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, |
167 presentation::SessionMessagePtr session_message, | 190 presentation::SessionMessagePtr session_message, |
168 const SendMessageMojoCallback& callback) override; | 191 const SendMessageMojoCallback& callback) override; |
169 void CloseSession( | 192 void CloseSession( |
170 const mojo::String& presentation_url, | 193 const mojo::String& presentation_url, |
171 const mojo::String& presentation_id) override; | 194 const mojo::String& presentation_id) override; |
172 void ListenForSessionStateChange() override; | 195 void ListenForSessionStateChange() override; |
173 void ListenForSessionMessages( | 196 void ListenForSessionMessages( |
174 presentation::PresentationSessionInfoPtr session) override; | 197 presentation::PresentationSessionInfoPtr session) override; |
175 | 198 |
176 // Creates a binding between this object and |request|. | 199 // Creates a binding between this object and |request|. |
177 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); | 200 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); |
178 | 201 |
179 // WebContentsObserver override. | 202 // WebContentsObserver override. |
180 void DidNavigateAnyFrame( | 203 void DidNavigateAnyFrame( |
181 content::RenderFrameHost* render_frame_host, | 204 content::RenderFrameHost* render_frame_host, |
182 const content::LoadCommittedDetails& details, | 205 const content::LoadCommittedDetails& details, |
183 const content::FrameNavigateParams& params) override; | 206 const content::FrameNavigateParams& params) override; |
184 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 207 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
185 | 208 |
186 // PresentationServiceDelegate::Observer | 209 // PresentationServiceDelegate::Observer |
187 void OnDelegateDestroyed() override; | 210 void OnDelegateDestroyed() override; |
188 | 211 void OnDefaultPresentationStarted(const PresentationSessionInfo& session) |
189 // Passed to embedder's implementation of PresentationServiceDelegate for | 212 override; |
190 // later invocation when default presentation has started. | |
191 void OnDefaultPresentationStarted( | |
192 const PresentationSessionInfo& session_info); | |
193 | 213 |
194 // Finds the callback from |pending_join_session_cbs_| using | 214 // Finds the callback from |pending_join_session_cbs_| using |
195 // |request_session_id|. | 215 // |request_session_id|. |
196 // If it exists, invoke it with |session| and |error|, then erase it from | 216 // If it exists, invoke it with |session| and |error|, then erase it from |
197 // |pending_join_session_cbs_|. | 217 // |pending_join_session_cbs_|. |
198 void RunAndEraseJoinSessionMojoCallback( | 218 void RunAndEraseJoinSessionMojoCallback( |
199 int request_session_id, | 219 int request_session_id, |
200 presentation::PresentationSessionInfoPtr session, | 220 presentation::PresentationSessionInfoPtr session, |
201 presentation::PresentationErrorPtr error); | 221 presentation::PresentationErrorPtr error); |
202 | 222 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 277 |
258 // For StartSession requests. | 278 // For StartSession requests. |
259 // Set to a positive value when a StartSession request is being processed. | 279 // Set to a positive value when a StartSession request is being processed. |
260 int start_session_request_id_; | 280 int start_session_request_id_; |
261 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_; | 281 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_; |
262 | 282 |
263 // For JoinSession requests. | 283 // For JoinSession requests. |
264 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>> | 284 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>> |
265 pending_join_session_cbs_; | 285 pending_join_session_cbs_; |
266 | 286 |
| 287 scoped_ptr<DefaultSessionStartContext> default_session_start_context_; |
| 288 |
267 // RAII binding of |this| to an Presentation interface request. | 289 // RAII binding of |this| to an Presentation interface request. |
268 // The binding is removed when binding_ is cleared or goes out of scope. | 290 // The binding is removed when binding_ is cleared or goes out of scope. |
269 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; | 291 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; |
270 | 292 |
271 // There can be only one send message request at a time. | 293 // There can be only one send message request at a time. |
272 scoped_ptr<SendMessageMojoCallback> send_message_callback_; | 294 scoped_ptr<SendMessageMojoCallback> send_message_callback_; |
273 | 295 |
274 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; | 296 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; |
275 | 297 |
276 // ID of the RenderFrameHost this object is associated with. | 298 // ID of the RenderFrameHost this object is associated with. |
277 int render_process_id_; | 299 int render_process_id_; |
278 int render_frame_id_; | 300 int render_frame_id_; |
279 | 301 |
280 // NOTE: Weak pointers must be invalidated before all other member variables. | 302 // NOTE: Weak pointers must be invalidated before all other member variables. |
281 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 303 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
282 | 304 |
283 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 305 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
284 }; | 306 }; |
285 | 307 |
286 } // namespace content | 308 } // namespace content |
287 | 309 |
288 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 310 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |