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 a73cdc0a7b3ad3c5b745b746197db877e1796a76..dfba7ee532a5ec30d2ea10846acfdeaac8f274ea 100644 |
| --- a/content/browser/presentation/presentation_service_impl.cc |
| +++ b/content/browser/presentation/presentation_service_impl.cc |
| @@ -29,68 +29,61 @@ int GetNextRequestSessionId() { |
| return ++next_request_session_id; |
| } |
| -// The return value takes ownership of the contents of |input|. |
| presentation::SessionMessagePtr ToMojoSessionMessage( |
| - content::PresentationSessionMessage* input) { |
| + const content::PresentationSessionMessage& input) { |
| presentation::SessionMessagePtr output(presentation::SessionMessage::New()); |
| - output->presentation_url.Swap(&input->presentation_url); |
| - output->presentation_id.Swap(&input->presentation_id); |
| - if (input->is_binary()) { |
| + if (input.is_binary()) { |
| // binary data |
| output->type = presentation::PresentationMessageType:: |
| PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
|
haibinlu
2015/08/05 17:19:51
The majority of cases are one-to-one, not one-to-m
imcheng
2015/08/05 21:38:35
We could do that but then we will need to have 2 v
|
| - output->data.Swap(input->data.get()); |
| + output->data = mojo::Array<uint8_t>::From(*input.data); |
|
mark a. foltz
2015/08/04 23:47:02
Why this change? It is more efficient to swap poi
imcheng
2015/08/05 21:38:35
|input| is sent to potentially multiple observers
|
| } else { |
| // string message |
| output->type = |
| presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; |
| - output->message.Swap(input->message.get()); |
| + output->message = input.message; |
| } |
| return output.Pass(); |
| } |
| -scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage( |
| +scoped_ptr<PresentationSessionMessage> GetPresentationSessionMessage( |
| presentation::SessionMessagePtr input) { |
| DCHECK(!input.is_null()); |
| scoped_ptr<content::PresentationSessionMessage> output; |
| switch (input->type) { |
| - case presentation::PresentationMessageType:: |
| - PRESENTATION_MESSAGE_TYPE_TEXT: { |
| + case presentation::PRESENTATION_MESSAGE_TYPE_TEXT: { |
| DCHECK(!input->message.is_null()); |
| DCHECK(input->data.is_null()); |
| // Return null PresentationSessionMessage if size exceeds. |
| if (input->message.size() > content::kMaxPresentationSessionMessageSize) |
| return output.Pass(); |
| - output = content::PresentationSessionMessage::CreateStringMessage( |
| - input->presentation_url, input->presentation_id, |
| - make_scoped_ptr(new std::string)); |
| - input->message.Swap(output->message.get()); |
| + output.reset( |
| + new PresentationSessionMessage(PresentationMessageType::TEXT)); |
| + input->message.Swap(&output->message); |
| return output.Pass(); |
| } |
| - case presentation::PresentationMessageType:: |
| - PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: { |
| + case presentation::PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: { |
| DCHECK(!input->data.is_null()); |
| DCHECK(input->message.is_null()); |
| if (input->data.size() > content::kMaxPresentationSessionMessageSize) |
| return output.Pass(); |
| - output = content::PresentationSessionMessage::CreateArrayBufferMessage( |
| - input->presentation_url, input->presentation_id, |
| - make_scoped_ptr(new std::vector<uint8_t>)); |
| + output.reset(new PresentationSessionMessage( |
| + PresentationMessageType::ARRAY_BUFFER)); |
| + output->data.reset(new std::vector<uint8_t>); |
| input->data.Swap(output->data.get()); |
| return output.Pass(); |
| } |
| - case presentation::PresentationMessageType:: |
| - PRESENTATION_MESSAGE_TYPE_BLOB: { |
| + case presentation::PRESENTATION_MESSAGE_TYPE_BLOB: { |
| DCHECK(!input->data.is_null()); |
| DCHECK(input->message.is_null()); |
| if (input->data.size() > content::kMaxPresentationSessionMessageSize) |
| return output.Pass(); |
| - output = content::PresentationSessionMessage::CreateBlobMessage( |
| - input->presentation_url, input->presentation_id, |
| - make_scoped_ptr(new std::vector<uint8_t>)); |
| + output.reset( |
| + new PresentationSessionMessage(PresentationMessageType::BLOB)); |
| + output->data.reset(new std::vector<uint8_t>); |
| input->data.Swap(output->data.get()); |
| return output.Pass(); |
| } |
| @@ -374,8 +367,8 @@ void PresentationServiceImpl::SetDefaultPresentationURL( |
| default_presentation_url_ = default_presentation_url; |
| } |
| - |
| void PresentationServiceImpl::SendSessionMessage( |
| + presentation::PresentationSessionInfoPtr session, |
| presentation::SessionMessagePtr session_message, |
| const SendMessageMojoCallback& callback) { |
| DVLOG(2) << "SendSessionMessage"; |
| @@ -389,8 +382,8 @@ void PresentationServiceImpl::SendSessionMessage( |
| send_message_callback_.reset(new SendMessageMojoCallback(callback)); |
| delegate_->SendMessage( |
| - render_process_id_, |
| - render_frame_id_, |
| + render_process_id_, render_frame_id_, |
| + session.To<PresentationSessionInfo>(), |
| GetPresentationSessionMessage(session_message.Pass()), |
| base::Bind(&PresentationServiceImpl::OnSendMessageCallback, |
| weak_factory_.GetWeakPtr())); |
| @@ -443,43 +436,31 @@ bool PresentationServiceImpl::FrameMatches( |
| } |
| void PresentationServiceImpl::ListenForSessionMessages( |
| - const SessionMessagesCallback& callback) { |
| + presentation::PresentationSessionInfoPtr session) { |
| DVLOG(2) << "ListenForSessionMessages"; |
| - if (!delegate_) { |
| - callback.Run(mojo::Array<presentation::SessionMessagePtr>()); |
| + if (!delegate_) |
| return; |
| - } |
| - // Crash early if renderer is misbehaving. |
| - CHECK(!on_session_messages_callback_.get()); |
| - |
| - on_session_messages_callback_.reset(new SessionMessagesCallback(callback)); |
| + PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); |
| delegate_->ListenForSessionMessages( |
| - render_process_id_, render_frame_id_, |
| + render_process_id_, render_frame_id_, session_info, |
| base::Bind(&PresentationServiceImpl::OnSessionMessages, |
| - weak_factory_.GetWeakPtr())); |
| + weak_factory_.GetWeakPtr(), session_info)); |
| } |
| void PresentationServiceImpl::OnSessionMessages( |
| - scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) { |
| - if (!on_session_messages_callback_.get()) { |
| - // The Reset method of this class was invoked. |
| - return; |
| - } |
| - |
| - if (!messages.get() || messages->empty()) { |
| - // Error handling. Session is either closed or in error state. |
| - on_session_messages_callback_->Run( |
| - mojo::Array<presentation::SessionMessagePtr>()); |
| - } else { |
| - mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size()); |
| - for (size_t i = 0; i < messages->size(); ++i) { |
| - mojoMessages[i] = ToMojoSessionMessage((*messages)[i]); |
| - } |
| - on_session_messages_callback_->Run(mojoMessages.Pass()); |
| - } |
| - |
| - on_session_messages_callback_.reset(); |
| + const PresentationSessionInfo& session, |
| + const ScopedVector<PresentationSessionMessage>& messages) { |
| + DCHECK(client_); |
| + |
| + DVLOG(2) << "OnSessionMessages"; |
| + mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); |
| + for (size_t i = 0; i < messages.size(); ++i) |
| + mojoMessages[i] = ToMojoSessionMessage(*messages[i]); |
| + |
| + client_->OnSessionMessagesReceived( |
| + presentation::PresentationSessionInfo::From(session), |
| + mojoMessages.Pass()); |
| } |
| void PresentationServiceImpl::DidNavigateAnyFrame( |