Chromium Code Reviews| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 const content::PresentationConnectionMessageCallback message_cb_; | 115 const content::PresentationConnectionMessageCallback message_cb_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); | 117 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 // Used by PresentationServiceDelegateImpl to manage | 122 // Used by PresentationServiceDelegateImpl to manage |
|
imcheng
2017/01/27 20:00:01
Could you update this comment please?
zhaobin
2017/01/27 23:42:50
Done.
| |
| 123 // listeners and default presentation info in a render frame. | 123 // listeners and default presentation info in a render frame. |
| 124 // Its lifetime: | 124 // Its lifetime: |
| 125 // * PresentationFrameManager AddDelegateObserver | 125 // * PresentationFrameManager AddDelegateObserver |
| 126 // * Reset 0+ times. | 126 // * Reset 0+ times. |
| 127 // * PresentationFrameManager.RemoveDelegateObserver. | 127 // * PresentationFrameManager.RemoveDelegateObserver. |
| 128 class PresentationFrame { | 128 class PresentationFrame { |
| 129 public: | 129 public: |
| 130 PresentationFrame(const RenderFrameHostId& render_frame_host_id, | 130 PresentationFrame(const RenderFrameHostId& render_frame_host_id, |
| 131 content::WebContents* web_contents, | 131 content::WebContents* web_contents, |
| 132 MediaRouter* router); | 132 MediaRouter* router); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 153 const MediaRoute::Id& route_id); | 153 const MediaRoute::Id& route_id); |
| 154 | 154 |
| 155 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 155 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 156 const std::vector<MediaRoute::Id> GetRouteIds() const; | 156 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 157 | 157 |
| 158 void OnPresentationSessionStarted( | 158 void OnPresentationSessionStarted( |
| 159 const content::PresentationSessionInfo& session, | 159 const content::PresentationSessionInfo& session, |
| 160 const MediaRoute& route); | 160 const MediaRoute& route); |
| 161 void OnPresentationServiceDelegateDestroyed() const; | 161 void OnPresentationServiceDelegateDestroyed() const; |
| 162 | 162 |
| 163 void set_delegate_observer(DelegateObserver* observer) { | |
| 164 delegate_observer_ = observer; | |
| 165 } | |
| 166 | |
| 167 private: | 163 private: |
| 168 MediaSource GetMediaSourceFromListener( | 164 MediaSource GetMediaSourceFromListener( |
| 169 content::PresentationScreenAvailabilityListener* listener) const; | 165 content::PresentationScreenAvailabilityListener* listener) const; |
| 170 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 166 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| 171 presentation_id_to_route_id_; | 167 presentation_id_to_route_id_; |
| 172 base::SmallMap< | 168 base::SmallMap< |
| 173 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 169 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
| 174 url_to_sinks_observer_; | 170 url_to_sinks_observer_; |
| 175 std::unordered_map< | 171 std::unordered_map< |
| 176 MediaRoute::Id, | 172 MediaRoute::Id, |
| 177 std::unique_ptr<PresentationConnectionStateSubscription>> | 173 std::unique_ptr<PresentationConnectionStateSubscription>> |
| 178 connection_state_subscriptions_; | 174 connection_state_subscriptions_; |
| 179 std::unordered_map< | 175 std::unordered_map< |
| 180 MediaRoute::Id, | 176 MediaRoute::Id, |
| 181 std::unique_ptr<PresentationSessionMessagesObserver>> | 177 std::unique_ptr<PresentationSessionMessagesObserver>> |
| 182 session_messages_observers_; | 178 session_messages_observers_; |
| 183 | 179 |
| 184 RenderFrameHostId render_frame_host_id_; | 180 RenderFrameHostId render_frame_host_id_; |
| 185 | 181 |
| 186 // References to the owning WebContents, and the corresponding MediaRouter. | 182 // References to the owning WebContents, and the corresponding MediaRouter. |
| 187 content::WebContents* web_contents_; | 183 content::WebContents* web_contents_; |
| 188 MediaRouter* router_; | 184 MediaRouter* router_; |
| 189 | |
| 190 DelegateObserver* delegate_observer_; | |
| 191 }; | 185 }; |
| 192 | 186 |
| 193 PresentationFrame::PresentationFrame( | 187 PresentationFrame::PresentationFrame( |
| 194 const RenderFrameHostId& render_frame_host_id, | 188 const RenderFrameHostId& render_frame_host_id, |
| 195 content::WebContents* web_contents, | 189 content::WebContents* web_contents, |
| 196 MediaRouter* router) | 190 MediaRouter* router) |
| 197 : render_frame_host_id_(render_frame_host_id), | 191 : render_frame_host_id_(render_frame_host_id), |
| 198 web_contents_(web_contents), | 192 web_contents_(web_contents), |
| 199 router_(router) { | 193 router_(router) { |
| 200 DCHECK(web_contents_); | 194 DCHECK(web_contents_); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 void SetMediaRouterForTest(MediaRouter* router); | 384 void SetMediaRouterForTest(MediaRouter* router); |
| 391 | 385 |
| 392 void OnPresentationSessionStarted( | 386 void OnPresentationSessionStarted( |
| 393 const RenderFrameHostId& render_frame_host_id, | 387 const RenderFrameHostId& render_frame_host_id, |
| 394 const content::PresentationSessionInfo& session, | 388 const content::PresentationSessionInfo& session, |
| 395 const MediaRoute& route); | 389 const MediaRoute& route); |
| 396 void OnDefaultPresentationSessionStarted( | 390 void OnDefaultPresentationSessionStarted( |
| 397 const PresentationRequest& request, | 391 const PresentationRequest& request, |
| 398 const content::PresentationSessionInfo& session, | 392 const content::PresentationSessionInfo& session, |
| 399 const MediaRoute& route); | 393 const MediaRoute& route); |
| 394 void AddPresentationFrame(const RenderFrameHostId& render_frame_host_id); | |
| 395 void RemovePresentationFrame(const RenderFrameHostId& render_frame_host_id); | |
| 400 | 396 |
| 401 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 397 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 402 const std::string& presentation_id) const; | 398 const std::string& presentation_id) const; |
| 403 const std::vector<MediaRoute::Id> GetRouteIds( | 399 const std::vector<MediaRoute::Id> GetRouteIds( |
| 404 const RenderFrameHostId& render_frame_host_id) const; | 400 const RenderFrameHostId& render_frame_host_id) const; |
| 405 | 401 |
| 406 const PresentationRequest* default_presentation_request() const { | 402 const PresentationRequest* default_presentation_request() const { |
| 407 return default_presentation_request_.get(); | 403 return default_presentation_request_.get(); |
| 408 } | 404 } |
| 409 | 405 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 const auto it = presentation_frames_.find(request.render_frame_host_id()); | 468 const auto it = presentation_frames_.find(request.render_frame_host_id()); |
| 473 if (it != presentation_frames_.end()) | 469 if (it != presentation_frames_.end()) |
| 474 it->second->OnPresentationSessionStarted(session, route); | 470 it->second->OnPresentationSessionStarted(session, route); |
| 475 | 471 |
| 476 if (default_presentation_request_ && | 472 if (default_presentation_request_ && |
| 477 default_presentation_request_->Equals(request)) { | 473 default_presentation_request_->Equals(request)) { |
| 478 default_presentation_started_callback_.Run(session); | 474 default_presentation_started_callback_.Run(session); |
| 479 } | 475 } |
| 480 } | 476 } |
| 481 | 477 |
| 478 void PresentationFrameManager::AddPresentationFrame( | |
| 479 const RenderFrameHostId& render_frame_host_id) { | |
| 480 GetOrAddPresentationFrame(render_frame_host_id); | |
| 481 } | |
| 482 | |
| 483 void PresentationFrameManager::RemovePresentationFrame( | |
| 484 const RenderFrameHostId& render_frame_host_id) { | |
| 485 const auto it = presentation_frames_.find(render_frame_host_id); | |
|
imcheng
2017/01/27 20:00:01
This can just be presentation_frames_.erase(render
zhaobin
2017/01/27 23:42:50
Code removed.
| |
| 486 if (it != presentation_frames_.end()) | |
| 487 presentation_frames_.erase(it); | |
| 488 } | |
| 489 | |
| 482 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 490 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 483 const RenderFrameHostId& render_frame_host_id, | 491 const RenderFrameHostId& render_frame_host_id, |
| 484 const std::string& presentation_id) const { | 492 const std::string& presentation_id) const { |
| 485 const auto it = presentation_frames_.find(render_frame_host_id); | 493 const auto it = presentation_frames_.find(render_frame_host_id); |
| 486 return it != presentation_frames_.end() | 494 return it != presentation_frames_.end() |
| 487 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 495 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); |
| 488 } | 496 } |
| 489 | 497 |
| 490 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | 498 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( |
| 491 const RenderFrameHostId& render_frame_host_id) const { | 499 const RenderFrameHostId& render_frame_host_id) const { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 } | 668 } |
| 661 | 669 |
| 662 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { | 670 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { |
| 663 } | 671 } |
| 664 | 672 |
| 665 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, | 673 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, |
| 666 int render_frame_id, | 674 int render_frame_id, |
| 667 DelegateObserver* observer) { | 675 DelegateObserver* observer) { |
| 668 DCHECK(observer); | 676 DCHECK(observer); |
| 669 observers_.AddObserver(render_process_id, render_frame_id, observer); | 677 observers_.AddObserver(render_process_id, render_frame_id, observer); |
| 678 frame_manager_->AddPresentationFrame( | |
|
imcheng
2017/01/27 20:00:01
It seems to me we don't need to explicitly add a P
zhaobin
2017/01/27 23:42:50
Done.
| |
| 679 RenderFrameHostId(render_process_id, render_frame_id)); | |
| 670 } | 680 } |
| 671 | 681 |
| 672 void PresentationServiceDelegateImpl::RemoveObserver(int render_process_id, | 682 void PresentationServiceDelegateImpl::RemoveObserver(int render_process_id, |
| 673 int render_frame_id) { | 683 int render_frame_id) { |
| 674 observers_.RemoveObserver(render_process_id, render_frame_id); | 684 observers_.RemoveObserver(render_process_id, render_frame_id); |
| 685 frame_manager_->RemovePresentationFrame( | |
|
imcheng
2017/01/27 20:00:01
I think it would make more sense to erase the Pres
zhaobin
2017/01/27 23:42:50
Done.
| |
| 686 RenderFrameHostId(render_process_id, render_frame_id)); | |
| 675 } | 687 } |
| 676 | 688 |
| 677 bool PresentationServiceDelegateImpl::AddScreenAvailabilityListener( | 689 bool PresentationServiceDelegateImpl::AddScreenAvailabilityListener( |
| 678 int render_process_id, | 690 int render_process_id, |
| 679 int render_frame_id, | 691 int render_frame_id, |
| 680 content::PresentationScreenAvailabilityListener* listener) { | 692 content::PresentationScreenAvailabilityListener* listener) { |
| 681 DCHECK(listener); | 693 DCHECK(listener); |
| 682 return frame_manager_->SetScreenAvailabilityListener( | 694 return frame_manager_->SetScreenAvailabilityListener( |
| 683 RenderFrameHostId(render_process_id, render_frame_id), listener); | 695 RenderFrameHostId(render_process_id, render_frame_id), listener); |
| 684 } | 696 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 const base::ListValue* origins = | 1000 const base::ListValue* origins = |
| 989 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1001 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 990 ->GetPrefs() | 1002 ->GetPrefs() |
| 991 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1003 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 992 return origins && | 1004 return origins && |
| 993 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1005 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 994 } | 1006 } |
| 995 #endif // !defined(OS_ANDROID) | 1007 #endif // !defined(OS_ANDROID) |
| 996 | 1008 |
| 997 } // namespace media_router | 1009 } // namespace media_router |
| OLD | NEW |