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..de7e75680955417334d8c8859f7faa9b6b820b70 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); |
| } |
| } |
| @@ -224,13 +225,6 @@ void PresentationServiceImpl::StopListeningForScreenAvailability( |
| screen_availability_listeners_.erase(listener_it); |
| } |
| -void PresentationServiceImpl::ListenForDefaultSessionStart( |
| - const DefaultSessionMojoCallback& callback) { |
| - if (!default_session_start_context_.get()) |
| - default_session_start_context_.reset(new DefaultSessionStartContext); |
| - default_session_start_context_->AddCallback(callback); |
| -} |
| - |
| void PresentationServiceImpl::StartSession( |
| const mojo::String& presentation_url, |
| const NewSessionMojoCallback& callback) { |
| @@ -368,11 +362,14 @@ void PresentationServiceImpl::SetDefaultPresentationURL( |
| const std::string& new_default_url = url.get(); |
| if (default_presentation_url_ == new_default_url) |
|
miu
2015/10/20 00:56:50
Why is this check here? It feels like a waste of
imcheng
2016/06/13 22:30:01
It looks like PSDImpl already does some form of de
|
| return; |
| + |
| + default_presentation_url_ = new_default_url; |
| delegate_->SetDefaultPresentationUrl( |
| render_process_id_, |
| render_frame_id_, |
| - new_default_url); |
| - default_presentation_url_ = new_default_url; |
| + default_presentation_url_, |
| + base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, |
| + weak_factory_.GetWeakPtr())); |
| } |
| void PresentationServiceImpl::SendSessionMessage( |
| @@ -457,6 +454,33 @@ void PresentationServiceImpl::ListenForSessionMessages( |
| weak_factory_.GetWeakPtr(), session_info)); |
| } |
| +void PresentationServiceImpl::GetPresentationReceiverSession( |
| + const PresentationSessionMojoCallback& callback) { |
| + DVLOG(2) << "GetPresentationReceiverSession"; |
| + DCHECK(receiver_session_callback_.is_null()); |
|
miu
2015/10/20 00:56:50
and DCHECK(!callback.is_null())
imcheng
2016/06/13 22:30:01
Done.
|
| + if (!delegate_) { |
| + callback.Run(presentation::PresentationSessionInfoPtr()); |
| + return; |
| + } |
| + |
| + receiver_session_callback_ = callback; |
| + delegate_->NotifyWhenReceiverSessionIsAvailable( |
| + 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()) { |
|
miu
2015/10/20 00:56:50
nit: Reduce indent on majority of the code by nega
imcheng
2016/06/13 22:30:01
Removed.
|
| + 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, |
| @@ -523,9 +547,7 @@ void PresentationServiceImpl::Reset() { |
| pending_join_session_cbs_.clear(); |
| - 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 +559,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() { |
| @@ -547,8 +574,8 @@ void PresentationServiceImpl::OnDelegateDestroyed() { |
| void PresentationServiceImpl::OnDefaultPresentationStarted( |
| const PresentationSessionInfo& session) { |
| - if (default_session_start_context_.get()) |
| - default_session_start_context_->set_session(session); |
| + client_->OnDefaultPresentationStarted( |
| + presentation::PresentationSessionInfo::From(session)); |
| } |
| PresentationServiceImpl::ScreenAvailabilityListenerImpl |
| @@ -622,45 +649,4 @@ void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
| callback_.reset(); |
| } |
| -PresentationServiceImpl::DefaultSessionStartContext |
| -::DefaultSessionStartContext() { |
| -} |
| - |
| -PresentationServiceImpl::DefaultSessionStartContext |
| -::~DefaultSessionStartContext() { |
| - Reset(); |
| -} |
| - |
| -void PresentationServiceImpl::DefaultSessionStartContext::AddCallback( |
| - const DefaultSessionMojoCallback& callback) { |
| - if (session_.get()) { |
| - DCHECK(callbacks_.empty()); |
| - callback.Run(presentation::PresentationSessionInfo::From(*session_)); |
| - session_.reset(); |
| - } else { |
| - callbacks_.push_back(new DefaultSessionMojoCallback(callback)); |
| - } |
| -} |
| - |
| -void PresentationServiceImpl::DefaultSessionStartContext::set_session( |
| - const PresentationSessionInfo& session) { |
| - if (callbacks_.empty()) { |
| - session_.reset(new PresentationSessionInfo(session)); |
| - } else { |
| - DCHECK(!session_.get()); |
| - ScopedVector<DefaultSessionMojoCallback> callbacks; |
| - callbacks.swap(callbacks_); |
| - for (const auto& callback : callbacks) |
| - callback->Run(presentation::PresentationSessionInfo::From(session)); |
| - } |
| -} |
| - |
| -void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| - ScopedVector<DefaultSessionMojoCallback> callbacks; |
| - callbacks.swap(callbacks_); |
| - for (const auto& callback : callbacks) |
| - callback->Run(presentation::PresentationSessionInfoPtr()); |
| - session_.reset(); |
| -} |
| - |
| } // namespace content |