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

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

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: resolve code review comments from jam Created 4 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 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/containers/small_map.h" 12 #include "base/containers/small_map.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "chrome/browser/media/router/create_presentation_connection_request.h" 17 #include "chrome/browser/media/router/create_presentation_connection_request.h"
18 #include "chrome/browser/media/router/media_route.h" 18 #include "chrome/browser/media/router/media_route.h"
19 #include "chrome/browser/media/router/media_router.h" 19 #include "chrome/browser/media/router/media_router.h"
20 #include "chrome/browser/media/router/media_router_dialog_controller.h" 20 #include "chrome/browser/media/router/media_router_dialog_controller.h"
21 #include "chrome/browser/media/router/media_router_factory.h" 21 #include "chrome/browser/media/router/media_router_factory.h"
22 #include "chrome/browser/media/router/media_sink.h" 22 #include "chrome/browser/media/router/media_sink.h"
23 #include "chrome/browser/media/router/media_source_helper.h" 23 #include "chrome/browser/media/router/media_source_helper.h"
24 #include "chrome/browser/media/router/offscreen_presentation_manager.h"
25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h"
24 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h"
25 #include "chrome/browser/media/router/route_message.h" 27 #include "chrome/browser/media/router/route_message.h"
26 #include "chrome/browser/media/router/route_message_observer.h" 28 #include "chrome/browser/media/router/route_message_observer.h"
27 #include "chrome/browser/media/router/route_request_result.h" 29 #include "chrome/browser/media/router/route_request_result.h"
28 #include "chrome/browser/sessions/session_tab_helper.h" 30 #include "chrome/browser/sessions/session_tab_helper.h"
29 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/presentation_screen_availability_listener.h" 32 #include "content/public/browser/presentation_screen_availability_listener.h"
31 #include "content/public/browser/presentation_session.h" 33 #include "content/public/browser/presentation_session.h"
32 #include "content/public/browser/render_frame_host.h" 34 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h" 35 #include "content/public/browser/render_process_host.h"
36 #include "url/gurl.h"
34 37
35 #if !defined(OS_ANDROID) 38 #if !defined(OS_ANDROID)
36 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
38 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
39 #endif 42 #endif
40 43
41 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
42 media_router::PresentationServiceDelegateImpl); 45 media_router::PresentationServiceDelegateImpl);
43 46
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 190
188 DelegateObserver* delegate_observer_; 191 DelegateObserver* delegate_observer_;
189 }; 192 };
190 193
191 PresentationFrame::PresentationFrame( 194 PresentationFrame::PresentationFrame(
192 const RenderFrameHostId& render_frame_host_id, 195 const RenderFrameHostId& render_frame_host_id,
193 content::WebContents* web_contents, 196 content::WebContents* web_contents,
194 MediaRouter* router) 197 MediaRouter* router)
195 : render_frame_host_id_(render_frame_host_id), 198 : render_frame_host_id_(render_frame_host_id),
196 web_contents_(web_contents), 199 web_contents_(web_contents),
197 router_(router), 200 router_(router) {
198 delegate_observer_(nullptr) {
199 DCHECK(web_contents_); 201 DCHECK(web_contents_);
200 DCHECK(router_); 202 DCHECK(router_);
201 } 203 }
202 204
203 PresentationFrame::~PresentationFrame() { 205 PresentationFrame::~PresentationFrame() {
204 } 206 }
205 207
206 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const {
207 if (delegate_observer_)
208 delegate_observer_->OnDelegateDestroyed();
209 }
210
211 void PresentationFrame::OnPresentationSessionStarted( 208 void PresentationFrame::OnPresentationSessionStarted(
212 const content::PresentationSessionInfo& session, 209 const content::PresentationSessionInfo& session,
213 const MediaRoute& route) { 210 const MediaRoute& route) {
214 presentation_id_to_route_id_[session.presentation_id] = 211 presentation_id_to_route_id_[session.presentation_id] =
215 route.media_route_id(); 212 route.media_route_id();
216 } 213 }
217 214
218 const MediaRoute::Id PresentationFrame::GetRouteId( 215 const MediaRoute::Id PresentationFrame::GetRouteId(
219 const std::string& presentation_id) const { 216 const std::string& presentation_id) const {
220 auto it = presentation_id_to_route_id_.find(presentation_id); 217 auto it = presentation_id_to_route_id_.find(presentation_id);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 }; 450 };
454 451
455 PresentationFrameManager::PresentationFrameManager( 452 PresentationFrameManager::PresentationFrameManager(
456 content::WebContents* web_contents, 453 content::WebContents* web_contents,
457 MediaRouter* router) 454 MediaRouter* router)
458 : router_(router), web_contents_(web_contents) { 455 : router_(router), web_contents_(web_contents) {
459 DCHECK(web_contents_); 456 DCHECK(web_contents_);
460 DCHECK(router_); 457 DCHECK(router_);
461 } 458 }
462 459
463 PresentationFrameManager::~PresentationFrameManager() { 460 PresentationFrameManager::~PresentationFrameManager() {}
464 for (auto& frame : presentation_frames_)
465 frame.second->OnPresentationServiceDelegateDestroyed();
466 }
467 461
468 void PresentationFrameManager::OnPresentationSessionStarted( 462 void PresentationFrameManager::OnPresentationSessionStarted(
469 const RenderFrameHostId& render_frame_host_id, 463 const RenderFrameHostId& render_frame_host_id,
470 const content::PresentationSessionInfo& session, 464 const content::PresentationSessionInfo& session,
471 const MediaRoute& route) { 465 const MediaRoute& route) {
472 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 466 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
473 presentation_frame->OnPresentationSessionStarted(session, route); 467 presentation_frame->OnPresentationSessionStarted(session, route);
474 } 468 }
475 469
476 void PresentationFrameManager::OnDefaultPresentationSessionStarted( 470 void PresentationFrameManager::OnDefaultPresentationSessionStarted(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 DCHECK(!callback.is_null()); 558 DCHECK(!callback.is_null());
565 GURL frame_url( 559 GURL frame_url(
566 GetLastCommittedURLForFrame(render_frame_host_id, web_contents_)); 560 GetLastCommittedURLForFrame(render_frame_host_id, web_contents_));
567 PresentationRequest request(render_frame_host_id, default_presentation_urls, 561 PresentationRequest request(render_frame_host_id, default_presentation_urls,
568 frame_url); 562 frame_url);
569 default_presentation_started_callback_ = callback; 563 default_presentation_started_callback_ = callback;
570 SetDefaultPresentationRequest(request); 564 SetDefaultPresentationRequest(request);
571 } 565 }
572 } 566 }
573 567
574 void PresentationFrameManager::AddDelegateObserver(
575 const RenderFrameHostId& render_frame_host_id,
576 DelegateObserver* observer) {
577 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
578 presentation_frame->set_delegate_observer(observer);
579 }
580
581 void PresentationFrameManager::RemoveDelegateObserver(
582 const RenderFrameHostId& render_frame_host_id) {
583 const auto it = presentation_frames_.find(render_frame_host_id);
584 if (it != presentation_frames_.end()) {
585 it->second->set_delegate_observer(nullptr);
586 presentation_frames_.erase(it);
587 }
588 }
589
590 void PresentationFrameManager::AddDefaultPresentationRequestObserver( 568 void PresentationFrameManager::AddDefaultPresentationRequestObserver(
591 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 569 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
592 observer) { 570 observer) {
593 default_presentation_request_observers_.AddObserver(observer); 571 default_presentation_request_observers_.AddObserver(observer);
594 } 572 }
595 573
596 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver( 574 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver(
597 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 575 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
598 observer) { 576 observer) {
599 default_presentation_request_observers_.RemoveObserver(observer); 577 default_presentation_request_observers_.RemoveObserver(observer);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 DCHECK(router_); 662 DCHECK(router_);
685 } 663 }
686 664
687 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { 665 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() {
688 } 666 }
689 667
690 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, 668 void PresentationServiceDelegateImpl::AddObserver(int render_process_id,
691 int render_frame_id, 669 int render_frame_id,
692 DelegateObserver* observer) { 670 DelegateObserver* observer) {
693 DCHECK(observer); 671 DCHECK(observer);
694 frame_manager_->AddDelegateObserver( 672 observers_.AddObserver(render_process_id, render_frame_id, observer);
695 RenderFrameHostId(render_process_id, render_frame_id), observer);
696 } 673 }
697 674
698 void PresentationServiceDelegateImpl::RemoveObserver(int render_process_id, 675 void PresentationServiceDelegateImpl::RemoveObserver(int render_process_id,
699 int render_frame_id) { 676 int render_frame_id) {
700 frame_manager_->RemoveDelegateObserver( 677 observers_.RemoveObserver(render_process_id, render_frame_id);
701 RenderFrameHostId(render_process_id, render_frame_id));
702 } 678 }
703 679
704 bool PresentationServiceDelegateImpl::AddScreenAvailabilityListener( 680 bool PresentationServiceDelegateImpl::AddScreenAvailabilityListener(
705 int render_process_id, 681 int render_process_id,
706 int render_frame_id, 682 int render_frame_id,
707 content::PresentationScreenAvailabilityListener* listener) { 683 content::PresentationScreenAvailabilityListener* listener) {
708 DCHECK(listener); 684 DCHECK(listener);
709 return frame_manager_->SetScreenAvailabilityListener( 685 return frame_manager_->SetScreenAvailabilityListener(
710 RenderFrameHostId(render_process_id, render_frame_id), listener); 686 RenderFrameHostId(render_process_id, render_frame_id), listener);
711 } 687 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 int render_process_id, 907 int render_process_id,
932 int render_frame_id, 908 int render_frame_id,
933 const content::PresentationSessionInfo& connection, 909 const content::PresentationSessionInfo& connection,
934 const content::PresentationConnectionStateChangedCallback& 910 const content::PresentationConnectionStateChangedCallback&
935 state_changed_cb) { 911 state_changed_cb) {
936 frame_manager_->ListenForConnectionStateChange( 912 frame_manager_->ListenForConnectionStateChange(
937 RenderFrameHostId(render_process_id, render_frame_id), connection, 913 RenderFrameHostId(render_process_id, render_frame_id), connection,
938 state_changed_cb); 914 state_changed_cb);
939 } 915 }
940 916
917 void PresentationServiceDelegateImpl::ConnectToOffscreenPresentation(
918 int render_process_id,
919 int render_frame_id,
920 const content::PresentationSessionInfo& session,
921 content::PresentationConnectionPtr connection) {
922 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
923 auto* const offscreen_presentation_manager =
924 OffscreenPresentationManagerFactory::GetOrCreateForWebContents(
925 web_contents_);
926 offscreen_presentation_manager->RegisterOffscreenPresentationController(
927 session.presentation_id, session.presentation_url, render_frame_host_id,
928 std::move(connection));
929 }
930
941 void PresentationServiceDelegateImpl::OnRouteResponse( 931 void PresentationServiceDelegateImpl::OnRouteResponse(
942 const PresentationRequest& presentation_request, 932 const PresentationRequest& presentation_request,
943 const RouteRequestResult& result) { 933 const RouteRequestResult& result) {
944 if (!result.route() || 934 if (!result.route() ||
945 !base::ContainsValue(presentation_request.presentation_urls(), 935 !base::ContainsValue(presentation_request.presentation_urls(),
946 result.presentation_url())) { 936 result.presentation_url())) {
947 return; 937 return;
948 } 938 }
949 939
950 content::PresentationSessionInfo session_info(result.presentation_url(), 940 content::PresentationSessionInfo session_info(result.presentation_url(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 const base::ListValue* origins = 989 const base::ListValue* origins =
1000 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) 990 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
1001 ->GetPrefs() 991 ->GetPrefs()
1002 ->GetList(prefs::kMediaRouterTabMirroringSources); 992 ->GetList(prefs::kMediaRouterTabMirroringSources);
1003 return origins && 993 return origins &&
1004 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); 994 origins->Find(base::StringValue(origin.Serialize())) != origins->end();
1005 } 995 }
1006 #endif // !defined(OS_ANDROID) 996 #endif // !defined(OS_ANDROID)
1007 997
1008 } // namespace media_router 998 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698