Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: content/browser/presentation/presentation_service_impl.cc

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: resolve code review comments from Derek Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 1a23a37ed6103e17bbd7ad61ee4eac6cc63b252c..3a99eb31dd03b46256c5adb3bacb0d462219fa06 100644
--- a/content/browser/presentation/presentation_service_impl.cc
+++ b/content/browser/presentation/presentation_service_impl.cc
@@ -126,9 +126,11 @@ void InvokeNewSessionCallbackWithError(
PresentationServiceImpl::PresentationServiceImpl(
RenderFrameHost* render_frame_host,
WebContents* web_contents,
- PresentationServiceDelegate* delegate)
+ ControllerPresentationServiceDelegate* controller_delegate,
+ ReceiverPresentationServiceDelegate* receiver_delegate)
: WebContentsObserver(web_contents),
- delegate_(delegate),
+ controller_delegate_(controller_delegate),
+ receiver_delegate_(receiver_delegate),
start_session_request_id_(kInvalidRequestSessionId),
weak_factory_(this) {
DCHECK(render_frame_host);
@@ -139,13 +141,17 @@ PresentationServiceImpl::PresentationServiceImpl(
render_frame_id_ = render_frame_host->GetRoutingID();
DVLOG(2) << "PresentationServiceImpl: "
<< render_process_id_ << ", " << render_frame_id_;
- if (delegate_)
- delegate_->AddObserver(render_process_id_, render_frame_id_, this);
+
+ if (auto* delegate = GetPresentationServiceDelegate())
+ delegate->AddObserver(render_process_id_, render_frame_id_, this);
}
PresentationServiceImpl::~PresentationServiceImpl() {
- if (delegate_)
- delegate_->RemoveObserver(render_process_id_, render_frame_id_);
+ DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", "
+ << render_frame_id_;
+
+ if (auto* delegate = GetPresentationServiceDelegate())
+ delegate->RemoveObserver(render_process_id_, render_frame_id_);
}
// static
@@ -157,13 +163,21 @@ void PresentationServiceImpl::CreateMojoService(
WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
+ auto* browser = GetContentClient()->browser();
+ auto* receiver_delegate =
+ browser->GetReceiverPresentationServiceDelegate(web_contents);
+
+ // In current implementation, web contents can be controller or receiver
mark a. foltz 2016/12/02 22:09:05 nit: web_contents
zhaobin 2016/12/03 00:34:26 Done.
+ // but not both.
+ auto* controller_delegate =
+ receiver_delegate
+ ? nullptr
+ : browser->GetControllerPresentationServiceDelegate(web_contents);
+
// This object will be deleted when the RenderFrameHost is about to be
// deleted (RenderFrameDeleted).
PresentationServiceImpl* impl = new PresentationServiceImpl(
- render_frame_host,
- web_contents,
- GetContentClient()->browser()->GetPresentationServiceDelegate(
- web_contents));
+ render_frame_host, web_contents, controller_delegate, receiver_delegate);
impl->Bind(std::move(request));
}
@@ -178,11 +192,17 @@ void PresentationServiceImpl::SetClient(
DCHECK(!client_.get());
// TODO(imcheng): Set ErrorHandler to listen for errors.
client_ = std::move(client);
+
+ if (receiver_delegate_) {
+ receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
+ base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
+ weak_factory_.GetWeakPtr()));
+ }
}
void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
DVLOG(2) << "ListenForScreenAvailability " << url.spec();
- if (!delegate_) {
+ if (!controller_delegate_) {
client_->OnScreenAvailabilityUpdated(url, false);
return;
}
@@ -192,10 +212,8 @@ void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
std::unique_ptr<ScreenAvailabilityListenerImpl> listener(
new ScreenAvailabilityListenerImpl(url, this));
- if (delegate_->AddScreenAvailabilityListener(
- render_process_id_,
- render_frame_id_,
- listener.get())) {
+ if (controller_delegate_->AddScreenAvailabilityListener(
+ render_process_id_, render_frame_id_, listener.get())) {
screen_availability_listeners_[url] = std::move(listener);
} else {
DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request.";
@@ -205,14 +223,14 @@ void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
void PresentationServiceImpl::StopListeningForScreenAvailability(
const GURL& url) {
DVLOG(2) << "StopListeningForScreenAvailability " << url.spec();
- if (!delegate_)
+ if (!controller_delegate_)
return;
auto listener_it = screen_availability_listeners_.find(url);
if (listener_it == screen_availability_listeners_.end())
return;
- delegate_->RemoveScreenAvailabilityListener(
+ controller_delegate_->RemoveScreenAvailabilityListener(
render_process_id_, render_frame_id_, listener_it->second.get());
screen_availability_listeners_.erase(listener_it);
}
@@ -221,7 +239,7 @@ void PresentationServiceImpl::StartSession(
const std::vector<GURL>& presentation_urls,
const NewSessionCallback& callback) {
DVLOG(2) << "StartSession";
- if (!delegate_) {
+ if (!controller_delegate_) {
callback.Run(
blink::mojom::PresentationSessionInfoPtr(),
blink::mojom::PresentationError::From(PresentationError(
@@ -238,7 +256,7 @@ void PresentationServiceImpl::StartSession(
start_session_request_id_ = GetNextRequestSessionId();
pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
- delegate_->StartSession(
+ controller_delegate_->StartSession(
render_process_id_, render_frame_id_, presentation_urls,
base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
weak_factory_.GetWeakPtr(), start_session_request_id_),
@@ -251,7 +269,7 @@ void PresentationServiceImpl::JoinSession(
const base::Optional<std::string>& presentation_id,
const NewSessionCallback& callback) {
DVLOG(2) << "JoinSession";
- if (!delegate_) {
+ if (!controller_delegate_) {
callback.Run(blink::mojom::PresentationSessionInfoPtr(),
blink::mojom::PresentationError::From(PresentationError(
PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
@@ -264,7 +282,7 @@ void PresentationServiceImpl::JoinSession(
InvokeNewSessionCallbackWithError(callback);
return;
}
- delegate_->JoinSession(
+ controller_delegate_->JoinSession(
render_process_id_, render_frame_id_, presentation_urls,
presentation_id.value_or(std::string()),
base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
@@ -286,8 +304,8 @@ int PresentationServiceImpl::RegisterJoinSessionCallback(
void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState(
const PresentationSessionInfo& connection) {
- if (delegate_) {
- delegate_->ListenForConnectionStateChange(
+ if (controller_delegate_) {
+ controller_delegate_->ListenForConnectionStateChange(
render_process_id_, render_frame_id_, connection,
base::Bind(&PresentationServiceImpl::OnConnectionStateChanged,
weak_factory_.GetWeakPtr(), connection));
@@ -361,14 +379,14 @@ bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback(
void PresentationServiceImpl::SetDefaultPresentationUrls(
const std::vector<GURL>& presentation_urls) {
DVLOG(2) << "SetDefaultPresentationUrls";
- if (!delegate_)
+ if (!controller_delegate_)
return;
if (default_presentation_urls_ == presentation_urls)
return;
default_presentation_urls_ = presentation_urls;
- delegate_->SetDefaultPresentationUrls(
+ controller_delegate_->SetDefaultPresentationUrls(
render_process_id_, render_frame_id_, presentation_urls,
base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
weak_factory_.GetWeakPtr()));
@@ -378,17 +396,18 @@ void PresentationServiceImpl::SendSessionMessage(
blink::mojom::PresentationSessionInfoPtr session,
blink::mojom::SessionMessagePtr session_message,
const SendSessionMessageCallback& callback) {
- DVLOG(2) << "SendSessionMessage";
+ DVLOG(2) << "SendSessionMessage"
+ << " [id]: " << session->id;
DCHECK(!session_message.is_null());
// send_message_callback_ should be null by now, otherwise resetting of
// send_message_callback_ with new callback will drop the old callback.
- if (!delegate_ || send_message_callback_) {
+ if (!controller_delegate_ || send_message_callback_) {
callback.Run(false);
return;
}
send_message_callback_.reset(new SendSessionMessageCallback(callback));
- delegate_->SendMessage(
+ controller_delegate_->SendMessage(
render_process_id_, render_frame_id_,
session.To<PresentationSessionInfo>(),
GetPresentationSessionMessage(std::move(session_message)),
@@ -409,16 +428,17 @@ void PresentationServiceImpl::CloseConnection(
const GURL& presentation_url,
const std::string& presentation_id) {
DVLOG(2) << "CloseConnection " << presentation_id;
- if (delegate_)
- delegate_->CloseConnection(render_process_id_, render_frame_id_,
- presentation_id);
+ if (controller_delegate_)
+ controller_delegate_->CloseConnection(render_process_id_, render_frame_id_,
+ presentation_id);
}
void PresentationServiceImpl::Terminate(const GURL& presentation_url,
const std::string& presentation_id) {
DVLOG(2) << "Terminate " << presentation_id;
- if (delegate_)
- delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id);
+ if (controller_delegate_)
+ controller_delegate_->Terminate(render_process_id_, render_frame_id_,
+ presentation_id);
}
void PresentationServiceImpl::OnConnectionStateChanged(
@@ -449,26 +469,47 @@ bool PresentationServiceImpl::FrameMatches(
render_frame_host->GetRoutingID() == render_frame_id_;
}
+PresentationServiceDelegate*
+PresentationServiceImpl::GetPresentationServiceDelegate() {
+ return receiver_delegate_
+ ? static_cast<PresentationServiceDelegate*>(receiver_delegate_)
mark a. foltz 2016/12/02 22:09:05 Can these casts be removed now since both receiver
+ : static_cast<PresentationServiceDelegate*>(controller_delegate_);
+}
+
void PresentationServiceImpl::ListenForSessionMessages(
blink::mojom::PresentationSessionInfoPtr session) {
DVLOG(2) << "ListenForSessionMessages";
- if (!delegate_)
+ if (!controller_delegate_)
return;
PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
- delegate_->ListenForSessionMessages(
+ controller_delegate_->ListenForSessionMessages(
render_process_id_, render_frame_id_, session_info,
base::Bind(&PresentationServiceImpl::OnSessionMessages,
weak_factory_.GetWeakPtr(), session_info));
}
+void PresentationServiceImpl::SetPresentationConnection(
+ blink::mojom::PresentationSessionInfoPtr session,
+ blink::mojom::PresentationConnectionPtr connection) {
+ DVLOG(2) << "SetPresentationConnection";
+
+ if (!controller_delegate_)
+ return;
+
+ PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
+ controller_delegate_->ConnectToOffscreenPresentation(
+ render_process_id_, render_frame_id_, session_info,
+ std::move(connection));
+}
+
void PresentationServiceImpl::OnSessionMessages(
const PresentationSessionInfo& session,
const ScopedVector<PresentationSessionMessage>& messages,
bool pass_ownership) {
DCHECK(client_);
-
- DVLOG(2) << "OnSessionMessages";
+ DVLOG(2) << "OnSessionMessages"
+ << " [id]: " << session.presentation_id;
std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size());
std::transform(messages.begin(), messages.end(), mojo_messages.begin(),
[pass_ownership](PresentationSessionMessage* message) {
@@ -480,6 +521,12 @@ void PresentationServiceImpl::OnSessionMessages(
std::move(mojo_messages));
}
+void PresentationServiceImpl::OnReceiverConnectionAvailable(
+ const content::PresentationSessionInfo& session_info,
+ PresentationConnectionPtr controller) {
+ DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
+}
+
void PresentationServiceImpl::DidNavigateAnyFrame(
content::RenderFrameHost* render_frame_host,
const content::LoadCommittedDetails& details,
@@ -525,8 +572,9 @@ void PresentationServiceImpl::WebContentsDestroyed() {
void PresentationServiceImpl::Reset() {
DVLOG(2) << "PresentationServiceImpl::Reset";
- if (delegate_)
- delegate_->Reset(render_process_id_, render_frame_id_);
+
+ if (auto* delegate = GetPresentationServiceDelegate())
+ delegate->Reset(render_process_id_, render_frame_id_);
default_presentation_urls_.clear();
@@ -553,7 +601,8 @@ void PresentationServiceImpl::Reset() {
void PresentationServiceImpl::OnDelegateDestroyed() {
DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
- delegate_ = nullptr;
+ controller_delegate_ = nullptr;
+ receiver_delegate_ = nullptr;
Reset();
}

Powered by Google App Engine
This is Rietveld 408576698