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

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: Addresses Anton's comments. 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..2293634e588c076869f6d80b898ac1d5732cd110 100644
--- a/content/browser/presentation/presentation_service_impl.cc
+++ b/content/browser/presentation/presentation_service_impl.cc
@@ -10,12 +10,36 @@
#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"
#include "content/public/common/content_client.h"
#include "content/public/common/frame_navigate_params.h"
+namespace {
+
+presentation::SessionMessagePtr ToMojoSessionMessage(
mark a. foltz 2015/05/01 19:42:07 Add // documentation for this function. Note that
haibinlu 2015/05/02 00:32:55 Done.
+ content::PresentationSessionMessage* input) {
mark a. foltz 2015/05/01 19:42:07 const content::PresentationSessionMessage& for |in
haibinlu 2015/05/02 00:32:55 cosnt does not work with Swap
+ presentation::SessionMessagePtr output(presentation::SessionMessage::New());
+ output->presentation_url = input->presentation_url;
+ output->presentation_id = input->presentation_id;
+ if (input->is_binary()) {
+ // 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();
+}
+
+} // namespace
+
namespace content {
PresentationServiceImpl::PresentationServiceImpl(
@@ -335,7 +359,38 @@ 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_callback_.get()) {
mark a. foltz 2015/05/01 19:42:07 When could this happen? Does this mean that the c
haibinlu 2015/05/02 00:32:55 Done.
+ callback.Run(mojo::Array<presentation::SessionMessagePtr>());
+ return;
+ }
+
+ on_session_messages_callback_.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) {
mark a. foltz 2015/05/01 19:42:07 I've usually seen std::vector<linked_ptr<Foo>> use
haibinlu 2015/05/02 00:32:55 Acknowledged.
+ DCHECK(messages.get());
mark a. foltz 2015/05/01 19:42:07 What if messages->size() == 0?
haibinlu 2015/05/02 00:32:55 Done.
+ if (!on_session_messages_callback_.get()) {
+ // Reseted
mark a. foltz 2015/05/01 19:42:07 What was reset? The callback?
haibinlu 2015/05/02 00:32:55 Clarified the comments.
+ return;
+ }
+
+ 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());
}
void PresentationServiceImpl::DidNavigateAnyFrame(
@@ -388,6 +443,11 @@ void PresentationServiceImpl::Reset() {
queued_start_session_requests_.clear();
FlushNewSessionCallbacks();
default_session_start_context_.reset();
+ if (on_session_messages_callback_.get()) {
+ on_session_messages_callback_->Run(
+ mojo::Array<presentation::SessionMessagePtr>());
+ on_session_messages_callback_.reset();
+ }
}
// static

Powered by Google App Engine
This is Rietveld 408576698