| 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/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void Reset(); | 138 void Reset(); |
| 139 void RemoveConnection(const std::string& presentation_id, | 139 void RemoveConnection(const std::string& presentation_id, |
| 140 const MediaRoute::Id& route_id); | 140 const MediaRoute::Id& route_id); |
| 141 | 141 |
| 142 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 142 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 143 const std::vector<MediaRoute::Id> GetRouteIds() const; | 143 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 144 | 144 |
| 145 void OnPresentationSessionStarted( | 145 void OnPresentationSessionStarted( |
| 146 const content::PresentationSessionInfo& session, | 146 const content::PresentationSessionInfo& session, |
| 147 const MediaRoute::Id& route_id); | 147 const MediaRoute& route); |
| 148 void OnPresentationServiceDelegateDestroyed() const; | 148 void OnPresentationServiceDelegateDestroyed() const; |
| 149 | 149 |
| 150 void set_delegate_observer(DelegateObserver* observer) { | 150 void set_delegate_observer(DelegateObserver* observer) { |
| 151 delegate_observer_ = observer; | 151 delegate_observer_ = observer; |
| 152 } | 152 } |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 MediaSource GetMediaSourceFromListener( | 155 MediaSource GetMediaSourceFromListener( |
| 156 content::PresentationScreenAvailabilityListener* listener) const; | 156 content::PresentationScreenAvailabilityListener* listener) const; |
| 157 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 157 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 PresentationFrame::~PresentationFrame() { | 192 PresentationFrame::~PresentationFrame() { |
| 193 } | 193 } |
| 194 | 194 |
| 195 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { | 195 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { |
| 196 if (delegate_observer_) | 196 if (delegate_observer_) |
| 197 delegate_observer_->OnDelegateDestroyed(); | 197 delegate_observer_->OnDelegateDestroyed(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void PresentationFrame::OnPresentationSessionStarted( | 200 void PresentationFrame::OnPresentationSessionStarted( |
| 201 const content::PresentationSessionInfo& session, | 201 const content::PresentationSessionInfo& session, |
| 202 const MediaRoute::Id& route_id) { | 202 const MediaRoute& route) { |
| 203 presentation_id_to_route_id_[session.presentation_id] = route_id; | 203 presentation_id_to_route_id_[session.presentation_id] = |
| 204 route.media_route_id(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 const MediaRoute::Id PresentationFrame::GetRouteId( | 207 const MediaRoute::Id PresentationFrame::GetRouteId( |
| 207 const std::string& presentation_id) const { | 208 const std::string& presentation_id) const { |
| 208 auto it = presentation_id_to_route_id_.find(presentation_id); | 209 auto it = presentation_id_to_route_id_.find(presentation_id); |
| 209 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 210 return it != presentation_id_to_route_id_.end() ? it->second : ""; |
| 210 } | 211 } |
| 211 | 212 |
| 212 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | 213 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { |
| 213 std::vector<MediaRoute::Id> route_ids; | 214 std::vector<MediaRoute::Id> route_ids; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 const MediaRoute::Id& route_id, | 378 const MediaRoute::Id& route_id, |
| 378 const std::string& presentation_id); | 379 const std::string& presentation_id); |
| 379 bool HasScreenAvailabilityListenerForTest( | 380 bool HasScreenAvailabilityListenerForTest( |
| 380 const RenderFrameHostId& render_frame_host_id, | 381 const RenderFrameHostId& render_frame_host_id, |
| 381 const MediaSource::Id& source_id) const; | 382 const MediaSource::Id& source_id) const; |
| 382 void SetMediaRouterForTest(MediaRouter* router); | 383 void SetMediaRouterForTest(MediaRouter* router); |
| 383 | 384 |
| 384 void OnPresentationSessionStarted( | 385 void OnPresentationSessionStarted( |
| 385 const RenderFrameHostId& render_frame_host_id, | 386 const RenderFrameHostId& render_frame_host_id, |
| 386 const content::PresentationSessionInfo& session, | 387 const content::PresentationSessionInfo& session, |
| 387 const MediaRoute::Id& route_id); | 388 const MediaRoute& route); |
| 388 void OnDefaultPresentationSessionStarted( | 389 void OnDefaultPresentationSessionStarted( |
| 389 const PresentationRequest& request, | 390 const PresentationRequest& request, |
| 390 const content::PresentationSessionInfo& session, | 391 const content::PresentationSessionInfo& session, |
| 391 const MediaRoute::Id& route_id); | 392 const MediaRoute& route); |
| 392 | 393 |
| 393 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 394 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 394 const std::string& presentation_id) const; | 395 const std::string& presentation_id) const; |
| 395 const std::vector<MediaRoute::Id> GetRouteIds( | 396 const std::vector<MediaRoute::Id> GetRouteIds( |
| 396 const RenderFrameHostId& render_frame_host_id) const; | 397 const RenderFrameHostId& render_frame_host_id) const; |
| 397 | 398 |
| 398 const PresentationRequest* default_presentation_request() const { | 399 const PresentationRequest* default_presentation_request() const { |
| 399 return default_presentation_request_.get(); | 400 return default_presentation_request_.get(); |
| 400 } | 401 } |
| 401 | 402 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 449 } |
| 449 | 450 |
| 450 PresentationFrameManager::~PresentationFrameManager() { | 451 PresentationFrameManager::~PresentationFrameManager() { |
| 451 for (auto& frame : presentation_frames_) | 452 for (auto& frame : presentation_frames_) |
| 452 frame.second->OnPresentationServiceDelegateDestroyed(); | 453 frame.second->OnPresentationServiceDelegateDestroyed(); |
| 453 } | 454 } |
| 454 | 455 |
| 455 void PresentationFrameManager::OnPresentationSessionStarted( | 456 void PresentationFrameManager::OnPresentationSessionStarted( |
| 456 const RenderFrameHostId& render_frame_host_id, | 457 const RenderFrameHostId& render_frame_host_id, |
| 457 const content::PresentationSessionInfo& session, | 458 const content::PresentationSessionInfo& session, |
| 458 const MediaRoute::Id& route_id) { | 459 const MediaRoute& route) { |
| 459 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 460 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 460 presentation_frame->OnPresentationSessionStarted(session, route_id); | 461 presentation_frame->OnPresentationSessionStarted(session, route); |
| 461 } | 462 } |
| 462 | 463 |
| 463 void PresentationFrameManager::OnDefaultPresentationSessionStarted( | 464 void PresentationFrameManager::OnDefaultPresentationSessionStarted( |
| 464 const PresentationRequest& request, | 465 const PresentationRequest& request, |
| 465 const content::PresentationSessionInfo& session, | 466 const content::PresentationSessionInfo& session, |
| 466 const MediaRoute::Id& route_id) { | 467 const MediaRoute& route) { |
| 467 const auto it = presentation_frames_.find(request.render_frame_host_id()); | 468 const auto it = presentation_frames_.find(request.render_frame_host_id()); |
| 468 if (it != presentation_frames_.end()) | 469 if (it != presentation_frames_.end()) |
| 469 it->second->OnPresentationSessionStarted(session, route_id); | 470 it->second->OnPresentationSessionStarted(session, route); |
| 470 | 471 |
| 471 if (default_presentation_request_ && | 472 if (default_presentation_request_ && |
| 472 default_presentation_request_->Equals(request)) { | 473 default_presentation_request_->Equals(request)) { |
| 473 default_presentation_started_callback_.Run(session); | 474 default_presentation_started_callback_.Run(session); |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 | 477 |
| 477 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 478 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 478 const RenderFrameHostId& render_frame_host_id, | 479 const RenderFrameHostId& render_frame_host_id, |
| 479 const std::string& presentation_id) const { | 480 const std::string& presentation_id) const { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 } else { | 743 } else { |
| 743 DVLOG(1) << "OnJoinRouteResponse: " | 744 DVLOG(1) << "OnJoinRouteResponse: " |
| 744 << "route_id: " << result.route()->media_route_id() | 745 << "route_id: " << result.route()->media_route_id() |
| 745 << ", presentation URL: " << presentation_url | 746 << ", presentation URL: " << presentation_url |
| 746 << ", presentation ID: " << presentation_id; | 747 << ", presentation ID: " << presentation_id; |
| 747 DCHECK_EQ(presentation_id, result.presentation_id()); | 748 DCHECK_EQ(presentation_id, result.presentation_id()); |
| 748 content::PresentationSessionInfo session(presentation_url, | 749 content::PresentationSessionInfo session(presentation_url, |
| 749 result.presentation_id()); | 750 result.presentation_id()); |
| 750 frame_manager_->OnPresentationSessionStarted( | 751 frame_manager_->OnPresentationSessionStarted( |
| 751 RenderFrameHostId(render_process_id, render_frame_id), session, | 752 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 752 result.route()->media_route_id()); | 753 *result.route()); |
| 753 success_cb.Run(session); | 754 success_cb.Run(session); |
| 754 } | 755 } |
| 755 } | 756 } |
| 756 | 757 |
| 757 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 758 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
| 758 int render_process_id, | 759 int render_process_id, |
| 759 int render_frame_id, | 760 int render_frame_id, |
| 760 const content::PresentationSessionStartedCallback& success_cb, | 761 const content::PresentationSessionStartedCallback& success_cb, |
| 761 const content::PresentationSessionInfo& new_session, | 762 const content::PresentationSessionInfo& new_session, |
| 762 const MediaRoute& route) { | 763 const MediaRoute& route) { |
| 763 const MediaRoute::Id& route_id = route.media_route_id(); | |
| 764 DVLOG(1) << "OnStartSessionSucceeded: " | 764 DVLOG(1) << "OnStartSessionSucceeded: " |
| 765 << "route_id: " << route_id | 765 << "route_id: " << route.media_route_id() |
| 766 << ", presentation URL: " << new_session.presentation_url | 766 << ", presentation URL: " << new_session.presentation_url |
| 767 << ", presentation ID: " << new_session.presentation_id; | 767 << ", presentation ID: " << new_session.presentation_id; |
| 768 frame_manager_->OnPresentationSessionStarted( | 768 frame_manager_->OnPresentationSessionStarted( |
| 769 RenderFrameHostId(render_process_id, render_frame_id), new_session, | 769 RenderFrameHostId(render_process_id, render_frame_id), new_session, |
| 770 route_id); | 770 route); |
| 771 success_cb.Run(new_session); | 771 success_cb.Run(new_session); |
| 772 } | 772 } |
| 773 | 773 |
| 774 void PresentationServiceDelegateImpl::StartSession( | 774 void PresentationServiceDelegateImpl::StartSession( |
| 775 int render_process_id, | 775 int render_process_id, |
| 776 int render_frame_id, | 776 int render_frame_id, |
| 777 const std::vector<GURL>& presentation_urls, | 777 const std::vector<GURL>& presentation_urls, |
| 778 const content::PresentationSessionStartedCallback& success_cb, | 778 const content::PresentationSessionStartedCallback& success_cb, |
| 779 const content::PresentationSessionErrorCallback& error_cb) { | 779 const content::PresentationSessionErrorCallback& error_cb) { |
| 780 if (presentation_urls.empty()) { | 780 if (presentation_urls.empty()) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 920 |
| 921 void PresentationServiceDelegateImpl::OnRouteResponse( | 921 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 922 const PresentationRequest& presentation_request, | 922 const PresentationRequest& presentation_request, |
| 923 const RouteRequestResult& result) { | 923 const RouteRequestResult& result) { |
| 924 if (!result.route()) | 924 if (!result.route()) |
| 925 return; | 925 return; |
| 926 | 926 |
| 927 content::PresentationSessionInfo session_info( | 927 content::PresentationSessionInfo session_info( |
| 928 presentation_request.presentation_url(), result.presentation_id()); | 928 presentation_request.presentation_url(), result.presentation_id()); |
| 929 frame_manager_->OnDefaultPresentationSessionStarted( | 929 frame_manager_->OnDefaultPresentationSessionStarted( |
| 930 presentation_request, session_info, result.route()->media_route_id()); | 930 presentation_request, session_info, *result.route()); |
| 931 } | 931 } |
| 932 | 932 |
| 933 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( | 933 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( |
| 934 DefaultPresentationRequestObserver* observer) { | 934 DefaultPresentationRequestObserver* observer) { |
| 935 frame_manager_->AddDefaultPresentationRequestObserver(observer); | 935 frame_manager_->AddDefaultPresentationRequestObserver(observer); |
| 936 } | 936 } |
| 937 | 937 |
| 938 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( | 938 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( |
| 939 DefaultPresentationRequestObserver* observer) { | 939 DefaultPresentationRequestObserver* observer) { |
| 940 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); | 940 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 964 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 964 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 965 int render_process_id, | 965 int render_process_id, |
| 966 int render_frame_id, | 966 int render_frame_id, |
| 967 const MediaSource::Id& source_id) const { | 967 const MediaSource::Id& source_id) const { |
| 968 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 968 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 969 return frame_manager_->HasScreenAvailabilityListenerForTest( | 969 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 970 render_frame_host_id, source_id); | 970 render_frame_host_id, source_id); |
| 971 } | 971 } |
| 972 | 972 |
| 973 } // namespace media_router | 973 } // namespace media_router |
| OLD | NEW |