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 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (listener_it == screen_availability_listeners_.end()) | 217 if (listener_it == screen_availability_listeners_.end()) |
218 return; | 218 return; |
219 | 219 |
220 delegate_->RemoveScreenAvailabilityListener( | 220 delegate_->RemoveScreenAvailabilityListener( |
221 render_process_id_, | 221 render_process_id_, |
222 render_frame_id_, | 222 render_frame_id_, |
223 listener_it->second); | 223 listener_it->second); |
224 screen_availability_listeners_.erase(listener_it); | 224 screen_availability_listeners_.erase(listener_it); |
225 } | 225 } |
226 | 226 |
| 227 void PresentationServiceImpl::ListenForDefaultSessionStart( |
| 228 const DefaultSessionMojoCallback& callback) { |
| 229 if (!default_session_start_context_.get()) |
| 230 default_session_start_context_.reset(new DefaultSessionStartContext); |
| 231 default_session_start_context_->AddCallback(callback); |
| 232 } |
| 233 |
227 void PresentationServiceImpl::StartSession( | 234 void PresentationServiceImpl::StartSession( |
228 const mojo::String& presentation_url, | 235 const mojo::String& presentation_url, |
229 const NewSessionMojoCallback& callback) { | 236 const NewSessionMojoCallback& callback) { |
230 DVLOG(2) << "StartSession"; | 237 DVLOG(2) << "StartSession"; |
231 if (!delegate_) { | 238 if (!delegate_) { |
232 callback.Run( | 239 callback.Run( |
233 presentation::PresentationSessionInfoPtr(), | 240 presentation::PresentationSessionInfoPtr(), |
234 presentation::PresentationError::From( | 241 presentation::PresentationError::From( |
235 PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 242 PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |
236 "No screens found."))); | 243 "No screens found."))); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 361 |
355 void PresentationServiceImpl::SetDefaultPresentationURL( | 362 void PresentationServiceImpl::SetDefaultPresentationURL( |
356 const mojo::String& url) { | 363 const mojo::String& url) { |
357 DVLOG(2) << "SetDefaultPresentationURL"; | 364 DVLOG(2) << "SetDefaultPresentationURL"; |
358 if (!delegate_) | 365 if (!delegate_) |
359 return; | 366 return; |
360 | 367 |
361 const std::string& new_default_url = url.get(); | 368 const std::string& new_default_url = url.get(); |
362 if (default_presentation_url_ == new_default_url) | 369 if (default_presentation_url_ == new_default_url) |
363 return; | 370 return; |
364 | 371 delegate_->SetDefaultPresentationUrl( |
| 372 render_process_id_, |
| 373 render_frame_id_, |
| 374 new_default_url); |
365 default_presentation_url_ = new_default_url; | 375 default_presentation_url_ = new_default_url; |
366 delegate_->SetDefaultPresentationUrl( | |
367 render_process_id_, render_frame_id_, new_default_url, | |
368 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, | |
369 weak_factory_.GetWeakPtr())); | |
370 } | 376 } |
371 | 377 |
372 void PresentationServiceImpl::SendSessionMessage( | 378 void PresentationServiceImpl::SendSessionMessage( |
373 presentation::PresentationSessionInfoPtr session, | 379 presentation::PresentationSessionInfoPtr session, |
374 presentation::SessionMessagePtr session_message, | 380 presentation::SessionMessagePtr session_message, |
375 const SendMessageMojoCallback& callback) { | 381 const SendMessageMojoCallback& callback) { |
376 DVLOG(2) << "SendSessionMessage"; | 382 DVLOG(2) << "SendSessionMessage"; |
377 DCHECK(!session_message.is_null()); | 383 DCHECK(!session_message.is_null()); |
378 // send_message_callback_ should be null by now, otherwise resetting of | 384 // send_message_callback_ should be null by now, otherwise resetting of |
379 // send_message_callback_ with new callback will drop the old callback. | 385 // send_message_callback_ with new callback will drop the old callback. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 514 |
509 default_presentation_url_.clear(); | 515 default_presentation_url_.clear(); |
510 | 516 |
511 screen_availability_listeners_.clear(); | 517 screen_availability_listeners_.clear(); |
512 | 518 |
513 start_session_request_id_ = kInvalidRequestSessionId; | 519 start_session_request_id_ = kInvalidRequestSessionId; |
514 pending_start_session_cb_.reset(); | 520 pending_start_session_cb_.reset(); |
515 | 521 |
516 pending_join_session_cbs_.clear(); | 522 pending_join_session_cbs_.clear(); |
517 | 523 |
| 524 default_session_start_context_.reset(); |
| 525 |
518 if (on_session_messages_callback_.get()) { | 526 if (on_session_messages_callback_.get()) { |
519 on_session_messages_callback_->Run( | 527 on_session_messages_callback_->Run( |
520 mojo::Array<presentation::SessionMessagePtr>()); | 528 mojo::Array<presentation::SessionMessagePtr>()); |
521 on_session_messages_callback_.reset(); | 529 on_session_messages_callback_.reset(); |
522 } | 530 } |
523 | 531 |
524 if (send_message_callback_) { | 532 if (send_message_callback_) { |
525 // Run the callback with false, indicating the renderer to stop sending | 533 // Run the callback with false, indicating the renderer to stop sending |
526 // the requests and invalidate all pending requests. | 534 // the requests and invalidate all pending requests. |
527 send_message_callback_->Run(false); | 535 send_message_callback_->Run(false); |
528 send_message_callback_.reset(); | 536 send_message_callback_.reset(); |
529 } | 537 } |
530 } | 538 } |
531 | 539 |
532 void PresentationServiceImpl::OnDelegateDestroyed() { | 540 void PresentationServiceImpl::OnDelegateDestroyed() { |
533 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 541 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
534 delegate_ = nullptr; | 542 delegate_ = nullptr; |
535 Reset(); | 543 Reset(); |
536 } | 544 } |
537 | 545 |
538 void PresentationServiceImpl::OnDefaultPresentationStarted( | 546 void PresentationServiceImpl::OnDefaultPresentationStarted( |
539 const PresentationSessionInfo& session_info) { | 547 const PresentationSessionInfo& session) { |
540 DCHECK(client_.get()); | 548 if (default_session_start_context_.get()) |
541 client_->OnDefaultSessionStarted( | 549 default_session_start_context_->set_session(session); |
542 presentation::PresentationSessionInfo::From(session_info)); | |
543 } | 550 } |
544 | 551 |
545 PresentationServiceImpl::ScreenAvailabilityListenerImpl | 552 PresentationServiceImpl::ScreenAvailabilityListenerImpl |
546 ::ScreenAvailabilityListenerImpl( | 553 ::ScreenAvailabilityListenerImpl( |
547 const std::string& availability_url, | 554 const std::string& availability_url, |
548 PresentationServiceImpl* service) | 555 PresentationServiceImpl* service) |
549 : availability_url_(availability_url), | 556 : availability_url_(availability_url), |
550 service_(service) { | 557 service_(service) { |
551 DCHECK(service_); | 558 DCHECK(service_); |
552 DCHECK(service_->client_.get()); | 559 DCHECK(service_->client_.get()); |
(...skipping 30 matching lines...) Expand all Loading... |
583 } | 590 } |
584 | 591 |
585 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( | 592 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
586 presentation::PresentationSessionInfoPtr session, | 593 presentation::PresentationSessionInfoPtr session, |
587 presentation::PresentationErrorPtr error) { | 594 presentation::PresentationErrorPtr error) { |
588 DCHECK(!callback_.is_null()); | 595 DCHECK(!callback_.is_null()); |
589 callback_.Run(session.Pass(), error.Pass()); | 596 callback_.Run(session.Pass(), error.Pass()); |
590 callback_.reset(); | 597 callback_.reset(); |
591 } | 598 } |
592 | 599 |
| 600 PresentationServiceImpl::DefaultSessionStartContext |
| 601 ::DefaultSessionStartContext() { |
| 602 } |
| 603 |
| 604 PresentationServiceImpl::DefaultSessionStartContext |
| 605 ::~DefaultSessionStartContext() { |
| 606 Reset(); |
| 607 } |
| 608 |
| 609 void PresentationServiceImpl::DefaultSessionStartContext::AddCallback( |
| 610 const DefaultSessionMojoCallback& callback) { |
| 611 if (session_.get()) { |
| 612 DCHECK(callbacks_.empty()); |
| 613 callback.Run(presentation::PresentationSessionInfo::From(*session_)); |
| 614 session_.reset(); |
| 615 } else { |
| 616 callbacks_.push_back(new DefaultSessionMojoCallback(callback)); |
| 617 } |
| 618 } |
| 619 |
| 620 void PresentationServiceImpl::DefaultSessionStartContext::set_session( |
| 621 const PresentationSessionInfo& session) { |
| 622 if (callbacks_.empty()) { |
| 623 session_.reset(new PresentationSessionInfo(session)); |
| 624 } else { |
| 625 DCHECK(!session_.get()); |
| 626 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 627 callbacks.swap(callbacks_); |
| 628 for (const auto& callback : callbacks) |
| 629 callback->Run(presentation::PresentationSessionInfo::From(session)); |
| 630 } |
| 631 } |
| 632 |
| 633 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| 634 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 635 callbacks.swap(callbacks_); |
| 636 for (const auto& callback : callbacks) |
| 637 callback->Run(presentation::PresentationSessionInfoPtr()); |
| 638 session_.reset(); |
| 639 } |
| 640 |
593 } // namespace content | 641 } // namespace content |
OLD | NEW |