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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 // WebContentsObserver override. | 174 // WebContentsObserver override. |
175 void DidNavigateAnyFrame( | 175 void DidNavigateAnyFrame( |
176 content::RenderFrameHost* render_frame_host, | 176 content::RenderFrameHost* render_frame_host, |
177 const content::LoadCommittedDetails& details, | 177 const content::LoadCommittedDetails& details, |
178 const content::FrameNavigateParams& params) override; | 178 const content::FrameNavigateParams& params) override; |
179 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 179 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
180 | 180 |
181 // PresentationServiceDelegate::Observer | 181 // PresentationServiceDelegate::Observer |
182 void OnDelegateDestroyed() override; | 182 void OnDelegateDestroyed() override; |
183 | 183 |
184 // Finds the callback from |pending_session_cbs_| using |request_session_id|. | |
185 // If it exists, invoke it with |session| and |error|, then erase it from | |
186 // |pending_session_cbs_|. | |
187 void RunAndEraseNewMojoCallback( | |
whywhat
2015/03/25 17:05:54
s/New/NewSession?
imcheng
2015/03/25 23:03:42
Done.
| |
188 int request_session_id, | |
189 presentation::PresentationSessionInfoPtr session, | |
190 presentation::PresentationErrorPtr error); | |
191 | |
184 // Sets |default_presentation_url_| to |presentation_url| and informs the | 192 // Sets |default_presentation_url_| to |presentation_url| and informs the |
185 // delegate of new default presentation URL and ID. | 193 // delegate of new default presentation URL and ID. |
186 void DoSetDefaultPresentationUrl( | 194 void DoSetDefaultPresentationUrl( |
187 const std::string& presentation_url, | 195 const std::string& presentation_url, |
188 const std::string& presentation_id); | 196 const std::string& presentation_id); |
189 | 197 |
190 // Removes all listeners and resets default presentation URL on this instance | 198 // Removes all listeners and resets default presentation URL on this instance |
191 // and informs the PresentationServiceDelegate of such. | 199 // and informs the PresentationServiceDelegate of such. |
192 void Reset(); | 200 void Reset(); |
193 | 201 |
194 // These two functions are bound as base::Callbacks and passed to | 202 // These two functions are bound as base::Callbacks and passed to |
195 // embedder's implementation of PresentationServiceDelegate for later | 203 // embedder's implementation of PresentationServiceDelegate for later |
196 // invocation. | 204 // invocation. |
197 void OnStartOrJoinSessionSucceeded( | 205 void OnStartOrJoinSessionSucceeded( |
198 bool is_start_session, | 206 bool is_start_session, |
199 const NewSessionMojoCallback& callback, | 207 int request_session_id, |
200 const PresentationSessionInfo& session_info); | 208 const PresentationSessionInfo& session_info); |
201 void OnStartOrJoinSessionError( | 209 void OnStartOrJoinSessionError( |
202 bool is_start_session, | 210 bool is_start_session, |
203 const NewSessionMojoCallback& callback, | 211 int request_session_id, |
204 const PresentationError& error); | 212 const PresentationError& error); |
205 | 213 |
206 // Requests delegate to start a session. | 214 // Requests delegate to start a session. |
207 void DoStartSession( | 215 void DoStartSession( |
208 const std::string& presentation_url, | 216 const std::string& presentation_url, |
209 const std::string& presentation_id, | 217 const std::string& presentation_id, |
210 const NewSessionMojoCallback& callback); | 218 const NewSessionMojoCallback& callback); |
211 | 219 |
212 // Removes the head of the queue (which represents the request that has just | 220 // Removes the head of the queue (which represents the request that has just |
213 // been processed). | 221 // been processed). |
214 // Checks if there are any queued StartSession requests and if so, executes | 222 // Checks if there are any queued StartSession requests and if so, executes |
215 // the first one in the queue. | 223 // the first one in the queue. |
216 void HandleQueuedStartSessionRequests(); | 224 void HandleQueuedStartSessionRequests(); |
217 | 225 |
226 // Invokes |callback| with an error. | |
227 void InvokeNewSessionMojoCallbackWithError( | |
228 const NewSessionMojoCallback& callback); | |
229 | |
218 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one | 230 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one |
219 // if it does not exist. | 231 // if it does not exist. |
220 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( | 232 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( |
221 const std::string& presentation_url); | 233 const std::string& presentation_url); |
222 | 234 |
223 RenderFrameHost* render_frame_host_; | 235 RenderFrameHost* render_frame_host_; |
224 PresentationServiceDelegate* delegate_; | 236 PresentationServiceDelegate* delegate_; |
225 | 237 |
226 // Map from presentation URL to its ScreenAvailabilityContext state machine. | 238 // Map from presentation URL to its ScreenAvailabilityContext state machine. |
227 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> | 239 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> |
228 availability_contexts_; | 240 availability_contexts_; |
229 | 241 |
230 std::string default_presentation_url_; | 242 std::string default_presentation_url_; |
231 std::string default_presentation_id_; | 243 std::string default_presentation_id_; |
232 | 244 |
233 // We only allow one StartSession request to be processed at a time. | 245 // We only allow one StartSession request to be processed at a time. |
234 // StartSession requests are queued here. When a request has been processed, | 246 // StartSession requests are queued here. When a request has been processed, |
235 // it is removed from head of the queue. | 247 // it is removed from head of the queue. |
236 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; | 248 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; |
237 | 249 |
250 int next_request_session_id_; | |
251 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; | |
whywhat
2015/03/25 17:05:54
Is it possible to just keep a set of Callback poin
imcheng
2015/03/25 23:03:42
I think that will be quite complicated to implemen
| |
252 | |
238 // NOTE: Weak pointers must be invalidated before all other member variables. | 253 // NOTE: Weak pointers must be invalidated before all other member variables. |
239 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 254 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
240 | 255 |
241 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 256 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
242 }; | 257 }; |
243 | 258 |
244 } // namespace content | 259 } // namespace content |
245 | 260 |
246 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 261 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |