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

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: Addresses Mark's comments 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
20 namespace {
21
22 // The return value takes ownership of the actual message of |input|.
23 presentation::SessionMessagePtr ToMojoSessionMessage(
24 content::PresentationSessionMessage* input) {
25 presentation::SessionMessagePtr output(presentation::SessionMessage::New());
26 output->presentation_url = input->presentation_url;
27 output->presentation_id = input->presentation_id;
28 if (input->is_binary()) {
29 // binary data
30 output->type = presentation::PresentationMessageType::
31 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
32 output->data.Swap(input->data.get());
33 } else {
34 // string message
35 output->type =
36 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
37 output->message.Swap(input->message.get());
38 }
39 return output.Pass();
40 }
41
42 } // namespace
43
19 namespace content { 44 namespace content {
20 45
21 PresentationServiceImpl::PresentationServiceImpl( 46 PresentationServiceImpl::PresentationServiceImpl(
22 RenderFrameHost* render_frame_host, 47 RenderFrameHost* render_frame_host,
23 WebContents* web_contents, 48 WebContents* web_contents,
24 PresentationServiceDelegate* delegate) 49 PresentationServiceDelegate* delegate)
25 : WebContentsObserver(web_contents), 50 : WebContentsObserver(web_contents),
26 delegate_(delegate), 51 delegate_(delegate),
27 is_start_session_pending_(false), 52 is_start_session_pending_(false),
28 next_request_session_id_(0), 53 next_request_session_id_(0),
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 content::RenderFrameHost* render_frame_host) const { 353 content::RenderFrameHost* render_frame_host) const {
329 if (!render_frame_host) 354 if (!render_frame_host)
330 return false; 355 return false;
331 356
332 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 357 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
333 render_frame_host->GetRoutingID() == render_frame_id_; 358 render_frame_host->GetRoutingID() == render_frame_id_;
334 } 359 }
335 360
336 void PresentationServiceImpl::ListenForSessionMessages( 361 void PresentationServiceImpl::ListenForSessionMessages(
337 const SessionMessagesCallback& callback) { 362 const SessionMessagesCallback& callback) {
338 NOTIMPLEMENTED(); 363 DVLOG(2) << "ListenForSessionMessages";
364 if (!delegate_) {
365 callback.Run(mojo::Array<presentation::SessionMessagePtr>());
366 return;
367 }
368
369 DCHECK(!on_session_messages_callback_.get());
imcheng (use chromium acct) 2015/05/04 19:53:55 I think we should just CHECK here. If renderer is
haibinlu 2015/05/04 21:33:49 Acknowledged.
370
371 on_session_messages_callback_.reset(new SessionMessagesCallback(callback));
372 delegate_->ListenForSessionMessages(
373 render_process_id_, render_frame_id_,
374 base::Bind(&PresentationServiceImpl::OnSessionMessages,
375 weak_factory_.GetWeakPtr()));
376 }
377
378 void PresentationServiceImpl::OnSessionMessages(
379 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) {
380 DCHECK(messages.get() && messages->size() > 0);
imcheng (use chromium acct) 2015/05/04 19:53:55 nit: check !messages->empty() instead of size() >
haibinlu 2015/05/04 21:33:49 Done.
381 if (!on_session_messages_callback_.get()) {
382 // The Reset method of this class was invoked.
383 return;
384 }
385
386 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size());
387 for (size_t i = 0; i < messages->size(); ++i) {
388 mojoMessages[i] = ToMojoSessionMessage((*messages)[i]);
389 }
390
391 on_session_messages_callback_->Run(mojoMessages.Pass());
imcheng (use chromium acct) 2015/05/04 19:53:55 Reset on_session_messages_callback_ after Run().
haibinlu 2015/05/04 21:33:49 Done.
339 } 392 }
340 393
341 void PresentationServiceImpl::DidNavigateAnyFrame( 394 void PresentationServiceImpl::DidNavigateAnyFrame(
342 content::RenderFrameHost* render_frame_host, 395 content::RenderFrameHost* render_frame_host,
343 const content::LoadCommittedDetails& details, 396 const content::LoadCommittedDetails& details,
344 const content::FrameNavigateParams& params) { 397 const content::FrameNavigateParams& params) {
345 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 398 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
346 if (!FrameMatches(render_frame_host)) 399 if (!FrameMatches(render_frame_host))
347 return; 400 return;
348 401
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 DVLOG(2) << "PresentationServiceImpl::Reset"; 434 DVLOG(2) << "PresentationServiceImpl::Reset";
382 if (delegate_) 435 if (delegate_)
383 delegate_->Reset(render_process_id_, render_frame_id_); 436 delegate_->Reset(render_process_id_, render_frame_id_);
384 437
385 default_presentation_url_.clear(); 438 default_presentation_url_.clear();
386 default_presentation_id_.clear(); 439 default_presentation_id_.clear();
387 availability_contexts_.clear(); 440 availability_contexts_.clear();
388 queued_start_session_requests_.clear(); 441 queued_start_session_requests_.clear();
389 FlushNewSessionCallbacks(); 442 FlushNewSessionCallbacks();
390 default_session_start_context_.reset(); 443 default_session_start_context_.reset();
444 if (on_session_messages_callback_.get()) {
445 on_session_messages_callback_->Run(
446 mojo::Array<presentation::SessionMessagePtr>());
imcheng (use chromium acct) 2015/05/04 19:53:55 It looks like you would also need to change Presen
haibinlu 2015/05/04 21:33:50 Done.
447 on_session_messages_callback_.reset();
448 }
391 } 449 }
392 450
393 // static 451 // static
394 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( 452 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError(
395 const NewSessionMojoCallback& callback) { 453 const NewSessionMojoCallback& callback) {
396 callback.Run( 454 callback.Run(
397 presentation::PresentationSessionInfoPtr(), 455 presentation::PresentationSessionInfoPtr(),
398 presentation::PresentationError::From( 456 presentation::PresentationError::From(
399 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 457 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error")));
400 } 458 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { 588 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
531 ScopedVector<DefaultSessionMojoCallback> callbacks; 589 ScopedVector<DefaultSessionMojoCallback> callbacks;
532 callbacks.swap(callbacks_); 590 callbacks.swap(callbacks_);
533 for (const auto& callback : callbacks) 591 for (const auto& callback : callbacks)
534 callback->Run(presentation::PresentationSessionInfoPtr()); 592 callback->Run(presentation::PresentationSessionInfoPtr());
535 session_.reset(); 593 session_.reset();
536 } 594 }
537 595
538 } // namespace content 596 } // namespace content
539 597
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698