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

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

Issue 1406013003: [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Original patch Created 5 years, 1 month 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (listener_it == screen_availability_listeners_.end()) 217 if (listener_it == screen_availability_listeners_.end())
218 return; 218 return;
219 219
220 delegate_->RemoveScreenAvailabilityListener( 220 delegate_->RemoveScreenAvailabilityListener(
221 render_process_id_, 221 render_process_id_,
222 render_frame_id_, 222 render_frame_id_,
223 listener_it->second); 223 listener_it->second);
224 screen_availability_listeners_.erase(listener_it); 224 screen_availability_listeners_.erase(listener_it);
225 } 225 }
226 226
227 void PresentationServiceImpl::ListenForDefaultSessionStart(
228 const DefaultSessionMojoCallback& callback) {
229 if (!default_session_start_context_.get())
230 default_session_start_context_.reset(new DefaultSessionStartContext);
231 default_session_start_context_->AddCallback(callback);
232 }
233
234 void PresentationServiceImpl::StartSession( 227 void PresentationServiceImpl::StartSession(
235 const mojo::String& presentation_url, 228 const mojo::String& presentation_url,
236 const NewSessionMojoCallback& callback) { 229 const NewSessionMojoCallback& callback) {
237 DVLOG(2) << "StartSession"; 230 DVLOG(2) << "StartSession";
238 if (!delegate_) { 231 if (!delegate_) {
239 callback.Run( 232 callback.Run(
240 presentation::PresentationSessionInfoPtr(), 233 presentation::PresentationSessionInfoPtr(),
241 presentation::PresentationError::From( 234 presentation::PresentationError::From(
242 PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, 235 PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
243 "No screens found."))); 236 "No screens found.")));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 354
362 void PresentationServiceImpl::SetDefaultPresentationURL( 355 void PresentationServiceImpl::SetDefaultPresentationURL(
363 const mojo::String& url) { 356 const mojo::String& url) {
364 DVLOG(2) << "SetDefaultPresentationURL"; 357 DVLOG(2) << "SetDefaultPresentationURL";
365 if (!delegate_) 358 if (!delegate_)
366 return; 359 return;
367 360
368 const std::string& new_default_url = url.get(); 361 const std::string& new_default_url = url.get();
369 if (default_presentation_url_ == new_default_url) 362 if (default_presentation_url_ == new_default_url)
370 return; 363 return;
364
365 default_presentation_url_ = new_default_url;
371 delegate_->SetDefaultPresentationUrl( 366 delegate_->SetDefaultPresentationUrl(
372 render_process_id_, 367 render_process_id_, render_frame_id_, new_default_url,
373 render_frame_id_, 368 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
374 new_default_url); 369 weak_factory_.GetWeakPtr()));
375 default_presentation_url_ = new_default_url;
376 } 370 }
377 371
378 void PresentationServiceImpl::SendSessionMessage( 372 void PresentationServiceImpl::SendSessionMessage(
379 presentation::PresentationSessionInfoPtr session, 373 presentation::PresentationSessionInfoPtr session,
380 presentation::SessionMessagePtr session_message, 374 presentation::SessionMessagePtr session_message,
381 const SendMessageMojoCallback& callback) { 375 const SendMessageMojoCallback& callback) {
382 DVLOG(2) << "SendSessionMessage"; 376 DVLOG(2) << "SendSessionMessage";
383 DCHECK(!session_message.is_null()); 377 DCHECK(!session_message.is_null());
384 // send_message_callback_ should be null by now, otherwise resetting of 378 // send_message_callback_ should be null by now, otherwise resetting of
385 // send_message_callback_ with new callback will drop the old callback. 379 // send_message_callback_ with new callback will drop the old callback.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 508
515 default_presentation_url_.clear(); 509 default_presentation_url_.clear();
516 510
517 screen_availability_listeners_.clear(); 511 screen_availability_listeners_.clear();
518 512
519 start_session_request_id_ = kInvalidRequestSessionId; 513 start_session_request_id_ = kInvalidRequestSessionId;
520 pending_start_session_cb_.reset(); 514 pending_start_session_cb_.reset();
521 515
522 pending_join_session_cbs_.clear(); 516 pending_join_session_cbs_.clear();
523 517
524 default_session_start_context_.reset();
525
526 if (on_session_messages_callback_.get()) { 518 if (on_session_messages_callback_.get()) {
527 on_session_messages_callback_->Run( 519 on_session_messages_callback_->Run(
528 mojo::Array<presentation::SessionMessagePtr>()); 520 mojo::Array<presentation::SessionMessagePtr>());
529 on_session_messages_callback_.reset(); 521 on_session_messages_callback_.reset();
530 } 522 }
531 523
532 if (send_message_callback_) { 524 if (send_message_callback_) {
533 // Run the callback with false, indicating the renderer to stop sending 525 // Run the callback with false, indicating the renderer to stop sending
534 // the requests and invalidate all pending requests. 526 // the requests and invalidate all pending requests.
535 send_message_callback_->Run(false); 527 send_message_callback_->Run(false);
536 send_message_callback_.reset(); 528 send_message_callback_.reset();
537 } 529 }
538 } 530 }
539 531
540 void PresentationServiceImpl::OnDelegateDestroyed() { 532 void PresentationServiceImpl::OnDelegateDestroyed() {
541 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 533 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
542 delegate_ = nullptr; 534 delegate_ = nullptr;
543 Reset(); 535 Reset();
544 } 536 }
545 537
546 void PresentationServiceImpl::OnDefaultPresentationStarted( 538 void PresentationServiceImpl::OnDefaultPresentationStarted(
547 const PresentationSessionInfo& session) { 539 const PresentationSessionInfo& session_info) {
548 if (default_session_start_context_.get()) 540 DCHECK(client_.get());
549 default_session_start_context_->set_session(session); 541 client_->OnDefaultSessionStarted(
542 presentation::PresentationSessionInfo::From(session_info));
550 } 543 }
551 544
552 PresentationServiceImpl::ScreenAvailabilityListenerImpl 545 PresentationServiceImpl::ScreenAvailabilityListenerImpl
553 ::ScreenAvailabilityListenerImpl( 546 ::ScreenAvailabilityListenerImpl(
554 const std::string& availability_url, 547 const std::string& availability_url,
555 PresentationServiceImpl* service) 548 PresentationServiceImpl* service)
556 : availability_url_(availability_url), 549 : availability_url_(availability_url),
557 service_(service) { 550 service_(service) {
558 DCHECK(service_); 551 DCHECK(service_);
559 DCHECK(service_->client_.get()); 552 DCHECK(service_->client_.get());
(...skipping 30 matching lines...) Expand all
590 } 583 }
591 584
592 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( 585 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run(
593 presentation::PresentationSessionInfoPtr session, 586 presentation::PresentationSessionInfoPtr session,
594 presentation::PresentationErrorPtr error) { 587 presentation::PresentationErrorPtr error) {
595 DCHECK(!callback_.is_null()); 588 DCHECK(!callback_.is_null());
596 callback_.Run(session.Pass(), error.Pass()); 589 callback_.Run(session.Pass(), error.Pass());
597 callback_.reset(); 590 callback_.reset();
598 } 591 }
599 592
600 PresentationServiceImpl::DefaultSessionStartContext
601 ::DefaultSessionStartContext() {
602 }
603
604 PresentationServiceImpl::DefaultSessionStartContext
605 ::~DefaultSessionStartContext() {
606 Reset();
607 }
608
609 void PresentationServiceImpl::DefaultSessionStartContext::AddCallback(
610 const DefaultSessionMojoCallback& callback) {
611 if (session_.get()) {
612 DCHECK(callbacks_.empty());
613 callback.Run(presentation::PresentationSessionInfo::From(*session_));
614 session_.reset();
615 } else {
616 callbacks_.push_back(new DefaultSessionMojoCallback(callback));
617 }
618 }
619
620 void PresentationServiceImpl::DefaultSessionStartContext::set_session(
621 const PresentationSessionInfo& session) {
622 if (callbacks_.empty()) {
623 session_.reset(new PresentationSessionInfo(session));
624 } else {
625 DCHECK(!session_.get());
626 ScopedVector<DefaultSessionMojoCallback> callbacks;
627 callbacks.swap(callbacks_);
628 for (const auto& callback : callbacks)
629 callback->Run(presentation::PresentationSessionInfo::From(session));
630 }
631 }
632
633 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
634 ScopedVector<DefaultSessionMojoCallback> callbacks;
635 callbacks.swap(callbacks_);
636 for (const auto& callback : callbacks)
637 callback->Run(presentation::PresentationSessionInfoPtr());
638 session_.reset();
639 }
640
641 } // namespace content 593 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698