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 #include "content/browser/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/presentation/presentation_type_converters.h" | 10 #include "content/browser/presentation/presentation_type_converters.h" |
11 #include "content/public/browser/content_browser_client.h" | 11 #include "content/public/browser/content_browser_client.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/presentation_session_message.h" | 13 #include "content/public/browser/presentation_session_message.h" |
14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "content/public/common/frame_navigate_params.h" | 18 #include "content/public/common/frame_navigate_params.h" |
19 #include "content/public/common/presentation_constants.h" | 19 #include "content/public/common/presentation_constants.h" |
20 | 20 |
| 21 namespace content { |
| 22 |
21 namespace { | 23 namespace { |
22 | 24 |
| 25 const int kInvalidRequestSessionId = -1; |
| 26 |
| 27 int GetNextRequestSessionId() { |
| 28 static int next_request_session_id = 0; |
| 29 return ++next_request_session_id; |
| 30 } |
| 31 |
23 // The return value takes ownership of the contents of |input|. | 32 // The return value takes ownership of the contents of |input|. |
24 presentation::SessionMessagePtr ToMojoSessionMessage( | 33 presentation::SessionMessagePtr ToMojoSessionMessage( |
25 content::PresentationSessionMessage* input) { | 34 content::PresentationSessionMessage* input) { |
26 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); | 35 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); |
27 output->presentation_url.Swap(&input->presentation_url); | 36 output->presentation_url.Swap(&input->presentation_url); |
28 output->presentation_id.Swap(&input->presentation_id); | 37 output->presentation_id.Swap(&input->presentation_id); |
29 if (input->is_binary()) { | 38 if (input->is_binary()) { |
30 // binary data | 39 // binary data |
31 output->type = presentation::PresentationMessageType:: | 40 output->type = presentation::PresentationMessageType:: |
32 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | 41 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 output = content::PresentationSessionMessage::CreateBinaryMessage( | 78 output = content::PresentationSessionMessage::CreateBinaryMessage( |
70 input->presentation_url, | 79 input->presentation_url, |
71 input->presentation_id, | 80 input->presentation_id, |
72 make_scoped_ptr(new std::vector<uint8_t>)); | 81 make_scoped_ptr(new std::vector<uint8_t>)); |
73 input->data.Swap(output->data.get()); | 82 input->data.Swap(output->data.get()); |
74 } | 83 } |
75 | 84 |
76 return output.Pass(); | 85 return output.Pass(); |
77 } | 86 } |
78 | 87 |
| 88 void InvokeNewSessionMojoCallbackWithError( |
| 89 const NewSessionMojoCallback& callback) { |
| 90 callback.Run( |
| 91 presentation::PresentationSessionInfoPtr(), |
| 92 presentation::PresentationError::From( |
| 93 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
| 94 } |
| 95 |
79 } // namespace | 96 } // namespace |
80 | 97 |
81 namespace content { | |
82 | |
83 PresentationServiceImpl::PresentationServiceImpl( | 98 PresentationServiceImpl::PresentationServiceImpl( |
84 RenderFrameHost* render_frame_host, | 99 RenderFrameHost* render_frame_host, |
85 WebContents* web_contents, | 100 WebContents* web_contents, |
86 PresentationServiceDelegate* delegate) | 101 PresentationServiceDelegate* delegate) |
87 : WebContentsObserver(web_contents), | 102 : WebContentsObserver(web_contents), |
88 delegate_(delegate), | 103 delegate_(delegate), |
89 is_start_session_pending_(false), | 104 start_session_request_id_(kInvalidRequestSessionId), |
90 next_request_session_id_(0), | |
91 weak_factory_(this) { | 105 weak_factory_(this) { |
92 DCHECK(render_frame_host); | 106 DCHECK(render_frame_host); |
93 DCHECK(web_contents); | 107 DCHECK(web_contents); |
94 | 108 |
95 render_process_id_ = render_frame_host->GetProcess()->GetID(); | 109 render_process_id_ = render_frame_host->GetProcess()->GetID(); |
96 render_frame_id_ = render_frame_host->GetRoutingID(); | 110 render_frame_id_ = render_frame_host->GetRoutingID(); |
97 DVLOG(2) << "PresentationServiceImpl: " | 111 DVLOG(2) << "PresentationServiceImpl: " |
98 << render_process_id_ << ", " << render_frame_id_; | 112 << render_process_id_ << ", " << render_frame_id_; |
99 if (delegate_) | 113 if (delegate_) |
100 delegate_->AddObserver(render_process_id_, render_frame_id_, this); | 114 delegate_->AddObserver(render_process_id_, render_frame_id_, this); |
101 } | 115 } |
102 | 116 |
103 PresentationServiceImpl::~PresentationServiceImpl() { | 117 PresentationServiceImpl::~PresentationServiceImpl() { |
104 if (delegate_) | 118 if (delegate_) |
105 delegate_->RemoveObserver(render_process_id_, render_frame_id_); | 119 delegate_->RemoveObserver(render_process_id_, render_frame_id_); |
106 FlushNewSessionCallbacks(); | |
107 } | 120 } |
108 | 121 |
109 // static | 122 // static |
110 void PresentationServiceImpl::CreateMojoService( | 123 void PresentationServiceImpl::CreateMojoService( |
111 RenderFrameHost* render_frame_host, | 124 RenderFrameHost* render_frame_host, |
112 mojo::InterfaceRequest<presentation::PresentationService> request) { | 125 mojo::InterfaceRequest<presentation::PresentationService> request) { |
113 DVLOG(2) << "CreateMojoService"; | 126 DVLOG(2) << "CreateMojoService"; |
114 WebContents* web_contents = | 127 WebContents* web_contents = |
115 WebContents::FromRenderFrameHost(render_frame_host); | 128 WebContents::FromRenderFrameHost(render_frame_host); |
116 DCHECK(web_contents); | 129 DCHECK(web_contents); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void PresentationServiceImpl::StartSession( | 219 void PresentationServiceImpl::StartSession( |
207 const mojo::String& presentation_url, | 220 const mojo::String& presentation_url, |
208 const mojo::String& presentation_id, | 221 const mojo::String& presentation_id, |
209 const NewSessionMojoCallback& callback) { | 222 const NewSessionMojoCallback& callback) { |
210 DVLOG(2) << "StartSession"; | 223 DVLOG(2) << "StartSession"; |
211 if (!delegate_) { | 224 if (!delegate_) { |
212 InvokeNewSessionMojoCallbackWithError(callback); | 225 InvokeNewSessionMojoCallbackWithError(callback); |
213 return; | 226 return; |
214 } | 227 } |
215 | 228 |
216 if (is_start_session_pending_) { | 229 // Currently not processing a request, so no need for queueing. |
217 queued_start_session_requests_.push_back(make_linked_ptr( | 230 if (start_session_request_id_ == kInvalidRequestSessionId) { |
218 new StartSessionRequest(presentation_url, presentation_id, callback))); | 231 DoStartSession(make_scoped_ptr(new StartSessionRequest( |
| 232 presentation_url, presentation_id, callback))); |
219 return; | 233 return; |
220 } | 234 } |
221 | 235 |
222 DoStartSession(presentation_url, presentation_id, callback); | 236 if (queued_start_session_requests_.size() >= kMaxNumQueuedSessionRequests) { |
| 237 InvokeNewSessionMojoCallbackWithError(callback); |
| 238 return; |
| 239 } |
| 240 |
| 241 queued_start_session_requests_.push_back( |
| 242 make_linked_ptr(new StartSessionRequest( |
| 243 presentation_url, presentation_id, callback))); |
223 } | 244 } |
224 | 245 |
225 void PresentationServiceImpl::JoinSession( | 246 void PresentationServiceImpl::JoinSession( |
226 const mojo::String& presentation_url, | 247 const mojo::String& presentation_url, |
227 const mojo::String& presentation_id, | 248 const mojo::String& presentation_id, |
228 const NewSessionMojoCallback& callback) { | 249 const NewSessionMojoCallback& callback) { |
229 DVLOG(2) << "JoinSession"; | 250 DVLOG(2) << "JoinSession"; |
230 if (!delegate_) { | 251 if (!delegate_) { |
231 InvokeNewSessionMojoCallbackWithError(callback); | 252 InvokeNewSessionMojoCallbackWithError(callback); |
232 return; | 253 return; |
233 } | 254 } |
234 | 255 |
235 int request_session_id = RegisterNewSessionCallback(callback); | 256 int request_session_id = RegisterJoinSessionCallback(callback); |
| 257 if (request_session_id == kInvalidRequestSessionId) { |
| 258 InvokeNewSessionMojoCallbackWithError(callback); |
| 259 return; |
| 260 } |
236 delegate_->JoinSession( | 261 delegate_->JoinSession( |
237 render_process_id_, | 262 render_process_id_, |
238 render_frame_id_, | 263 render_frame_id_, |
239 presentation_url, | 264 presentation_url, |
240 presentation_id, | 265 presentation_id, |
241 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 266 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, |
242 weak_factory_.GetWeakPtr(), false, request_session_id), | 267 weak_factory_.GetWeakPtr(), request_session_id), |
243 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 268 base::Bind(&PresentationServiceImpl::OnJoinSessionError, |
244 weak_factory_.GetWeakPtr(), false, request_session_id)); | 269 weak_factory_.GetWeakPtr(), request_session_id)); |
245 } | 270 } |
246 | 271 |
247 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { | 272 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { |
248 if (queued_start_session_requests_.empty()) { | 273 if (queued_start_session_requests_.empty()) |
249 is_start_session_pending_ = false; | |
250 return; | 274 return; |
251 } | 275 |
252 linked_ptr<StartSessionRequest> request = | 276 linked_ptr<StartSessionRequest> request = |
253 queued_start_session_requests_.front(); | 277 queued_start_session_requests_.front(); |
254 queued_start_session_requests_.pop_front(); | 278 queued_start_session_requests_.pop_front(); |
255 DoStartSession(request->presentation_url(), | 279 DoStartSession(make_scoped_ptr(request.release())); |
256 request->presentation_id(), | |
257 request->PassCallback()); | |
258 } | 280 } |
259 | 281 |
260 int PresentationServiceImpl::RegisterNewSessionCallback( | 282 int PresentationServiceImpl::RegisterJoinSessionCallback( |
261 const NewSessionMojoCallback& callback) { | 283 const NewSessionMojoCallback& callback) { |
262 ++next_request_session_id_; | 284 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
263 pending_session_cbs_[next_request_session_id_].reset( | 285 return kInvalidRequestSessionId; |
264 new NewSessionMojoCallback(callback)); | |
265 return next_request_session_id_; | |
266 } | |
267 | 286 |
268 void PresentationServiceImpl::FlushNewSessionCallbacks() { | 287 int request_id = GetNextRequestSessionId(); |
269 for (auto& pending_entry : pending_session_cbs_) { | 288 pending_join_session_cbs_[request_id].reset( |
270 InvokeNewSessionMojoCallbackWithError(*pending_entry.second); | 289 new NewSessionMojoCallbackWrapper(callback)); |
271 } | 290 return request_id; |
272 pending_session_cbs_.clear(); | |
273 } | 291 } |
274 | 292 |
275 void PresentationServiceImpl::DoStartSession( | 293 void PresentationServiceImpl::DoStartSession( |
276 const std::string& presentation_url, | 294 scoped_ptr<StartSessionRequest> request) { |
277 const std::string& presentation_id, | 295 DCHECK_EQ(kInvalidRequestSessionId, start_session_request_id_); |
278 const NewSessionMojoCallback& callback) { | 296 DCHECK(!pending_start_session_cb_.get()); |
279 int request_session_id = RegisterNewSessionCallback(callback); | 297 |
280 is_start_session_pending_ = true; | 298 int request_session_id = GetNextRequestSessionId(); |
| 299 start_session_request_id_ = request_session_id; |
| 300 pending_start_session_cb_ = request->PassCallback(); |
| 301 |
281 delegate_->StartSession( | 302 delegate_->StartSession( |
282 render_process_id_, | 303 render_process_id_, |
283 render_frame_id_, | 304 render_frame_id_, |
284 presentation_url, | 305 request->presentation_url(), |
285 presentation_id, | 306 request->presentation_id(), |
286 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 307 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, |
287 weak_factory_.GetWeakPtr(), true, request_session_id), | 308 weak_factory_.GetWeakPtr(), request_session_id), |
288 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 309 base::Bind(&PresentationServiceImpl::OnStartSessionError, |
289 weak_factory_.GetWeakPtr(), true, request_session_id)); | 310 weak_factory_.GetWeakPtr(), request_session_id)); |
290 } | 311 } |
291 | 312 |
292 void PresentationServiceImpl::OnStartOrJoinSessionSucceeded( | 313 void PresentationServiceImpl::OnStartSessionSucceeded( |
293 bool is_start_session, | |
294 int request_session_id, | 314 int request_session_id, |
295 const PresentationSessionInfo& session_info) { | 315 const PresentationSessionInfo& session_info) { |
296 RunAndEraseNewSessionMojoCallback( | 316 if (request_session_id == start_session_request_id_) { |
| 317 CHECK(pending_start_session_cb_.get()); |
| 318 pending_start_session_cb_->Run( |
| 319 presentation::PresentationSessionInfo::From(session_info), |
| 320 presentation::PresentationErrorPtr()); |
| 321 pending_start_session_cb_.reset(); |
| 322 start_session_request_id_ = kInvalidRequestSessionId; |
| 323 HandleQueuedStartSessionRequests(); |
| 324 } |
| 325 } |
| 326 |
| 327 void PresentationServiceImpl::OnStartSessionError( |
| 328 int request_session_id, |
| 329 const PresentationError& error) { |
| 330 if (request_session_id == start_session_request_id_) { |
| 331 CHECK(pending_start_session_cb_.get()); |
| 332 pending_start_session_cb_->Run( |
| 333 presentation::PresentationSessionInfoPtr(), |
| 334 presentation::PresentationError::From(error)); |
| 335 pending_start_session_cb_.reset(); |
| 336 start_session_request_id_ = kInvalidRequestSessionId; |
| 337 HandleQueuedStartSessionRequests(); |
| 338 } |
| 339 } |
| 340 |
| 341 void PresentationServiceImpl::OnJoinSessionSucceeded( |
| 342 int request_session_id, |
| 343 const PresentationSessionInfo& session_info) { |
| 344 RunAndEraseJoinSessionMojoCallback( |
297 request_session_id, | 345 request_session_id, |
298 presentation::PresentationSessionInfo::From(session_info), | 346 presentation::PresentationSessionInfo::From(session_info), |
299 presentation::PresentationErrorPtr()); | 347 presentation::PresentationErrorPtr()); |
300 if (is_start_session) | |
301 HandleQueuedStartSessionRequests(); | |
302 } | 348 } |
303 | 349 |
304 void PresentationServiceImpl::OnStartOrJoinSessionError( | 350 void PresentationServiceImpl::OnJoinSessionError( |
305 bool is_start_session, | |
306 int request_session_id, | 351 int request_session_id, |
307 const PresentationError& error) { | 352 const PresentationError& error) { |
308 RunAndEraseNewSessionMojoCallback( | 353 RunAndEraseJoinSessionMojoCallback( |
309 request_session_id, | 354 request_session_id, |
310 presentation::PresentationSessionInfoPtr(), | 355 presentation::PresentationSessionInfoPtr(), |
311 presentation::PresentationError::From(error)); | 356 presentation::PresentationError::From(error)); |
312 if (is_start_session) | |
313 HandleQueuedStartSessionRequests(); | |
314 } | 357 } |
315 | 358 |
316 void PresentationServiceImpl::RunAndEraseNewSessionMojoCallback( | 359 void PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( |
317 int request_session_id, | 360 int request_session_id, |
318 presentation::PresentationSessionInfoPtr session, | 361 presentation::PresentationSessionInfoPtr session, |
319 presentation::PresentationErrorPtr error) { | 362 presentation::PresentationErrorPtr error) { |
320 auto it = pending_session_cbs_.find(request_session_id); | 363 auto it = pending_join_session_cbs_.find(request_session_id); |
321 if (it == pending_session_cbs_.end()) | 364 if (it == pending_join_session_cbs_.end()) |
322 return; | 365 return; |
323 | 366 |
324 DCHECK(it->second.get()); | 367 DCHECK(it->second.get()); |
325 it->second->Run(session.Pass(), error.Pass()); | 368 it->second->Run(session.Pass(), error.Pass()); |
326 pending_session_cbs_.erase(it); | 369 pending_join_session_cbs_.erase(it); |
327 } | 370 } |
328 | 371 |
329 void PresentationServiceImpl::SetDefaultPresentationURL( | 372 void PresentationServiceImpl::SetDefaultPresentationURL( |
330 const mojo::String& default_presentation_url, | 373 const mojo::String& default_presentation_url, |
331 const mojo::String& default_presentation_id) { | 374 const mojo::String& default_presentation_id) { |
332 DVLOG(2) << "SetDefaultPresentationURL"; | 375 DVLOG(2) << "SetDefaultPresentationURL"; |
333 if (!delegate_) | 376 if (!delegate_) |
334 return; | 377 return; |
335 | 378 |
336 const std::string& old_default_url = default_presentation_url_; | 379 const std::string& old_default_url = default_presentation_url_; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 delete this; | 525 delete this; |
483 } | 526 } |
484 | 527 |
485 void PresentationServiceImpl::Reset() { | 528 void PresentationServiceImpl::Reset() { |
486 DVLOG(2) << "PresentationServiceImpl::Reset"; | 529 DVLOG(2) << "PresentationServiceImpl::Reset"; |
487 if (delegate_) | 530 if (delegate_) |
488 delegate_->Reset(render_process_id_, render_frame_id_); | 531 delegate_->Reset(render_process_id_, render_frame_id_); |
489 | 532 |
490 default_presentation_url_.clear(); | 533 default_presentation_url_.clear(); |
491 default_presentation_id_.clear(); | 534 default_presentation_id_.clear(); |
| 535 |
492 screen_availability_listener_.reset(); | 536 screen_availability_listener_.reset(); |
| 537 |
493 queued_start_session_requests_.clear(); | 538 queued_start_session_requests_.clear(); |
494 FlushNewSessionCallbacks(); | 539 start_session_request_id_ = kInvalidRequestSessionId; |
| 540 pending_start_session_cb_.reset(); |
| 541 |
| 542 pending_join_session_cbs_.clear(); |
| 543 |
495 default_session_start_context_.reset(); | 544 default_session_start_context_.reset(); |
| 545 |
496 if (on_session_messages_callback_.get()) { | 546 if (on_session_messages_callback_.get()) { |
497 on_session_messages_callback_->Run( | 547 on_session_messages_callback_->Run( |
498 mojo::Array<presentation::SessionMessagePtr>()); | 548 mojo::Array<presentation::SessionMessagePtr>()); |
499 on_session_messages_callback_.reset(); | 549 on_session_messages_callback_.reset(); |
500 } | 550 } |
| 551 |
501 if (send_message_callback_) { | 552 if (send_message_callback_) { |
502 // Run the callback with false, indicating the renderer to stop sending | 553 // Run the callback with false, indicating the renderer to stop sending |
503 // the requests and invalidate all pending requests. | 554 // the requests and invalidate all pending requests. |
504 send_message_callback_->Run(false); | 555 send_message_callback_->Run(false); |
505 send_message_callback_.reset(); | 556 send_message_callback_.reset(); |
506 } | 557 } |
507 } | 558 } |
508 | 559 |
509 // static | |
510 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | |
511 const NewSessionMojoCallback& callback) { | |
512 callback.Run( | |
513 presentation::PresentationSessionInfoPtr(), | |
514 presentation::PresentationError::From( | |
515 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | |
516 } | |
517 | |
518 void PresentationServiceImpl::OnDelegateDestroyed() { | 560 void PresentationServiceImpl::OnDelegateDestroyed() { |
519 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 561 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
520 delegate_ = nullptr; | 562 delegate_ = nullptr; |
521 Reset(); | 563 Reset(); |
522 } | 564 } |
523 | 565 |
524 void PresentationServiceImpl::OnDefaultPresentationStarted( | 566 void PresentationServiceImpl::OnDefaultPresentationStarted( |
525 const PresentationSessionInfo& session) { | 567 const PresentationSessionInfo& session) { |
526 if (default_session_start_context_.get()) | 568 if (default_session_start_context_.get()) |
527 default_session_start_context_->set_session(session); | 569 default_session_start_context_->set_session(session); |
(...skipping 16 matching lines...) Expand all Loading... |
544 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl | 586 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl |
545 ::GetPresentationUrl() const { | 587 ::GetPresentationUrl() const { |
546 return presentation_url_; | 588 return presentation_url_; |
547 } | 589 } |
548 | 590 |
549 void PresentationServiceImpl::ScreenAvailabilityListenerImpl | 591 void PresentationServiceImpl::ScreenAvailabilityListenerImpl |
550 ::OnScreenAvailabilityChanged(bool available) { | 592 ::OnScreenAvailabilityChanged(bool available) { |
551 service_->client_->OnScreenAvailabilityUpdated(available); | 593 service_->client_->OnScreenAvailabilityUpdated(available); |
552 } | 594 } |
553 | 595 |
| 596 PresentationServiceImpl::NewSessionMojoCallbackWrapper |
| 597 ::NewSessionMojoCallbackWrapper(const NewSessionMojoCallback& callback) |
| 598 : callback_(callback) { |
| 599 } |
| 600 |
| 601 PresentationServiceImpl::NewSessionMojoCallbackWrapper |
| 602 ::~NewSessionMojoCallbackWrapper() { |
| 603 if (!callback_.is_null()) |
| 604 InvokeNewSessionMojoCallbackWithError(callback_); |
| 605 } |
| 606 |
| 607 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
| 608 presentation::PresentationSessionInfoPtr session, |
| 609 presentation::PresentationErrorPtr error) { |
| 610 DCHECK(!callback_.is_null()); |
| 611 callback_.Run(session.Pass(), error.Pass()); |
| 612 callback_.reset(); |
| 613 } |
| 614 |
554 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( | 615 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( |
555 const std::string& presentation_url, | 616 const std::string& presentation_url, |
556 const std::string& presentation_id, | 617 const std::string& presentation_id, |
557 const NewSessionMojoCallback& callback) | 618 const NewSessionMojoCallback& callback) |
558 : presentation_url_(presentation_url), | 619 : presentation_url_(presentation_url), |
559 presentation_id_(presentation_id), | 620 presentation_id_(presentation_id), |
560 callback_(callback) { | 621 callback_wrapper_(new NewSessionMojoCallbackWrapper(callback)) { |
561 } | 622 } |
562 | 623 |
563 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { | 624 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { |
564 // Ensure that a pending callback is not dropped. | |
565 if (!callback_.is_null()) | |
566 InvokeNewSessionMojoCallbackWithError(callback_); | |
567 } | 625 } |
568 | 626 |
569 PresentationServiceImpl::NewSessionMojoCallback | 627 scoped_ptr<PresentationServiceImpl::NewSessionMojoCallbackWrapper> |
570 PresentationServiceImpl::StartSessionRequest::PassCallback() { | 628 PresentationServiceImpl::StartSessionRequest::PassCallback() { |
571 NewSessionMojoCallback callback = callback_; | 629 return callback_wrapper_.Pass(); |
572 callback_.reset(); | |
573 return callback; | |
574 } | 630 } |
575 | 631 |
576 PresentationServiceImpl::DefaultSessionStartContext | 632 PresentationServiceImpl::DefaultSessionStartContext |
577 ::DefaultSessionStartContext() { | 633 ::DefaultSessionStartContext() { |
578 } | 634 } |
579 | 635 |
580 PresentationServiceImpl::DefaultSessionStartContext | 636 PresentationServiceImpl::DefaultSessionStartContext |
581 ::~DefaultSessionStartContext() { | 637 ::~DefaultSessionStartContext() { |
582 Reset(); | 638 Reset(); |
583 } | 639 } |
(...skipping 25 matching lines...) Expand all Loading... |
609 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 665 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
610 ScopedVector<DefaultSessionMojoCallback> callbacks; | 666 ScopedVector<DefaultSessionMojoCallback> callbacks; |
611 callbacks.swap(callbacks_); | 667 callbacks.swap(callbacks_); |
612 for (const auto& callback : callbacks) | 668 for (const auto& callback : callbacks) |
613 callback->Run(presentation::PresentationSessionInfoPtr()); | 669 callback->Run(presentation::PresentationSessionInfoPtr()); |
614 session_.reset(); | 670 session_.reset(); |
615 } | 671 } |
616 | 672 |
617 } // namespace content | 673 } // namespace content |
618 | 674 |
OLD | NEW |