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

Side by Side 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: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/presentation/presentation_type_converters.h" 10 #include "content/browser/presentation/presentation_type_converters.h"
11 #include "content/public/browser/content_browser_client.h" 11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/presentation_session_message.h"
13 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
17 #include "content/public/common/frame_navigate_params.h" 18 #include "content/public/common/frame_navigate_params.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 PresentationServiceImpl::PresentationServiceImpl( 22 PresentationServiceImpl::PresentationServiceImpl(
22 RenderFrameHost* render_frame_host, 23 RenderFrameHost* render_frame_host,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 content::RenderFrameHost* render_frame_host) const { 329 content::RenderFrameHost* render_frame_host) const {
329 if (!render_frame_host) 330 if (!render_frame_host)
330 return false; 331 return false;
331 332
332 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 333 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
333 render_frame_host->GetRoutingID() == render_frame_id_; 334 render_frame_host->GetRoutingID() == render_frame_id_;
334 } 335 }
335 336
336 void PresentationServiceImpl::ListenForSessionMessages( 337 void PresentationServiceImpl::ListenForSessionMessages(
337 const SessionMessagesCallback& callback) { 338 const SessionMessagesCallback& callback) {
338 NOTIMPLEMENTED(); 339 DVLOG(2) << "ListenForSessionMessages";
340 if (!delegate_) {
341 callback.Run(mojo::Array<presentation::SessionMessagePtr>());
342 return;
343 }
344
345 delegate_->ListenForSessionMessages(
346 render_process_id_, render_frame_id_,
347 base::Bind(&PresentationServiceImpl::OnSessionMessages,
348 weak_factory_.GetWeakPtr(), callback));
imcheng (use chromium acct) 2015/04/30 21:52:01 I am not sure about binding the mojo callback to O
haibinlu 2015/05/01 01:37:11 Done.
349 }
350
351 void PresentationServiceImpl::OnSessionMessages(
352 const SessionMessagesCallback& callback,
353 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) {
imcheng (use chromium acct) 2015/04/30 21:52:01 should probably add a DCHECK on messages
haibinlu 2015/05/01 19:03:19 Done.
354 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size());
355 for (size_t i = 0; i < messages->size(); ++i)
356 mojoMessages[i] = PresentationServiceImpl::ToMojoSessionMessage(
357 messages.get()->get().at(i));
358
359 callback.Run(mojoMessages.Pass());
360 }
361
362 // static
363 presentation::SessionMessagePtr PresentationServiceImpl::ToMojoSessionMessage(
364 PresentationSessionMessage* input) {
365 presentation::SessionMessagePtr output(presentation::SessionMessage::New());
366 output->presentation_url = input->presentation_url;
367 output->presentation_id = input->presentation_id;
368 if (input->message->size() == 0) {
369 // binary data
370 output->type = presentation::PresentationMessageType::
371 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
372 output->data.Swap(input->data.get());
373 } else {
374 // string message
375 output->type =
376 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
377 output->message.Swap(input->message.get());
378 }
379 return output.Pass();
339 } 380 }
340 381
341 void PresentationServiceImpl::DidNavigateAnyFrame( 382 void PresentationServiceImpl::DidNavigateAnyFrame(
342 content::RenderFrameHost* render_frame_host, 383 content::RenderFrameHost* render_frame_host,
343 const content::LoadCommittedDetails& details, 384 const content::LoadCommittedDetails& details,
344 const content::FrameNavigateParams& params) { 385 const content::FrameNavigateParams& params) {
345 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 386 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
346 if (!FrameMatches(render_frame_host)) 387 if (!FrameMatches(render_frame_host))
347 return; 388 return;
348 389
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { 571 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
531 ScopedVector<DefaultSessionMojoCallback> callbacks; 572 ScopedVector<DefaultSessionMojoCallback> callbacks;
532 callbacks.swap(callbacks_); 573 callbacks.swap(callbacks_);
533 for (const auto& callback : callbacks) 574 for (const auto& callback : callbacks)
534 callback->Run(presentation::PresentationSessionInfoPtr()); 575 callback->Run(presentation::PresentationSessionInfoPtr());
535 session_.reset(); 576 session_.reset();
536 } 577 }
537 578
538 } // namespace content 579 } // namespace content
539 580
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.h ('k') | content/browser/presentation/presentation_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698