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

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

Issue 1314413005: [Presentation API] 1-UA presentation support + presenter APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return; 195 return;
196 196
197 scoped_ptr<ScreenAvailabilityListenerImpl> listener( 197 scoped_ptr<ScreenAvailabilityListenerImpl> listener(
198 new ScreenAvailabilityListenerImpl(availability_url, this)); 198 new ScreenAvailabilityListenerImpl(availability_url, this));
199 if (delegate_->AddScreenAvailabilityListener( 199 if (delegate_->AddScreenAvailabilityListener(
200 render_process_id_, 200 render_process_id_,
201 render_frame_id_, 201 render_frame_id_,
202 listener.get())) { 202 listener.get())) {
203 screen_availability_listeners_.set(availability_url, listener.Pass()); 203 screen_availability_listeners_.set(availability_url, listener.Pass());
204 } else { 204 } else {
205 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; 205 DVLOG(1) << "AddScreenAvailabilityListener failed. Returning false.";
206 client_->OnScreenAvailabilityUpdated(url, false);
206 } 207 }
207 } 208 }
208 209
209 void PresentationServiceImpl::StopListeningForScreenAvailability( 210 void PresentationServiceImpl::StopListeningForScreenAvailability(
210 const mojo::String& url) { 211 const mojo::String& url) {
211 DVLOG(2) << "StopListeningForScreenAvailability " << url; 212 DVLOG(2) << "StopListeningForScreenAvailability " << url;
212 if (!delegate_) 213 if (!delegate_)
213 return; 214 return;
214 215
215 const std::string& availability_url = url.get(); 216 const std::string& availability_url = url.get();
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 if (!delegate_) 451 if (!delegate_)
451 return; 452 return;
452 453
453 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 454 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
454 delegate_->ListenForSessionMessages( 455 delegate_->ListenForSessionMessages(
455 render_process_id_, render_frame_id_, session_info, 456 render_process_id_, render_frame_id_, session_info,
456 base::Bind(&PresentationServiceImpl::OnSessionMessages, 457 base::Bind(&PresentationServiceImpl::OnSessionMessages,
457 weak_factory_.GetWeakPtr(), session_info)); 458 weak_factory_.GetWeakPtr(), session_info));
458 } 459 }
459 460
461 void PresentationServiceImpl::GetPresentationReceiverSession(
462 const GetPresentationReceiverSessionMojoCallback& callback) {
463 DVLOG(2) << "GetPresentationReceiverSession";
464 if (!delegate_) {
465 callback.Run(presentation::PresentationSessionInfoPtr());
466 return;
467 }
468
469 presenter_session_callback_.reset(
470 new GetPresentationReceiverSessionMojoCallback(callback));
471 delegate_->GetPresentationReceiverSession(
472 render_process_id_, render_frame_id_,
473 base::Bind(
474 &PresentationServiceImpl::OnGetPresentationReceiverSessionSuccess,
475 weak_factory_.GetWeakPtr()),
476 base::Bind(
477 &PresentationServiceImpl::OnGetPresentationReceiverSessionError,
478 weak_factory_.GetWeakPtr()));
479 }
480
481 void PresentationServiceImpl::OnGetPresentationReceiverSessionSuccess(
482 const content::PresentationSessionInfo& session_info) {
483 DVLOG(2) << "OnGetPresentationReceiverSessionSuccess: "
484 << session_info.presentation_id;
485 if (presenter_session_callback_) {
486 presenter_session_callback_->Run(
487 presentation::PresentationSessionInfo::From(session_info));
488 presenter_session_callback_.reset();
489 }
490 }
491
492 void PresentationServiceImpl::OnGetPresentationReceiverSessionError(
493 const std::string& error) {
494 DVLOG(2) << __FUNCTION__ << ", error: " << error;
495 if (presenter_session_callback_) {
496 presenter_session_callback_->Run(
497 presentation::PresentationSessionInfoPtr());
498 presenter_session_callback_.reset();
499 }
500 }
501
460 void PresentationServiceImpl::OnSessionMessages( 502 void PresentationServiceImpl::OnSessionMessages(
461 const PresentationSessionInfo& session, 503 const PresentationSessionInfo& session,
462 const ScopedVector<PresentationSessionMessage>& messages, 504 const ScopedVector<PresentationSessionMessage>& messages,
463 bool pass_ownership) { 505 bool pass_ownership) {
464 DCHECK(client_); 506 DCHECK(client_);
465 507
466 DVLOG(2) << "OnSessionMessages"; 508 DVLOG(2) << "OnSessionMessages";
467 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size()); 509 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages.size());
468 for (size_t i = 0; i < messages.size(); ++i) 510 for (size_t i = 0; i < messages.size(); ++i)
469 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); 511 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 screen_availability_listeners_.clear(); 560 screen_availability_listeners_.clear();
519 session_state_listeners_.clear(); 561 session_state_listeners_.clear();
520 562
521 start_session_request_id_ = kInvalidRequestSessionId; 563 start_session_request_id_ = kInvalidRequestSessionId;
522 pending_start_session_cb_.reset(); 564 pending_start_session_cb_.reset();
523 565
524 pending_join_session_cbs_.clear(); 566 pending_join_session_cbs_.clear();
525 567
526 default_session_start_context_.reset(); 568 default_session_start_context_.reset();
527 569
528 if (on_session_messages_callback_.get()) { 570 if (on_session_messages_callback_) {
529 on_session_messages_callback_->Run( 571 on_session_messages_callback_->Run(
530 mojo::Array<presentation::SessionMessagePtr>()); 572 mojo::Array<presentation::SessionMessagePtr>());
531 on_session_messages_callback_.reset(); 573 on_session_messages_callback_.reset();
532 } 574 }
533 575
534 if (send_message_callback_) { 576 if (send_message_callback_) {
535 // Run the callback with false, indicating the renderer to stop sending 577 // Run the callback with false, indicating the renderer to stop sending
536 // the requests and invalidate all pending requests. 578 // the requests and invalidate all pending requests.
537 send_message_callback_->Run(false); 579 send_message_callback_->Run(false);
538 send_message_callback_.reset(); 580 send_message_callback_.reset();
539 } 581 }
582
583 presenter_session_callback_.reset();
540 } 584 }
541 585
542 void PresentationServiceImpl::OnDelegateDestroyed() { 586 void PresentationServiceImpl::OnDelegateDestroyed() {
543 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 587 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
544 delegate_ = nullptr; 588 delegate_ = nullptr;
545 Reset(); 589 Reset();
546 } 590 }
547 591
548 void PresentationServiceImpl::OnDefaultPresentationStarted( 592 void PresentationServiceImpl::OnDefaultPresentationStarted(
549 const PresentationSessionInfo& session) { 593 const PresentationSessionInfo& session) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 696
653 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { 697 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
654 ScopedVector<DefaultSessionMojoCallback> callbacks; 698 ScopedVector<DefaultSessionMojoCallback> callbacks;
655 callbacks.swap(callbacks_); 699 callbacks.swap(callbacks_);
656 for (const auto& callback : callbacks) 700 for (const auto& callback : callbacks)
657 callback->Run(presentation::PresentationSessionInfoPtr()); 701 callback->Run(presentation::PresentationSessionInfoPtr());
658 session_.reset(); 702 session_.reset();
659 } 703 }
660 704
661 } // namespace content 705 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698