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

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

Issue 2613153003: [Presentation API] Replaces type converters with typemaps (Closed)
Patch Set: Add more OWNERS foo Created 3 years, 11 months 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 9d870e3adf4c717129a36ad5d51f12538394c494..7b676c5a6b7e766cf110ca71ff6d30360997ec9b 100644
--- a/content/browser/presentation/presentation_service_impl.cc
+++ b/content/browser/presentation/presentation_service_impl.cc
@@ -11,7 +11,6 @@
#include "base/logging.h"
#include "base/stl_util.h"
-#include "content/browser/presentation/presentation_type_converters.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_frame_host.h"
@@ -107,9 +106,8 @@ std::unique_ptr<PresentationConnectionMessage> GetPresentationConnectionMessage(
void InvokeNewSessionCallbackWithError(
const PresentationServiceImpl::NewSessionCallback& callback) {
- callback.Run(blink::mojom::PresentationSessionInfoPtr(),
- blink::mojom::PresentationError::From(PresentationError(
- PRESENTATION_ERROR_UNKNOWN, "Internal error")));
+ callback.Run(base::nullopt,
+ PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"));
}
} // namespace
@@ -231,10 +229,9 @@ void PresentationServiceImpl::StartSession(
const NewSessionCallback& callback) {
DVLOG(2) << "StartSession";
if (!controller_delegate_) {
- callback.Run(
- blink::mojom::PresentationSessionInfoPtr(),
- blink::mojom::PresentationError::From(PresentationError(
- PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
+ callback.Run(base::nullopt,
+ PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
+ "No screens found."));
return;
}
@@ -261,10 +258,9 @@ void PresentationServiceImpl::JoinSession(
const NewSessionCallback& callback) {
DVLOG(2) << "JoinSession";
if (!controller_delegate_) {
- callback.Run(blink::mojom::PresentationSessionInfoPtr(),
- blink::mojom::PresentationError::From(PresentationError(
- PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
- "Error joining route: No matching route")));
+ callback.Run(base::nullopt,
+ PresentationError(PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
+ "Error joining route: No matching route"));
return;
}
@@ -313,9 +309,7 @@ void PresentationServiceImpl::OnStartSessionSucceeded(
return;
CHECK(pending_start_session_cb_.get());
- pending_start_session_cb_->Run(
- blink::mojom::PresentationSessionInfo::From(session_info),
- blink::mojom::PresentationErrorPtr());
+ pending_start_session_cb_->Run(session_info, base::nullopt);
ListenForConnectionStateChangeAndChangeState(session_info);
pending_start_session_cb_.reset();
start_session_request_id_ = kInvalidRequestSessionId;
@@ -328,8 +322,7 @@ void PresentationServiceImpl::OnStartSessionError(
return;
CHECK(pending_start_session_cb_.get());
- pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(),
- blink::mojom::PresentationError::From(error));
+ pending_start_session_cb_->Run(base::nullopt, error);
pending_start_session_cb_.reset();
start_session_request_id_ = kInvalidRequestSessionId;
}
@@ -337,10 +330,8 @@ void PresentationServiceImpl::OnStartSessionError(
void PresentationServiceImpl::OnJoinSessionSucceeded(
int request_session_id,
const PresentationSessionInfo& session_info) {
- if (RunAndEraseJoinSessionMojoCallback(
- request_session_id,
- blink::mojom::PresentationSessionInfo::From(session_info),
- blink::mojom::PresentationErrorPtr())) {
+ if (RunAndEraseJoinSessionMojoCallback(request_session_id, session_info,
+ base::nullopt)) {
ListenForConnectionStateChangeAndChangeState(session_info);
}
}
@@ -348,21 +339,19 @@ void PresentationServiceImpl::OnJoinSessionSucceeded(
void PresentationServiceImpl::OnJoinSessionError(
int request_session_id,
const PresentationError& error) {
- RunAndEraseJoinSessionMojoCallback(
- request_session_id, blink::mojom::PresentationSessionInfoPtr(),
- blink::mojom::PresentationError::From(error));
+ RunAndEraseJoinSessionMojoCallback(request_session_id, base::nullopt, error);
}
bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback(
int request_session_id,
- blink::mojom::PresentationSessionInfoPtr session,
- blink::mojom::PresentationErrorPtr error) {
+ const base::Optional<PresentationSessionInfo>& session_info,
+ const base::Optional<PresentationError>& error) {
auto it = pending_join_session_cbs_.find(request_session_id);
if (it == pending_join_session_cbs_.end())
return false;
DCHECK(it->second.get());
- it->second->Run(std::move(session), std::move(error));
+ it->second->Run(session_info, error);
pending_join_session_cbs_.erase(it);
return true;
}
@@ -384,11 +373,10 @@ void PresentationServiceImpl::SetDefaultPresentationUrls(
}
void PresentationServiceImpl::SendConnectionMessage(
- blink::mojom::PresentationSessionInfoPtr session,
+ const PresentationSessionInfo& session_info,
blink::mojom::ConnectionMessagePtr connection_message,
const SendConnectionMessageCallback& callback) {
- DVLOG(2) << "SendConnectionMessage"
- << " [id]: " << session->id;
+ DVLOG(2) << "SendConnectionMessage [id]: " << session_info.presentation_id;
DCHECK(!connection_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.
@@ -399,8 +387,7 @@ void PresentationServiceImpl::SendConnectionMessage(
send_message_callback_.reset(new SendConnectionMessageCallback(callback));
controller_delegate_->SendMessage(
- render_process_id_, render_frame_id_,
- session.To<PresentationSessionInfo>(),
+ render_process_id_, render_frame_id_, session_info,
GetPresentationConnectionMessage(std::move(connection_message)),
base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
weak_factory_.GetWeakPtr()));
@@ -440,14 +427,9 @@ void PresentationServiceImpl::OnConnectionStateChanged(
<< " [state]: " << info.state;
DCHECK(client_.get());
if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
- client_->OnConnectionClosed(
- blink::mojom::PresentationSessionInfo::From(connection),
- content::PresentationConnectionCloseReasonToMojo(info.close_reason),
- info.message);
+ client_->OnConnectionClosed(connection, info.close_reason, info.message);
} else {
- client_->OnConnectionStateChanged(
- blink::mojom::PresentationSessionInfo::From(connection),
- PresentationConnectionStateToMojo(info.state));
+ client_->OnConnectionStateChanged(connection, info.state);
}
}
@@ -468,12 +450,11 @@ PresentationServiceImpl::GetPresentationServiceDelegate() {
}
void PresentationServiceImpl::ListenForConnectionMessages(
- blink::mojom::PresentationSessionInfoPtr session) {
+ const PresentationSessionInfo& session_info) {
DVLOG(2) << "ListenForConnectionMessages";
if (!controller_delegate_)
return;
- PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
controller_delegate_->ListenForConnectionMessages(
render_process_id_, render_frame_id_, session_info,
base::Bind(&PresentationServiceImpl::OnConnectionMessages,
@@ -481,7 +462,7 @@ void PresentationServiceImpl::ListenForConnectionMessages(
}
void PresentationServiceImpl::SetPresentationConnection(
- blink::mojom::PresentationSessionInfoPtr session,
+ const PresentationSessionInfo& session_info,
blink::mojom::PresentationConnectionPtr controller_connection_ptr,
blink::mojom::PresentationConnectionRequest receiver_connection_request) {
DVLOG(2) << "SetPresentationConnection";
@@ -489,7 +470,6 @@ void PresentationServiceImpl::SetPresentationConnection(
if (!controller_delegate_)
return;
- PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
controller_delegate_->ConnectToOffscreenPresentation(
render_process_id_, render_frame_id_, session_info,
std::move(controller_connection_ptr),
@@ -497,13 +477,12 @@ void PresentationServiceImpl::SetPresentationConnection(
}
void PresentationServiceImpl::OnConnectionMessages(
- const PresentationSessionInfo& session,
+ const PresentationSessionInfo& session_info,
const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages,
bool pass_ownership) {
DCHECK(client_);
- DVLOG(2) << "OnConnectionMessages"
- << " [id]: " << session.presentation_id;
+ DVLOG(2) << "OnConnectionMessages [id]: " << session_info.presentation_id;
std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages(
messages.size());
std::transform(
@@ -513,9 +492,7 @@ void PresentationServiceImpl::OnConnectionMessages(
return ToMojoConnectionMessage(message.get(), pass_ownership);
});
- client_->OnConnectionMessagesReceived(
- blink::mojom::PresentationSessionInfo::From(session),
- std::move(mojo_messages));
+ client_->OnConnectionMessagesReceived(session_info, std::move(mojo_messages));
}
void PresentationServiceImpl::OnReceiverConnectionAvailable(
@@ -525,8 +502,7 @@ void PresentationServiceImpl::OnReceiverConnectionAvailable(
DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
client_->OnReceiverConnectionAvailable(
- blink::mojom::PresentationSessionInfo::From(session_info),
- std::move(controller_connection_ptr),
+ session_info, std::move(controller_connection_ptr),
std::move(receiver_connection_request));
}
@@ -612,8 +588,7 @@ void PresentationServiceImpl::OnDelegateDestroyed() {
void PresentationServiceImpl::OnDefaultPresentationStarted(
const PresentationSessionInfo& connection) {
DCHECK(client_.get());
- client_->OnDefaultSessionStarted(
- blink::mojom::PresentationSessionInfo::From(connection));
+ client_->OnDefaultSessionStarted(connection);
ListenForConnectionStateChangeAndChangeState(connection);
}
@@ -656,10 +631,10 @@ PresentationServiceImpl::NewSessionCallbackWrapper
}
void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
- blink::mojom::PresentationSessionInfoPtr session,
- blink::mojom::PresentationErrorPtr error) {
+ const base::Optional<PresentationSessionInfo>& session_info,
+ const base::Optional<PresentationError>& error) {
DCHECK(!callback_.is_null());
- callback_.Run(std::move(session), std::move(error));
+ callback_.Run(session_info, error);
callback_.Reset();
}

Powered by Google App Engine
This is Rietveld 408576698