Chromium Code Reviews| Index: content/browser/presentation/presentation_service_impl.cc |
| diff --git a/content/browser/presentation/presentation_service_impl.cc b/content/browser/presentation/presentation_service_impl.cc |
| index 1703ab2253d91aafbd3919fe1e6a10461ae175e9..e5d01bef6d4013529d83efba3a737420b06e1d92 100644 |
| --- a/content/browser/presentation/presentation_service_impl.cc |
| +++ b/content/browser/presentation/presentation_service_impl.cc |
| @@ -202,7 +202,8 @@ void PresentationServiceImpl::ListenForScreenAvailability( |
| listener.get())) { |
| screen_availability_listeners_.set(availability_url, listener.Pass()); |
| } else { |
| - DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; |
| + DVLOG(1) << "AddScreenAvailabilityListener failed. Returning false."; |
| + client_->OnScreenAvailabilityUpdated(url, false); |
| } |
| } |
| @@ -225,7 +226,7 @@ void PresentationServiceImpl::StopListeningForScreenAvailability( |
| } |
| void PresentationServiceImpl::ListenForDefaultSessionStart( |
| - const DefaultSessionMojoCallback& callback) { |
| + const PresentationSessionMojoCallback& callback) { |
| if (!default_session_start_context_.get()) |
| default_session_start_context_.reset(new DefaultSessionStartContext); |
| default_session_start_context_->AddCallback(callback); |
| @@ -457,6 +458,33 @@ void PresentationServiceImpl::ListenForSessionMessages( |
| weak_factory_.GetWeakPtr(), session_info)); |
| } |
| +void PresentationServiceImpl::GetPresentationReceiverSession( |
| + const PresentationSessionMojoCallback& callback) { |
| + DVLOG(2) << "GetPresentationReceiverSession"; |
| + DCHECK(receiver_session_callback_.is_null()); |
| + if (!delegate_) { |
| + callback.Run(presentation::PresentationSessionInfoPtr()); |
| + return; |
| + } |
| + |
| + receiver_session_callback_ = callback; |
|
miu
2015/10/07 21:51:46
Can there only be one call to GetPresentationRecei
imcheng
2015/10/10 04:39:43
It does need to be run before it is destroyed (see
|
| + delegate_->GetPresentationReceiverSession( |
| + render_process_id_, render_frame_id_, |
| + base::Bind(&PresentationServiceImpl::OnGetPresentationReceiverSession, |
| + weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +void PresentationServiceImpl::OnGetPresentationReceiverSession( |
| + const content::PresentationSessionInfo* session_info) { |
| + if (!receiver_session_callback_.is_null()) { |
| + receiver_session_callback_.Run( |
| + session_info |
| + ? presentation::PresentationSessionInfo::From(*session_info) |
| + : presentation::PresentationSessionInfoPtr()); |
| + receiver_session_callback_.reset(); |
| + } |
| +} |
| + |
| void PresentationServiceImpl::OnSessionMessages( |
| const PresentationSessionInfo& session, |
| const ScopedVector<PresentationSessionMessage>& messages, |
| @@ -525,7 +553,7 @@ void PresentationServiceImpl::Reset() { |
| default_session_start_context_.reset(); |
| - if (on_session_messages_callback_.get()) { |
| + if (on_session_messages_callback_) { |
| on_session_messages_callback_->Run( |
| mojo::Array<presentation::SessionMessagePtr>()); |
| on_session_messages_callback_.reset(); |
| @@ -537,6 +565,11 @@ void PresentationServiceImpl::Reset() { |
| send_message_callback_->Run(false); |
| send_message_callback_.reset(); |
| } |
| + |
| + if (!receiver_session_callback_.is_null()) { |
| + receiver_session_callback_.Run(presentation::PresentationSessionInfoPtr()); |
| + receiver_session_callback_.reset(); |
| + } |
| } |
| void PresentationServiceImpl::OnDelegateDestroyed() { |
| @@ -632,13 +665,13 @@ PresentationServiceImpl::DefaultSessionStartContext |
| } |
| void PresentationServiceImpl::DefaultSessionStartContext::AddCallback( |
| - const DefaultSessionMojoCallback& callback) { |
| + const PresentationSessionMojoCallback& callback) { |
| if (session_.get()) { |
| DCHECK(callbacks_.empty()); |
| callback.Run(presentation::PresentationSessionInfo::From(*session_)); |
| session_.reset(); |
| } else { |
| - callbacks_.push_back(new DefaultSessionMojoCallback(callback)); |
| + callbacks_.push_back(new PresentationSessionMojoCallback(callback)); |
| } |
| } |
| @@ -648,7 +681,7 @@ void PresentationServiceImpl::DefaultSessionStartContext::set_session( |
| session_.reset(new PresentationSessionInfo(session)); |
| } else { |
| DCHECK(!session_.get()); |
| - ScopedVector<DefaultSessionMojoCallback> callbacks; |
| + ScopedVector<PresentationSessionMojoCallback> callbacks; |
| callbacks.swap(callbacks_); |
| for (const auto& callback : callbacks) |
| callback->Run(presentation::PresentationSessionInfo::From(session)); |
| @@ -656,7 +689,7 @@ void PresentationServiceImpl::DefaultSessionStartContext::set_session( |
| } |
| void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| - ScopedVector<DefaultSessionMojoCallback> callbacks; |
| + ScopedVector<PresentationSessionMojoCallback> callbacks; |
| callbacks.swap(callbacks_); |
| for (const auto& callback : callbacks) |
| callback->Run(presentation::PresentationSessionInfoPtr()); |