| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 state_changed_cb); | 150 state_changed_cb); |
| 151 void ListenForSessionMessages( | 151 void ListenForSessionMessages( |
| 152 const content::PresentationSessionInfo& session, | 152 const content::PresentationSessionInfo& session, |
| 153 const content::PresentationConnectionMessageCallback& message_cb); | 153 const content::PresentationConnectionMessageCallback& message_cb); |
| 154 | 154 |
| 155 void Reset(); | 155 void Reset(); |
| 156 void RemoveConnection(const std::string& presentation_id, | 156 void RemoveConnection(const std::string& presentation_id, |
| 157 const MediaRoute::Id& route_id); | 157 const MediaRoute::Id& route_id); |
| 158 | 158 |
| 159 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 159 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 160 const std::vector<MediaRoute::Id> GetRouteIds() const; | |
| 161 | 160 |
| 162 void OnPresentationSessionStarted( | 161 void OnPresentationSessionStarted( |
| 163 const content::PresentationSessionInfo& session, | 162 const content::PresentationSessionInfo& session, |
| 164 const MediaRoute& route); | 163 const MediaRoute& route); |
| 165 void OnPresentationServiceDelegateDestroyed() const; | 164 void OnPresentationServiceDelegateDestroyed() const; |
| 166 | 165 |
| 167 private: | 166 private: |
| 168 MediaSource GetMediaSourceFromListener( | 167 MediaSource GetMediaSourceFromListener( |
| 169 content::PresentationScreenAvailabilityListener* listener) const; | 168 content::PresentationScreenAvailabilityListener* listener) const; |
| 170 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 169 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 presentation_id_to_route_id_[session.presentation_id] = | 207 presentation_id_to_route_id_[session.presentation_id] = |
| 209 route.media_route_id(); | 208 route.media_route_id(); |
| 210 } | 209 } |
| 211 | 210 |
| 212 const MediaRoute::Id PresentationFrame::GetRouteId( | 211 const MediaRoute::Id PresentationFrame::GetRouteId( |
| 213 const std::string& presentation_id) const { | 212 const std::string& presentation_id) const { |
| 214 auto it = presentation_id_to_route_id_.find(presentation_id); | 213 auto it = presentation_id_to_route_id_.find(presentation_id); |
| 215 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 214 return it != presentation_id_to_route_id_.end() ? it->second : ""; |
| 216 } | 215 } |
| 217 | 216 |
| 218 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | |
| 219 std::vector<MediaRoute::Id> route_ids; | |
| 220 for (const auto& e : presentation_id_to_route_id_) | |
| 221 route_ids.push_back(e.second); | |
| 222 return route_ids; | |
| 223 } | |
| 224 | |
| 225 bool PresentationFrame::SetScreenAvailabilityListener( | 217 bool PresentationFrame::SetScreenAvailabilityListener( |
| 226 content::PresentationScreenAvailabilityListener* listener) { | 218 content::PresentationScreenAvailabilityListener* listener) { |
| 227 MediaSource source(GetMediaSourceFromListener(listener)); | 219 MediaSource source(GetMediaSourceFromListener(listener)); |
| 228 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 220 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
| 229 if (sinks_observer && sinks_observer->listener() == listener) | 221 if (sinks_observer && sinks_observer->listener() == listener) |
| 230 return false; | 222 return false; |
| 231 | 223 |
| 232 sinks_observer.reset(new PresentationMediaSinksObserver( | 224 sinks_observer.reset(new PresentationMediaSinksObserver( |
| 233 router_, listener, source, | 225 router_, listener, source, |
| 234 GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin())); | 226 GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin())); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const RenderFrameHostId& render_frame_host_id, | 383 const RenderFrameHostId& render_frame_host_id, |
| 392 const content::PresentationSessionInfo& session, | 384 const content::PresentationSessionInfo& session, |
| 393 const MediaRoute& route); | 385 const MediaRoute& route); |
| 394 void OnDefaultPresentationSessionStarted( | 386 void OnDefaultPresentationSessionStarted( |
| 395 const PresentationRequest& request, | 387 const PresentationRequest& request, |
| 396 const content::PresentationSessionInfo& session, | 388 const content::PresentationSessionInfo& session, |
| 397 const MediaRoute& route); | 389 const MediaRoute& route); |
| 398 | 390 |
| 399 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 391 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 400 const std::string& presentation_id) const; | 392 const std::string& presentation_id) const; |
| 401 const std::vector<MediaRoute::Id> GetRouteIds( | |
| 402 const RenderFrameHostId& render_frame_host_id) const; | |
| 403 | 393 |
| 404 const PresentationRequest* default_presentation_request() const { | 394 const PresentationRequest* default_presentation_request() const { |
| 405 return default_presentation_request_.get(); | 395 return default_presentation_request_.get(); |
| 406 } | 396 } |
| 407 | 397 |
| 408 private: | 398 private: |
| 409 PresentationFrame* GetOrAddPresentationFrame( | 399 PresentationFrame* GetOrAddPresentationFrame( |
| 410 const RenderFrameHostId& render_frame_host_id); | 400 const RenderFrameHostId& render_frame_host_id); |
| 411 | 401 |
| 412 // Sets the default presentation request for the owning WebContents and | 402 // Sets the default presentation request for the owning WebContents and |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 466 } |
| 477 | 467 |
| 478 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 468 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 479 const RenderFrameHostId& render_frame_host_id, | 469 const RenderFrameHostId& render_frame_host_id, |
| 480 const std::string& presentation_id) const { | 470 const std::string& presentation_id) const { |
| 481 const auto it = presentation_frames_.find(render_frame_host_id); | 471 const auto it = presentation_frames_.find(render_frame_host_id); |
| 482 return it != presentation_frames_.end() | 472 return it != presentation_frames_.end() |
| 483 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 473 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); |
| 484 } | 474 } |
| 485 | 475 |
| 486 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | |
| 487 const RenderFrameHostId& render_frame_host_id) const { | |
| 488 const auto it = presentation_frames_.find(render_frame_host_id); | |
| 489 return it != presentation_frames_.end() ? it->second->GetRouteIds() | |
| 490 : std::vector<MediaRoute::Id>(); | |
| 491 } | |
| 492 | |
| 493 bool PresentationFrameManager::SetScreenAvailabilityListener( | 476 bool PresentationFrameManager::SetScreenAvailabilityListener( |
| 494 const RenderFrameHostId& render_frame_host_id, | 477 const RenderFrameHostId& render_frame_host_id, |
| 495 content::PresentationScreenAvailabilityListener* listener) { | 478 content::PresentationScreenAvailabilityListener* listener) { |
| 496 DCHECK(listener); | 479 DCHECK(listener); |
| 497 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 480 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 498 return presentation_frame->SetScreenAvailabilityListener(listener); | 481 return presentation_frame->SetScreenAvailabilityListener(listener); |
| 499 } | 482 } |
| 500 | 483 |
| 501 bool PresentationFrameManager::RemoveScreenAvailabilityListener( | 484 bool PresentationFrameManager::RemoveScreenAvailabilityListener( |
| 502 const RenderFrameHostId& render_frame_host_id, | 485 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 const base::ListValue* origins = | 969 const base::ListValue* origins = |
| 987 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 970 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 988 ->GetPrefs() | 971 ->GetPrefs() |
| 989 ->GetList(prefs::kMediaRouterTabMirroringSources); | 972 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 990 return origins && | 973 return origins && |
| 991 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 974 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 992 } | 975 } |
| 993 #endif // !defined(OS_ANDROID) | 976 #endif // !defined(OS_ANDROID) |
| 994 | 977 |
| 995 } // namespace media_router | 978 } // namespace media_router |
| OLD | NEW |