| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 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 // * Create an instance with |render_frame_host_id_| if no instance with the |
| 126 // * Reset 0+ times. | 126 // same |render_frame_host_id_| exists in: |
| 127 // * PresentationFrameManager.RemoveDelegateObserver. | 127 // PresentationFrameManager::OnPresentationSessionStarted |
| 128 // PresentationFrameManager::OnDefaultPresentationSessionStarted |
| 129 // PresentationFrameManager::SetScreenAvailabilityListener |
| 130 // * Destroy the instance in: |
| 131 // PresentationFrameManager::Reset |
| 128 class PresentationFrame { | 132 class PresentationFrame { |
| 129 public: | 133 public: |
| 130 PresentationFrame(const RenderFrameHostId& render_frame_host_id, | 134 PresentationFrame(const RenderFrameHostId& render_frame_host_id, |
| 131 content::WebContents* web_contents, | 135 content::WebContents* web_contents, |
| 132 MediaRouter* router); | 136 MediaRouter* router); |
| 133 ~PresentationFrame(); | 137 ~PresentationFrame(); |
| 134 | 138 |
| 135 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 139 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 136 bool SetScreenAvailabilityListener( | 140 bool SetScreenAvailabilityListener( |
| 137 content::PresentationScreenAvailabilityListener* listener); | 141 content::PresentationScreenAvailabilityListener* listener); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 const MediaRoute::Id& route_id); | 157 const MediaRoute::Id& route_id); |
| 154 | 158 |
| 155 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 159 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 156 const std::vector<MediaRoute::Id> GetRouteIds() const; | 160 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 157 | 161 |
| 158 void OnPresentationSessionStarted( | 162 void OnPresentationSessionStarted( |
| 159 const content::PresentationSessionInfo& session, | 163 const content::PresentationSessionInfo& session, |
| 160 const MediaRoute& route); | 164 const MediaRoute& route); |
| 161 void OnPresentationServiceDelegateDestroyed() const; | 165 void OnPresentationServiceDelegateDestroyed() const; |
| 162 | 166 |
| 163 void set_delegate_observer(DelegateObserver* observer) { | |
| 164 delegate_observer_ = observer; | |
| 165 } | |
| 166 | |
| 167 private: | 167 private: |
| 168 MediaSource GetMediaSourceFromListener( | 168 MediaSource GetMediaSourceFromListener( |
| 169 content::PresentationScreenAvailabilityListener* listener) const; | 169 content::PresentationScreenAvailabilityListener* listener) const; |
| 170 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 170 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| 171 presentation_id_to_route_id_; | 171 presentation_id_to_route_id_; |
| 172 base::SmallMap< | 172 base::SmallMap< |
| 173 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 173 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
| 174 url_to_sinks_observer_; | 174 url_to_sinks_observer_; |
| 175 std::unordered_map< | 175 std::unordered_map< |
| 176 MediaRoute::Id, | 176 MediaRoute::Id, |
| 177 std::unique_ptr<PresentationConnectionStateSubscription>> | 177 std::unique_ptr<PresentationConnectionStateSubscription>> |
| 178 connection_state_subscriptions_; | 178 connection_state_subscriptions_; |
| 179 std::unordered_map< | 179 std::unordered_map< |
| 180 MediaRoute::Id, | 180 MediaRoute::Id, |
| 181 std::unique_ptr<PresentationSessionMessagesObserver>> | 181 std::unique_ptr<PresentationSessionMessagesObserver>> |
| 182 session_messages_observers_; | 182 session_messages_observers_; |
| 183 | 183 |
| 184 RenderFrameHostId render_frame_host_id_; | 184 RenderFrameHostId render_frame_host_id_; |
| 185 | 185 |
| 186 // References to the owning WebContents, and the corresponding MediaRouter. | 186 // References to the owning WebContents, and the corresponding MediaRouter. |
| 187 content::WebContents* web_contents_; | 187 content::WebContents* web_contents_; |
| 188 MediaRouter* router_; | 188 MediaRouter* router_; |
| 189 | |
| 190 DelegateObserver* delegate_observer_; | |
| 191 }; | 189 }; |
| 192 | 190 |
| 193 PresentationFrame::PresentationFrame( | 191 PresentationFrame::PresentationFrame( |
| 194 const RenderFrameHostId& render_frame_host_id, | 192 const RenderFrameHostId& render_frame_host_id, |
| 195 content::WebContents* web_contents, | 193 content::WebContents* web_contents, |
| 196 MediaRouter* router) | 194 MediaRouter* router) |
| 197 : render_frame_host_id_(render_frame_host_id), | 195 : render_frame_host_id_(render_frame_host_id), |
| 198 web_contents_(web_contents), | 196 web_contents_(web_contents), |
| 199 router_(router) { | 197 router_(router) { |
| 200 DCHECK(web_contents_); | 198 DCHECK(web_contents_); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 const content::PresentationSessionInfo& session, | 460 const content::PresentationSessionInfo& session, |
| 463 const MediaRoute& route) { | 461 const MediaRoute& route) { |
| 464 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 462 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 465 presentation_frame->OnPresentationSessionStarted(session, route); | 463 presentation_frame->OnPresentationSessionStarted(session, route); |
| 466 } | 464 } |
| 467 | 465 |
| 468 void PresentationFrameManager::OnDefaultPresentationSessionStarted( | 466 void PresentationFrameManager::OnDefaultPresentationSessionStarted( |
| 469 const PresentationRequest& request, | 467 const PresentationRequest& request, |
| 470 const content::PresentationSessionInfo& session, | 468 const content::PresentationSessionInfo& session, |
| 471 const MediaRoute& route) { | 469 const MediaRoute& route) { |
| 472 const auto it = presentation_frames_.find(request.render_frame_host_id()); | 470 OnPresentationSessionStarted(request.render_frame_host_id(), session, route); |
| 473 if (it != presentation_frames_.end()) | |
| 474 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 |
| 482 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 478 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 483 const RenderFrameHostId& render_frame_host_id, | 479 const RenderFrameHostId& render_frame_host_id, |
| 484 const std::string& presentation_id) const { | 480 const std::string& presentation_id) const { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 566 |
| 571 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver( | 567 void PresentationFrameManager::RemoveDefaultPresentationRequestObserver( |
| 572 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* | 568 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* |
| 573 observer) { | 569 observer) { |
| 574 default_presentation_request_observers_.RemoveObserver(observer); | 570 default_presentation_request_observers_.RemoveObserver(observer); |
| 575 } | 571 } |
| 576 | 572 |
| 577 void PresentationFrameManager::Reset( | 573 void PresentationFrameManager::Reset( |
| 578 const RenderFrameHostId& render_frame_host_id) { | 574 const RenderFrameHostId& render_frame_host_id) { |
| 579 const auto it = presentation_frames_.find(render_frame_host_id); | 575 const auto it = presentation_frames_.find(render_frame_host_id); |
| 580 if (it != presentation_frames_.end()) | 576 if (it != presentation_frames_.end()) { |
| 581 it->second->Reset(); | 577 it->second->Reset(); |
| 578 presentation_frames_.erase(it); |
| 579 } |
| 582 | 580 |
| 583 if (default_presentation_request_ && | 581 if (default_presentation_request_ && |
| 584 render_frame_host_id == | 582 render_frame_host_id == |
| 585 default_presentation_request_->render_frame_host_id()) { | 583 default_presentation_request_->render_frame_host_id()) { |
| 586 ClearDefaultPresentationRequest(); | 584 ClearDefaultPresentationRequest(); |
| 587 } | 585 } |
| 588 } | 586 } |
| 589 | 587 |
| 590 void PresentationFrameManager::RemoveConnection( | 588 void PresentationFrameManager::RemoveConnection( |
| 591 const RenderFrameHostId& render_frame_host_id, | 589 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 const base::ListValue* origins = | 986 const base::ListValue* origins = |
| 989 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 987 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 990 ->GetPrefs() | 988 ->GetPrefs() |
| 991 ->GetList(prefs::kMediaRouterTabMirroringSources); | 989 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 992 return origins && | 990 return origins && |
| 993 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 991 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 994 } | 992 } |
| 995 #endif // !defined(OS_ANDROID) | 993 #endif // !defined(OS_ANDROID) |
| 996 | 994 |
| 997 } // namespace media_router | 995 } // namespace media_router |
| OLD | NEW |