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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 if (!delegate_) | 451 if (!delegate_) |
451 return; | 452 return; |
452 | 453 |
453 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); | 454 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); |
454 delegate_->ListenForSessionMessages( | 455 delegate_->ListenForSessionMessages( |
455 render_process_id_, render_frame_id_, session_info, | 456 render_process_id_, render_frame_id_, session_info, |
456 base::Bind(&PresentationServiceImpl::OnSessionMessages, | 457 base::Bind(&PresentationServiceImpl::OnSessionMessages, |
457 weak_factory_.GetWeakPtr(), session_info)); | 458 weak_factory_.GetWeakPtr(), session_info)); |
458 } | 459 } |
459 | 460 |
461 void PresentationServiceImpl::GetPresentationReceiverSession( | |
462 const GetPresentationReceiverSessionMojoCallback& callback) { | |
463 DVLOG(2) << "GetPresentationReceiverSession"; | |
464 if (!delegate_) { | |
465 callback.Run(presentation::PresentationSessionInfoPtr()); | |
466 return; | |
467 } | |
468 | |
469 receiver_session_callback_.reset( | |
470 new GetPresentationReceiverSessionMojoCallback(callback)); | |
mark a. foltz
2015/10/01 06:25:28
Do we need to wrap the passed-in callback in anoth
imcheng
2015/10/06 00:59:15
1) It used to be that we can't store mojo callback
| |
471 delegate_->GetPresentationReceiverSession( | |
472 render_process_id_, render_frame_id_, | |
473 base::Bind(&PresentationServiceImpl::OnGetPresentationReceiverSession, | |
474 weak_factory_.GetWeakPtr())); | |
475 } | |
476 | |
477 void PresentationServiceImpl::OnGetPresentationReceiverSession( | |
478 const content::PresentationSessionInfo* session_info) { | |
479 if (receiver_session_callback_) { | |
480 receiver_session_callback_->Run( | |
481 session_info | |
482 ? presentation::PresentationSessionInfo::From(*session_info) | |
483 : presentation::PresentationSessionInfoPtr()); | |
484 receiver_session_callback_.reset(); | |
485 } | |
486 } | |
487 | |
460 void PresentationServiceImpl::OnSessionMessages( | 488 void PresentationServiceImpl::OnSessionMessages( |
461 const PresentationSessionInfo& session, | 489 const PresentationSessionInfo& session, |
462 const ScopedVector<PresentationSessionMessage>& messages, | 490 const ScopedVector<PresentationSessionMessage>& messages, |
463 bool pass_ownership) { | 491 bool pass_ownership) { |
464 DCHECK(client_); | 492 DCHECK(client_); |
465 | 493 |
466 DVLOG(2) << "OnSessionMessages"; | 494 DVLOG(2) << "OnSessionMessages"; |
467 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); | 495 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); |
468 for (size_t i = 0; i < messages.size(); ++i) | 496 for (size_t i = 0; i < messages.size(); ++i) |
469 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); | 497 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 screen_availability_listeners_.clear(); | 546 screen_availability_listeners_.clear(); |
519 session_state_listeners_.clear(); | 547 session_state_listeners_.clear(); |
520 | 548 |
521 start_session_request_id_ = kInvalidRequestSessionId; | 549 start_session_request_id_ = kInvalidRequestSessionId; |
522 pending_start_session_cb_.reset(); | 550 pending_start_session_cb_.reset(); |
523 | 551 |
524 pending_join_session_cbs_.clear(); | 552 pending_join_session_cbs_.clear(); |
525 | 553 |
526 default_session_start_context_.reset(); | 554 default_session_start_context_.reset(); |
527 | 555 |
528 if (on_session_messages_callback_.get()) { | 556 if (on_session_messages_callback_) { |
529 on_session_messages_callback_->Run( | 557 on_session_messages_callback_->Run( |
530 mojo::Array<presentation::SessionMessagePtr>()); | 558 mojo::Array<presentation::SessionMessagePtr>()); |
531 on_session_messages_callback_.reset(); | 559 on_session_messages_callback_.reset(); |
532 } | 560 } |
533 | 561 |
534 if (send_message_callback_) { | 562 if (send_message_callback_) { |
535 // Run the callback with false, indicating the renderer to stop sending | 563 // Run the callback with false, indicating the renderer to stop sending |
536 // the requests and invalidate all pending requests. | 564 // the requests and invalidate all pending requests. |
537 send_message_callback_->Run(false); | 565 send_message_callback_->Run(false); |
538 send_message_callback_.reset(); | 566 send_message_callback_.reset(); |
539 } | 567 } |
568 | |
569 if (receiver_session_callback_) { | |
570 receiver_session_callback_->Run(presentation::PresentationSessionInfoPtr()); | |
571 receiver_session_callback_.reset(); | |
572 } | |
540 } | 573 } |
541 | 574 |
542 void PresentationServiceImpl::OnDelegateDestroyed() { | 575 void PresentationServiceImpl::OnDelegateDestroyed() { |
543 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 576 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
544 delegate_ = nullptr; | 577 delegate_ = nullptr; |
545 Reset(); | 578 Reset(); |
546 } | 579 } |
547 | 580 |
548 void PresentationServiceImpl::OnDefaultPresentationStarted( | 581 void PresentationServiceImpl::OnDefaultPresentationStarted( |
549 const PresentationSessionInfo& session) { | 582 const PresentationSessionInfo& session) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 685 |
653 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 686 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
654 ScopedVector<DefaultSessionMojoCallback> callbacks; | 687 ScopedVector<DefaultSessionMojoCallback> callbacks; |
655 callbacks.swap(callbacks_); | 688 callbacks.swap(callbacks_); |
656 for (const auto& callback : callbacks) | 689 for (const auto& callback : callbacks) |
657 callback->Run(presentation::PresentationSessionInfoPtr()); | 690 callback->Run(presentation::PresentationSessionInfoPtr()); |
658 session_.reset(); | 691 session_.reset(); |
659 } | 692 } |
660 | 693 |
661 } // namespace content | 694 } // namespace content |
OLD | NEW |