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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 1507743005: [MediaRouter] Renames CloseRoute() to Terminate() and creates DetachRoute() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android build Created 5 years 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 "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 8
9 #include "base/containers/scoped_ptr_hash_map.h" 9 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "base/containers/small_map.h" 10 #include "base/containers/small_map.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 std::string GetDefaultPresentationId() const; 76 std::string GetDefaultPresentationId() const;
77 void ListenForConnectionStateChange( 77 void ListenForConnectionStateChange(
78 const content::PresentationSessionInfo& connection, 78 const content::PresentationSessionInfo& connection,
79 const content::PresentationConnectionStateChangedCallback& 79 const content::PresentationConnectionStateChangedCallback&
80 state_changed_cb); 80 state_changed_cb);
81 void ListenForSessionMessages( 81 void ListenForSessionMessages(
82 const content::PresentationSessionInfo& session, 82 const content::PresentationSessionInfo& session,
83 const content::PresentationSessionMessageCallback& message_cb); 83 const content::PresentationSessionMessageCallback& message_cb);
84 84
85 void Reset(); 85 void Reset();
86 void RemoveConnection(const std::string& presentation_id,
87 const MediaRoute::Id& route_id);
86 88
87 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; 89 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const;
88 const std::vector<MediaRoute::Id> GetRouteIds() const; 90 const std::vector<MediaRoute::Id> GetRouteIds() const;
89 91
90 void OnPresentationSessionStarted( 92 void OnPresentationSessionStarted(
91 const content::PresentationSessionInfo& session, 93 const content::PresentationSessionInfo& session,
92 const MediaRoute::Id& route_id); 94 const MediaRoute::Id& route_id);
93 void OnPresentationServiceDelegateDestroyed() const; 95 void OnPresentationServiceDelegateDestroyed() const;
94 96
95 void set_delegate_observer(DelegateObserver* observer) { 97 void set_delegate_observer(DelegateObserver* observer) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return false; 179 return false;
178 } 180 }
179 181
180 bool PresentationFrame::HasScreenAvailabilityListenerForTest( 182 bool PresentationFrame::HasScreenAvailabilityListenerForTest(
181 const MediaSource::Id& source_id) const { 183 const MediaSource::Id& source_id) const {
182 return sinks_observer_ && sinks_observer_->source().id() == source_id; 184 return sinks_observer_ && sinks_observer_->source().id() == source_id;
183 } 185 }
184 186
185 void PresentationFrame::Reset() { 187 void PresentationFrame::Reset() {
186 for (const auto& pid_route_id : presentation_id_to_route_id_) 188 for (const auto& pid_route_id : presentation_id_to_route_id_)
187 router_->OnPresentationSessionDetached(pid_route_id.second); 189 router_->DetachRoute(pid_route_id.second);
188 190
189 presentation_id_to_route_id_.clear(); 191 presentation_id_to_route_id_.clear();
190 sinks_observer_.reset(); 192 sinks_observer_.reset();
191 connection_state_subscriptions_.clear(); 193 connection_state_subscriptions_.clear();
192 session_messages_observers_.clear(); 194 session_messages_observers_.clear();
193 } 195 }
194 196
197 void PresentationFrame::RemoveConnection(const std::string& presentation_id,
198 const MediaRoute::Id& route_id) {
199 // Remove the presentation id mapping so a later call to Reset is a no-op.
200 presentation_id_to_route_id_.erase(presentation_id);
201
202 // We no longer need to observe route messages.
203 auto observer_iter = std::find_if(
204 session_messages_observers_.begin(), session_messages_observers_.end(),
205 [&route_id](const PresentationSessionMessagesObserver* observer) {
206 return route_id == observer->route_id();
207 });
208 if (observer_iter != session_messages_observers_.end())
209 session_messages_observers_.erase(observer_iter);
210
211 // We keep the PresentationConnectionStateChangedCallback registered with MR
212 // so the MRP can tell us when terminate() completed.
213 }
214
195 void PresentationFrame::ListenForConnectionStateChange( 215 void PresentationFrame::ListenForConnectionStateChange(
196 const content::PresentationSessionInfo& connection, 216 const content::PresentationSessionInfo& connection,
197 const content::PresentationConnectionStateChangedCallback& 217 const content::PresentationConnectionStateChangedCallback&
198 state_changed_cb) { 218 state_changed_cb) {
199 auto it = presentation_id_to_route_id_.find(connection.presentation_id); 219 auto it = presentation_id_to_route_id_.find(connection.presentation_id);
200 if (it == presentation_id_to_route_id_.end()) { 220 if (it == presentation_id_to_route_id_.end()) {
201 DLOG(ERROR) << __FUNCTION__ << "route id not found for presentation: " 221 DLOG(ERROR) << __FUNCTION__ << "route id not found for presentation: "
202 << connection.presentation_id; 222 << connection.presentation_id;
203 return; 223 return;
204 } 224 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, 293 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id,
274 DelegateObserver* observer); 294 DelegateObserver* observer);
275 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); 295 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id);
276 void AddDefaultPresentationRequestObserver( 296 void AddDefaultPresentationRequestObserver(
277 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 297 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
278 observer); 298 observer);
279 void RemoveDefaultPresentationRequestObserver( 299 void RemoveDefaultPresentationRequestObserver(
280 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 300 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
281 observer); 301 observer);
282 void Reset(const RenderFrameHostId& render_frame_host_id); 302 void Reset(const RenderFrameHostId& render_frame_host_id);
303 void RemoveConnection(const RenderFrameHostId& render_frame_host_id,
304 const MediaRoute::Id& route_id,
305 const std::string& presentation_id);
283 bool HasScreenAvailabilityListenerForTest( 306 bool HasScreenAvailabilityListenerForTest(
284 const RenderFrameHostId& render_frame_host_id, 307 const RenderFrameHostId& render_frame_host_id,
285 const MediaSource::Id& source_id) const; 308 const MediaSource::Id& source_id) const;
286 void SetMediaRouterForTest(MediaRouter* router); 309 void SetMediaRouterForTest(MediaRouter* router);
287 310
288 void OnPresentationSessionStarted( 311 void OnPresentationSessionStarted(
289 const RenderFrameHostId& render_frame_host_id, 312 const RenderFrameHostId& render_frame_host_id,
290 const content::PresentationSessionInfo& session, 313 const content::PresentationSessionInfo& session,
291 const MediaRoute::Id& route_id); 314 const MediaRoute::Id& route_id);
292 void OnDefaultPresentationSessionStarted( 315 void OnDefaultPresentationSessionStarted(
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 if (presentation_frame) 521 if (presentation_frame)
499 presentation_frame->Reset(); 522 presentation_frame->Reset();
500 523
501 if (default_presentation_request_ && 524 if (default_presentation_request_ &&
502 render_frame_host_id == 525 render_frame_host_id ==
503 default_presentation_request_->render_frame_host_id()) { 526 default_presentation_request_->render_frame_host_id()) {
504 ClearDefaultPresentationRequest(); 527 ClearDefaultPresentationRequest();
505 } 528 }
506 } 529 }
507 530
531 void PresentationFrameManager::RemoveConnection(
532 const RenderFrameHostId& render_frame_host_id,
533 const MediaRoute::Id& route_id,
534 const std::string& presentation_id) {
535 auto presentation_frame = presentation_frames_.get(render_frame_host_id);
536 if (presentation_frame)
537 presentation_frame->RemoveConnection(route_id, presentation_id);
538 }
539
508 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( 540 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame(
509 const RenderFrameHostId& render_frame_host_id) { 541 const RenderFrameHostId& render_frame_host_id) {
510 if (!presentation_frames_.contains(render_frame_host_id)) { 542 if (!presentation_frames_.contains(render_frame_host_id)) {
511 presentation_frames_.add( 543 presentation_frames_.add(
512 render_frame_host_id, 544 render_frame_host_id,
513 scoped_ptr<PresentationFrame>( 545 scoped_ptr<PresentationFrame>(
514 new PresentationFrame(web_contents_, router_))); 546 new PresentationFrame(web_contents_, router_)));
515 } 547 }
516 return presentation_frames_.get(render_frame_host_id); 548 return presentation_frames_.get(render_frame_host_id);
517 } 549 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 content::PresentationSessionInfo(presentation_url, presentation_id), 740 content::PresentationSessionInfo(presentation_url, presentation_id),
709 success_cb, error_cb)); 741 success_cb, error_cb));
710 router_->JoinRoute( 742 router_->JoinRoute(
711 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, 743 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id,
712 GetLastCommittedURLForFrame( 744 GetLastCommittedURLForFrame(
713 RenderFrameHostId(render_process_id, render_frame_id)) 745 RenderFrameHostId(render_process_id, render_frame_id))
714 .GetOrigin(), 746 .GetOrigin(),
715 web_contents_, route_response_callbacks); 747 web_contents_, route_response_callbacks);
716 } 748 }
717 749
718 void PresentationServiceDelegateImpl::CloseSession( 750 void PresentationServiceDelegateImpl::CloseConnection(
719 int render_process_id, 751 int render_process_id,
720 int render_frame_id, 752 int render_frame_id,
721 const std::string& presentation_id) { 753 const std::string& presentation_id) {
722 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( 754 const RenderFrameHostId rfh_id(render_process_id, render_frame_id);
723 RenderFrameHostId(render_process_id, render_frame_id), presentation_id); 755 const MediaRoute::Id& route_id =
756 frame_manager_->GetRouteId(rfh_id, presentation_id);
724 if (route_id.empty()) { 757 if (route_id.empty()) {
725 DVLOG(1) << "No active route for: " << presentation_id; 758 DVLOG(1) << "No active route for: " << presentation_id;
726 return; 759 return;
727 } 760 }
728 761
729 // TODO(mfoltz, mlamouri): implement CloseSession(). 762 router_->DetachRoute(route_id);
730 // This could call router_->OnPresentationSessionDetached(route_id). 763 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id);
731 // PresentationFrame::Reset() should probably call CloseSession() too. 764 // TODO(mfoltz): close() should always succeed so there is no need to keep the
732 // Rename CloseRoute() to something else to avoid confusion? 765 // state_changed_cb around - remove it and fire the ChangeEvent on the
733 NOTIMPLEMENTED(); 766 // PresentationConnection in Blink.
734 } 767 }
735 768
736 void PresentationServiceDelegateImpl::TerminateSession( 769 void PresentationServiceDelegateImpl::Terminate(
737 int render_process_id, 770 int render_process_id,
738 int render_frame_id, 771 int render_frame_id,
739 const std::string& presentation_id) { 772 const std::string& presentation_id) {
740 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( 773 const RenderFrameHostId rfh_id(render_process_id, render_frame_id);
741 RenderFrameHostId(render_process_id, render_frame_id), presentation_id); 774 const MediaRoute::Id& route_id =
775 frame_manager_->GetRouteId(rfh_id, presentation_id);
742 if (route_id.empty()) { 776 if (route_id.empty()) {
743 DVLOG(1) << "No active route for: " << presentation_id; 777 DVLOG(1) << "No active route for: " << presentation_id;
744 return; 778 return;
745 } 779 }
746 router_->CloseRoute(route_id); 780 router_->TerminateRoute(route_id);
781 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id);
747 } 782 }
748 783
749 void PresentationServiceDelegateImpl::ListenForSessionMessages( 784 void PresentationServiceDelegateImpl::ListenForSessionMessages(
750 int render_process_id, 785 int render_process_id,
751 int render_frame_id, 786 int render_frame_id,
752 const content::PresentationSessionInfo& session, 787 const content::PresentationSessionInfo& session,
753 const content::PresentationSessionMessageCallback& message_cb) { 788 const content::PresentationSessionMessageCallback& message_cb) {
754 frame_manager_->ListenForSessionMessages( 789 frame_manager_->ListenForSessionMessages(
755 RenderFrameHostId(render_process_id, render_frame_id), session, 790 RenderFrameHostId(render_process_id, render_frame_id), session,
756 message_cb); 791 message_cb);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( 873 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest(
839 int render_process_id, 874 int render_process_id,
840 int render_frame_id, 875 int render_frame_id,
841 const MediaSource::Id& source_id) const { 876 const MediaSource::Id& source_id) const {
842 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 877 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
843 return frame_manager_->HasScreenAvailabilityListenerForTest( 878 return frame_manager_->HasScreenAvailabilityListenerForTest(
844 render_frame_host_id, source_id); 879 render_frame_host_id, source_id);
845 } 880 }
846 881
847 } // namespace media_router 882 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/presentation_service_delegate_impl.h ('k') | chrome/browser/media/router/test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698