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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return; | 195 return; |
196 | 196 |
197 scoped_ptr<ScreenAvailabilityListenerImpl> listener( | 197 scoped_ptr<ScreenAvailabilityListenerImpl> listener( |
198 new ScreenAvailabilityListenerImpl(availability_url, this)); | 198 new ScreenAvailabilityListenerImpl(availability_url, this)); |
199 if (delegate_->AddScreenAvailabilityListener( | 199 if (delegate_->AddScreenAvailabilityListener( |
200 render_process_id_, | 200 render_process_id_, |
201 render_frame_id_, | 201 render_frame_id_, |
202 listener.get())) { | 202 listener.get())) { |
203 screen_availability_listeners_.set(availability_url, listener.Pass()); | 203 screen_availability_listeners_.set(availability_url, listener.Pass()); |
204 } else { | 204 } else { |
205 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; | 205 DVLOG(1) << "AddScreenAvailabilityListener failed. Returning false."; |
| 206 client_->OnScreenAvailabilityUpdated(url, false); |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void PresentationServiceImpl::StopListeningForScreenAvailability( | 210 void PresentationServiceImpl::StopListeningForScreenAvailability( |
210 const mojo::String& url) { | 211 const mojo::String& url) { |
211 DVLOG(2) << "StopListeningForScreenAvailability " << url; | 212 DVLOG(2) << "StopListeningForScreenAvailability " << url; |
212 if (!delegate_) | 213 if (!delegate_) |
213 return; | 214 return; |
214 | 215 |
215 const std::string& availability_url = url.get(); | 216 const std::string& availability_url = url.get(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 if (!delegate_) | 450 if (!delegate_) |
450 return; | 451 return; |
451 | 452 |
452 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); | 453 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); |
453 delegate_->ListenForSessionMessages( | 454 delegate_->ListenForSessionMessages( |
454 render_process_id_, render_frame_id_, session_info, | 455 render_process_id_, render_frame_id_, session_info, |
455 base::Bind(&PresentationServiceImpl::OnSessionMessages, | 456 base::Bind(&PresentationServiceImpl::OnSessionMessages, |
456 weak_factory_.GetWeakPtr(), session_info)); | 457 weak_factory_.GetWeakPtr(), session_info)); |
457 } | 458 } |
458 | 459 |
| 460 void PresentationServiceImpl::GetPresenterSession( |
| 461 const GetPresenterSessionMojoCallback& callback) { |
| 462 DVLOG(2) << "GetPresenterSession"; |
| 463 if (!delegate_) { |
| 464 callback.Run(presentation::PresentationSessionInfoPtr()); |
| 465 return; |
| 466 } |
| 467 |
| 468 presenter_session_callback_.reset( |
| 469 new GetPresenterSessionMojoCallback(callback)); |
| 470 delegate_->GetPresenterSession( |
| 471 render_process_id_, render_frame_id_, |
| 472 base::Bind(&PresentationServiceImpl::OnGetPresenterSessionSuccess, |
| 473 weak_factory_.GetWeakPtr()), |
| 474 base::Bind(&PresentationServiceImpl::OnGetPresenterSessionError, |
| 475 weak_factory_.GetWeakPtr())); |
| 476 } |
| 477 |
| 478 void PresentationServiceImpl::OnGetPresenterSessionSuccess( |
| 479 const content::PresentationSessionInfo& session_info) { |
| 480 DVLOG(2) << "OnGetPresenterSessionSuccess: " << session_info.presentation_id; |
| 481 if (presenter_session_callback_) { |
| 482 presenter_session_callback_->Run( |
| 483 presentation::PresentationSessionInfo::From(session_info)); |
| 484 presenter_session_callback_.reset(); |
| 485 } |
| 486 } |
| 487 |
| 488 void PresentationServiceImpl::OnGetPresenterSessionError( |
| 489 const std::string& error) { |
| 490 DVLOG(2) << __FUNCTION__ << ", error: " << error; |
| 491 if (presenter_session_callback_) { |
| 492 presenter_session_callback_->Run( |
| 493 presentation::PresentationSessionInfoPtr()); |
| 494 presenter_session_callback_.reset(); |
| 495 } |
| 496 } |
| 497 |
459 void PresentationServiceImpl::OnSessionMessages( | 498 void PresentationServiceImpl::OnSessionMessages( |
460 const PresentationSessionInfo& session, | 499 const PresentationSessionInfo& session, |
461 const ScopedVector<PresentationSessionMessage>& messages, | 500 const ScopedVector<PresentationSessionMessage>& messages, |
462 bool pass_ownership) { | 501 bool pass_ownership) { |
463 DCHECK(client_); | 502 DCHECK(client_); |
464 | 503 |
465 DVLOG(2) << "OnSessionMessages"; | 504 DVLOG(2) << "OnSessionMessages"; |
466 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); | 505 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); |
467 for (size_t i = 0; i < messages.size(); ++i) | 506 for (size_t i = 0; i < messages.size(); ++i) |
468 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); | 507 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 555 |
517 screen_availability_listeners_.clear(); | 556 screen_availability_listeners_.clear(); |
518 | 557 |
519 start_session_request_id_ = kInvalidRequestSessionId; | 558 start_session_request_id_ = kInvalidRequestSessionId; |
520 pending_start_session_cb_.reset(); | 559 pending_start_session_cb_.reset(); |
521 | 560 |
522 pending_join_session_cbs_.clear(); | 561 pending_join_session_cbs_.clear(); |
523 | 562 |
524 default_session_start_context_.reset(); | 563 default_session_start_context_.reset(); |
525 | 564 |
526 if (on_session_messages_callback_.get()) { | 565 if (on_session_messages_callback_) { |
527 on_session_messages_callback_->Run( | 566 on_session_messages_callback_->Run( |
528 mojo::Array<presentation::SessionMessagePtr>()); | 567 mojo::Array<presentation::SessionMessagePtr>()); |
529 on_session_messages_callback_.reset(); | 568 on_session_messages_callback_.reset(); |
530 } | 569 } |
531 | 570 |
532 if (send_message_callback_) { | 571 if (send_message_callback_) { |
533 // Run the callback with false, indicating the renderer to stop sending | 572 // Run the callback with false, indicating the renderer to stop sending |
534 // the requests and invalidate all pending requests. | 573 // the requests and invalidate all pending requests. |
535 send_message_callback_->Run(false); | 574 send_message_callback_->Run(false); |
536 send_message_callback_.reset(); | 575 send_message_callback_.reset(); |
537 } | 576 } |
| 577 |
| 578 presenter_session_callback_.reset(); |
538 } | 579 } |
539 | 580 |
540 void PresentationServiceImpl::OnDelegateDestroyed() { | 581 void PresentationServiceImpl::OnDelegateDestroyed() { |
541 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 582 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
542 delegate_ = nullptr; | 583 delegate_ = nullptr; |
543 Reset(); | 584 Reset(); |
544 } | 585 } |
545 | 586 |
546 void PresentationServiceImpl::OnDefaultPresentationStarted( | 587 void PresentationServiceImpl::OnDefaultPresentationStarted( |
547 const PresentationSessionInfo& session) { | 588 const PresentationSessionInfo& session) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 668 |
628 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 669 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
629 ScopedVector<DefaultSessionMojoCallback> callbacks; | 670 ScopedVector<DefaultSessionMojoCallback> callbacks; |
630 callbacks.swap(callbacks_); | 671 callbacks.swap(callbacks_); |
631 for (const auto& callback : callbacks) | 672 for (const auto& callback : callbacks) |
632 callback->Run(presentation::PresentationSessionInfoPtr()); | 673 callback->Run(presentation::PresentationSessionInfoPtr()); |
633 session_.reset(); | 674 session_.reset(); |
634 } | 675 } |
635 | 676 |
636 } // namespace content | 677 } // namespace content |
OLD | NEW |