| OLD | NEW |
| 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 "chrome/browser/media/router/media_router_mojo_impl.h" | 5 #include "chrome/browser/media/router/media_router_mojo_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/media/router/issues_observer.h" | 14 #include "chrome/browser/media/router/issues_observer.h" |
| 15 #include "chrome/browser/media/router/local_media_routes_observer.h" | 15 #include "chrome/browser/media/router/local_media_routes_observer.h" |
| 16 #include "chrome/browser/media/router/media_router_factory.h" | 16 #include "chrome/browser/media/router/media_router_factory.h" |
| 17 #include "chrome/browser/media/router/media_router_type_converters.h" | 17 #include "chrome/browser/media/router/media_router_type_converters.h" |
| 18 #include "chrome/browser/media/router/media_routes_observer.h" | 18 #include "chrome/browser/media/router/media_routes_observer.h" |
| 19 #include "chrome/browser/media/router/media_sinks_observer.h" | 19 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 20 #include "chrome/browser/media/router/presentation_connection_state_observer.h" | |
| 21 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 20 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 22 #include "chrome/browser/sessions/session_tab_helper.h" | 21 #include "chrome/browser/sessions/session_tab_helper.h" |
| 23 #include "extensions/browser/process_manager.h" | 22 #include "extensions/browser/process_manager.h" |
| 24 | 23 |
| 25 #define DVLOG_WITH_INSTANCE(level) \ | 24 #define DVLOG_WITH_INSTANCE(level) \ |
| 26 DVLOG(level) << "MR #" << instance_id_ << ": " | 25 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 27 | 26 |
| 28 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 27 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| 29 | 28 |
| 30 namespace media_router { | 29 namespace media_router { |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 void MediaRouterMojoImpl::UnregisterLocalMediaRoutesObserver( | 498 void MediaRouterMojoImpl::UnregisterLocalMediaRoutesObserver( |
| 500 LocalMediaRoutesObserver* observer) { | 499 LocalMediaRoutesObserver* observer) { |
| 501 DCHECK(thread_checker_.CalledOnValidThread()); | 500 DCHECK(thread_checker_.CalledOnValidThread()); |
| 502 DCHECK(observer); | 501 DCHECK(observer); |
| 503 | 502 |
| 504 if (!local_routes_observers_.HasObserver(observer)) | 503 if (!local_routes_observers_.HasObserver(observer)) |
| 505 return; | 504 return; |
| 506 local_routes_observers_.RemoveObserver(observer); | 505 local_routes_observers_.RemoveObserver(observer); |
| 507 } | 506 } |
| 508 | 507 |
| 509 void MediaRouterMojoImpl::RegisterPresentationConnectionStateObserver( | |
| 510 PresentationConnectionStateObserver* observer) { | |
| 511 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 512 DCHECK(observer); | |
| 513 | |
| 514 const MediaRoute::Id route_id = observer->route_id(); | |
| 515 auto* observers = presentation_connection_state_observers_.get(route_id); | |
| 516 if (!observers) { | |
| 517 observers = new PresentationConnectionStateObserverList; | |
| 518 presentation_connection_state_observers_.add(route_id, | |
| 519 make_scoped_ptr(observers)); | |
| 520 } | |
| 521 | |
| 522 if (observers->HasObserver(observer)) | |
| 523 return; | |
| 524 | |
| 525 observers->AddObserver(observer); | |
| 526 } | |
| 527 | |
| 528 void MediaRouterMojoImpl::UnregisterPresentationConnectionStateObserver( | |
| 529 PresentationConnectionStateObserver* observer) { | |
| 530 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 531 DCHECK(observer); | |
| 532 | |
| 533 const MediaRoute::Id route_id = observer->route_id(); | |
| 534 auto* observers = presentation_connection_state_observers_.get(route_id); | |
| 535 if (!observers) | |
| 536 return; | |
| 537 | |
| 538 observers->RemoveObserver(observer); | |
| 539 if (!observers->might_have_observers()) | |
| 540 presentation_connection_state_observers_.erase(route_id); | |
| 541 } | |
| 542 | |
| 543 void MediaRouterMojoImpl::DoCreateRoute( | 508 void MediaRouterMojoImpl::DoCreateRoute( |
| 544 const MediaSource::Id& source_id, | 509 const MediaSource::Id& source_id, |
| 545 const MediaSink::Id& sink_id, | 510 const MediaSink::Id& sink_id, |
| 546 const std::string& origin, | 511 const std::string& origin, |
| 547 int tab_id, | 512 int tab_id, |
| 548 const std::vector<MediaRouteResponseCallback>& callbacks) { | 513 const std::vector<MediaRouteResponseCallback>& callbacks) { |
| 549 std::string presentation_id("mr_"); | 514 std::string presentation_id("mr_"); |
| 550 presentation_id += base::GenerateGUID(); | 515 presentation_id += base::GenerateGUID(); |
| 551 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 516 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| 552 << ", presentation ID: " << presentation_id; | 517 << ", presentation ID: " << presentation_id; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 652 |
| 688 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( | 653 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( |
| 689 const mojo::String& route_id, | 654 const mojo::String& route_id, |
| 690 interfaces::MediaRouter::PresentationConnectionState state) { | 655 interfaces::MediaRouter::PresentationConnectionState state) { |
| 691 if (!interfaces::MediaRouter::PresentationConnectionState_IsValidValue( | 656 if (!interfaces::MediaRouter::PresentationConnectionState_IsValidValue( |
| 692 state)) { | 657 state)) { |
| 693 DLOG(WARNING) << "Unknown PresentationConnectionState value " << state; | 658 DLOG(WARNING) << "Unknown PresentationConnectionState value " << state; |
| 694 return; | 659 return; |
| 695 } | 660 } |
| 696 | 661 |
| 697 auto* observers = presentation_connection_state_observers_.get(route_id); | 662 NotifyPresentationConnectionStateChange( |
| 698 if (!observers) | 663 route_id, mojo::PresentationConnectionStateFromMojo(state)); |
| 699 return; | |
| 700 | |
| 701 content::PresentationConnectionState converted_state = | |
| 702 mojo::PresentationConnectionStateFromMojo(state); | |
| 703 FOR_EACH_OBSERVER(PresentationConnectionStateObserver, *observers, | |
| 704 OnStateChanged(converted_state)); | |
| 705 } | 664 } |
| 706 | 665 |
| 707 void MediaRouterMojoImpl::DoOnPresentationSessionDetached( | 666 void MediaRouterMojoImpl::DoOnPresentationSessionDetached( |
| 708 const MediaRoute::Id& route_id) { | 667 const MediaRoute::Id& route_id) { |
| 709 DVLOG_WITH_INSTANCE(1) << "DoOnPresentationSessionDetached " << route_id; | 668 DVLOG_WITH_INSTANCE(1) << "DoOnPresentationSessionDetached " << route_id; |
| 710 media_route_provider_->OnPresentationSessionDetached(route_id); | 669 media_route_provider_->OnPresentationSessionDetached(route_id); |
| 711 } | 670 } |
| 712 | 671 |
| 713 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const { | 672 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const { |
| 714 return has_local_display_route_; | 673 return has_local_display_route_; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 797 } |
| 839 | 798 |
| 840 void MediaRouterMojoImpl::DrainPendingRequests() { | 799 void MediaRouterMojoImpl::DrainPendingRequests() { |
| 841 DLOG_WITH_INSTANCE(ERROR) | 800 DLOG_WITH_INSTANCE(ERROR) |
| 842 << "Draining request queue. (queue-length=" << pending_requests_.size() | 801 << "Draining request queue. (queue-length=" << pending_requests_.size() |
| 843 << ")"; | 802 << ")"; |
| 844 pending_requests_.clear(); | 803 pending_requests_.clear(); |
| 845 } | 804 } |
| 846 | 805 |
| 847 } // namespace media_router | 806 } // namespace media_router |
| OLD | NEW |