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

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

Issue 1118103002: Implements ListenForSessionMessages in PresentationServiceImpl; uses Swap to avoid copying large da… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit test Created 5 years, 8 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 19372a179473915a2e2c95a9b68e0f1dbe60b03e..1e0a64c46a3e536b0cac605f4a60d4829c241b80 100644
--- a/content/browser/presentation/presentation_service_impl.cc
+++ b/content/browser/presentation/presentation_service_impl.cc
@@ -10,6 +10,7 @@
#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/presentation_session_message.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
@@ -335,7 +336,57 @@ bool PresentationServiceImpl::FrameMatches(
void PresentationServiceImpl::ListenForSessionMessages(
const SessionMessagesCallback& callback) {
- NOTIMPLEMENTED();
+ DVLOG(2) << "ListenForSessionMessages";
+ if (!delegate_) {
+ callback.Run(mojo::Array<presentation::SessionMessagePtr>());
+ return;
+ }
+
+ if (on_session_messages_.get()) {
+ callback.Run(mojo::Array<presentation::SessionMessagePtr>());
+ return;
+ }
+
+ on_session_messages_.reset(new SessionMessagesCallback(callback));
+ delegate_->ListenForSessionMessages(
+ render_process_id_, render_frame_id_,
+ base::Bind(&PresentationServiceImpl::OnSessionMessages,
+ weak_factory_.GetWeakPtr()));
+}
+
+void PresentationServiceImpl::OnSessionMessages(
+ scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) {
+ if (!on_session_messages_.get()) {
+ // Reseted
+ return;
+ }
+
+ mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size());
+ for (size_t i = 0; i < messages->size(); ++i)
+ mojoMessages[i] =
whywhat 2015/05/01 15:26:12 nits: this needs to be in curly braces {}
haibinlu 2015/05/01 19:03:20 Done.
+ PresentationServiceImpl::ToMojoSessionMessage((*messages)[i]);
+
+ on_session_messages_->Run(mojoMessages.Pass());
+}
+
+// static
+presentation::SessionMessagePtr PresentationServiceImpl::ToMojoSessionMessage(
+ PresentationSessionMessage* input) {
+ presentation::SessionMessagePtr output(presentation::SessionMessage::New());
+ output->presentation_url = input->presentation_url;
+ output->presentation_id = input->presentation_id;
+ if (input->message->size() == 0) {
whywhat 2015/05/01 15:26:12 nit: could be if (input->message->empty()) {
haibinlu 2015/05/01 19:03:20 Done.
+ // binary data
+ output->type = presentation::PresentationMessageType::
+ PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
+ output->data.Swap(input->data.get());
+ } else {
+ // string message
+ output->type =
+ presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
+ output->message.Swap(input->message.get());
+ }
+ return output.Pass();
}
void PresentationServiceImpl::DidNavigateAnyFrame(
@@ -388,6 +439,10 @@ void PresentationServiceImpl::Reset() {
queued_start_session_requests_.clear();
FlushNewSessionCallbacks();
default_session_start_context_.reset();
+ if (on_session_messages_.get()) {
+ on_session_messages_->Run(mojo::Array<presentation::SessionMessagePtr>());
+ on_session_messages_.reset();
+ }
}
// static

Powered by Google App Engine
This is Rietveld 408576698