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> |
| 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/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/media/router/browser_presentation_connection_proxy.h" | |
| 17 #include "chrome/browser/media/router/create_presentation_connection_request.h" | 18 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
| 18 #include "chrome/browser/media/router/media_route.h" | 19 #include "chrome/browser/media/router/media_route.h" |
| 19 #include "chrome/browser/media/router/media_router.h" | 20 #include "chrome/browser/media/router/media_router.h" |
| 20 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 21 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 21 #include "chrome/browser/media/router/media_router_factory.h" | 22 #include "chrome/browser/media/router/media_router_factory.h" |
| 22 #include "chrome/browser/media/router/media_sink.h" | 23 #include "chrome/browser/media/router/media_sink.h" |
| 23 #include "chrome/browser/media/router/media_source_helper.h" | 24 #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.h" |
| 25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | 26 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 27 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 141 |
| 141 void Reset(); | 142 void Reset(); |
| 142 void RemoveConnection(const std::string& presentation_id, | 143 void RemoveConnection(const std::string& presentation_id, |
| 143 const MediaRoute::Id& route_id); | 144 const MediaRoute::Id& route_id); |
| 144 | 145 |
| 145 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 146 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 146 const std::vector<MediaRoute::Id> GetRouteIds() const; | 147 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 147 | 148 |
| 148 void OnPresentationSessionStarted( | 149 void OnPresentationSessionStarted( |
| 149 const content::PresentationSessionInfo& session, | 150 const content::PresentationSessionInfo& session, |
| 150 const MediaRoute::Id& route_id); | 151 const MediaRoute& route); |
| 152 | |
| 153 bool IsOffscreenPresentation(const std::string& presentation_id); | |
| 154 void OnBrowserConnectionAvailable( | |
| 155 const content::PresentationSessionInfo& session, | |
| 156 content::PresentationConnectionPtr controller); | |
| 151 | 157 |
| 152 private: | 158 private: |
| 153 MediaSource GetMediaSourceFromListener( | 159 MediaSource GetMediaSourceFromListener( |
| 154 content::PresentationScreenAvailabilityListener* listener) const; | 160 content::PresentationScreenAvailabilityListener* listener) const; |
| 155 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 161 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; |
| 156 presentation_id_to_route_id_; | |
| 157 base::SmallMap< | 162 base::SmallMap< |
| 158 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 163 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
| 159 url_to_sinks_observer_; | 164 url_to_sinks_observer_; |
| 160 std::unordered_map< | 165 std::unordered_map< |
| 161 MediaRoute::Id, | 166 MediaRoute::Id, |
| 162 std::unique_ptr<PresentationConnectionStateSubscription>> | 167 std::unique_ptr<PresentationConnectionStateSubscription>> |
| 163 connection_state_subscriptions_; | 168 connection_state_subscriptions_; |
| 164 std::unordered_map< | 169 std::unordered_map< |
| 165 MediaRoute::Id, | 170 MediaRoute::Id, |
| 166 std::unique_ptr<PresentationSessionMessagesObserver>> | 171 std::unique_ptr<PresentationSessionMessagesObserver>> |
| 167 session_messages_observers_; | 172 session_messages_observers_; |
| 173 std::set<std::unique_ptr<BrowserPresentationConnectionProxy>> | |
| 174 browser_connection_proxies_; | |
| 168 | 175 |
| 169 RenderFrameHostId render_frame_host_id_; | 176 RenderFrameHostId render_frame_host_id_; |
| 170 | 177 |
| 171 // References to the owning WebContents, and the corresponding MediaRouter. | 178 // References to the owning WebContents, and the corresponding MediaRouter. |
| 172 const content::WebContents* web_contents_; | 179 content::WebContents* web_contents_; |
| 173 MediaRouter* router_; | 180 MediaRouter* router_; |
| 174 }; | 181 }; |
| 175 | 182 |
| 176 PresentationFrame::PresentationFrame( | 183 PresentationFrame::PresentationFrame( |
| 177 const RenderFrameHostId& render_frame_host_id, | 184 const RenderFrameHostId& render_frame_host_id, |
| 178 content::WebContents* web_contents, | 185 content::WebContents* web_contents, |
| 179 MediaRouter* router) | 186 MediaRouter* router) |
| 180 : render_frame_host_id_(render_frame_host_id), | 187 : render_frame_host_id_(render_frame_host_id), |
| 181 web_contents_(web_contents), | 188 web_contents_(web_contents), |
| 182 router_(router) { | 189 router_(router) { |
| 183 DCHECK(web_contents_); | 190 DCHECK(web_contents_); |
| 184 DCHECK(router_); | 191 DCHECK(router_); |
| 185 } | 192 } |
| 186 | 193 |
| 187 PresentationFrame::~PresentationFrame() { | 194 PresentationFrame::~PresentationFrame() { |
| 188 } | 195 } |
| 189 | 196 |
| 190 void PresentationFrame::OnPresentationSessionStarted( | 197 void PresentationFrame::OnPresentationSessionStarted( |
| 191 const content::PresentationSessionInfo& session, | 198 const content::PresentationSessionInfo& session, |
| 192 const MediaRoute::Id& route_id) { | 199 const MediaRoute& route) { |
| 193 presentation_id_to_route_id_[session.presentation_id] = route_id; | 200 presentation_id_to_route_.insert( |
| 201 std::make_pair(session.presentation_id, route)); | |
| 194 } | 202 } |
| 195 | 203 |
| 196 const MediaRoute::Id PresentationFrame::GetRouteId( | 204 const MediaRoute::Id PresentationFrame::GetRouteId( |
| 197 const std::string& presentation_id) const { | 205 const std::string& presentation_id) const { |
| 198 auto it = presentation_id_to_route_id_.find(presentation_id); | 206 auto it = presentation_id_to_route_.find(presentation_id); |
| 199 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 207 return it != presentation_id_to_route_.end() ? it->second.media_route_id() |
| 208 : ""; | |
| 200 } | 209 } |
| 201 | 210 |
| 202 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | 211 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { |
| 203 std::vector<MediaRoute::Id> route_ids; | 212 std::vector<MediaRoute::Id> route_ids; |
| 204 for (const auto& e : presentation_id_to_route_id_) | 213 for (const auto& e : presentation_id_to_route_) |
| 205 route_ids.push_back(e.second); | 214 route_ids.push_back(e.second.media_route_id()); |
| 206 return route_ids; | 215 return route_ids; |
| 207 } | 216 } |
| 208 | 217 |
| 209 bool PresentationFrame::SetScreenAvailabilityListener( | 218 bool PresentationFrame::SetScreenAvailabilityListener( |
| 210 content::PresentationScreenAvailabilityListener* listener) { | 219 content::PresentationScreenAvailabilityListener* listener) { |
| 211 MediaSource source(GetMediaSourceFromListener(listener)); | 220 MediaSource source(GetMediaSourceFromListener(listener)); |
| 212 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 221 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
| 213 if (sinks_observer && sinks_observer->listener() == listener) | 222 if (sinks_observer && sinks_observer->listener() == listener) |
| 214 return false; | 223 return false; |
| 215 | 224 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 237 } | 246 } |
| 238 return false; | 247 return false; |
| 239 } | 248 } |
| 240 | 249 |
| 241 bool PresentationFrame::HasScreenAvailabilityListenerForTest( | 250 bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
| 242 const MediaSource::Id& source_id) const { | 251 const MediaSource::Id& source_id) const { |
| 243 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); | 252 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); |
| 244 } | 253 } |
| 245 | 254 |
| 246 void PresentationFrame::Reset() { | 255 void PresentationFrame::Reset() { |
| 247 for (const auto& pid_route_id : presentation_id_to_route_id_) | 256 auto offscreen_presentation_manager = OffscreenPresentationManagerFactory:: |
| 248 router_->DetachRoute(pid_route_id.second); | 257 GetOrCreateForControllerBrowserContext(web_contents_); |
| 249 | 258 |
| 250 presentation_id_to_route_id_.clear(); | 259 for (const auto& pid_route : presentation_id_to_route_) { |
| 260 offscreen_presentation_manager->UnregisterOffscreenPresentationController( | |
| 261 pid_route.first, render_frame_host_id_); | |
| 262 router_->DetachRoute(pid_route.second.media_route_id()); | |
| 263 } | |
| 264 | |
| 265 presentation_id_to_route_.clear(); | |
| 251 url_to_sinks_observer_.clear(); | 266 url_to_sinks_observer_.clear(); |
| 252 connection_state_subscriptions_.clear(); | 267 connection_state_subscriptions_.clear(); |
| 253 session_messages_observers_.clear(); | 268 session_messages_observers_.clear(); |
| 254 } | 269 } |
| 255 | 270 |
| 256 void PresentationFrame::RemoveConnection(const std::string& presentation_id, | 271 void PresentationFrame::RemoveConnection(const std::string& presentation_id, |
| 257 const MediaRoute::Id& route_id) { | 272 const MediaRoute::Id& route_id) { |
| 258 // Remove the presentation id mapping so a later call to Reset is a no-op. | 273 // Remove the presentation id mapping so a later call to Reset is a no-op. |
| 259 presentation_id_to_route_id_.erase(presentation_id); | 274 presentation_id_to_route_.erase(presentation_id); |
| 260 | 275 |
| 261 // We no longer need to observe route messages. | 276 // We no longer need to observe route messages. |
| 262 session_messages_observers_.erase(route_id); | 277 session_messages_observers_.erase(route_id); |
| 263 | 278 |
| 264 // We keep the PresentationConnectionStateChangedCallback registered with MR | 279 // We keep the PresentationConnectionStateChangedCallback registered with MR |
| 265 // so the MRP can tell us when terminate() completed. | 280 // so the MRP can tell us when terminate() completed. |
| 266 } | 281 } |
| 267 | 282 |
| 268 void PresentationFrame::ListenForConnectionStateChange( | 283 void PresentationFrame::ListenForConnectionStateChange( |
| 269 const content::PresentationSessionInfo& connection, | 284 const content::PresentationSessionInfo& connection, |
| 270 const content::PresentationConnectionStateChangedCallback& | 285 const content::PresentationConnectionStateChangedCallback& |
| 271 state_changed_cb) { | 286 state_changed_cb) { |
| 272 auto it = presentation_id_to_route_id_.find(connection.presentation_id); | 287 auto it = presentation_id_to_route_.find(connection.presentation_id); |
| 273 if (it == presentation_id_to_route_id_.end()) { | 288 if (it == presentation_id_to_route_.end()) { |
| 274 DLOG(ERROR) << __func__ << "route id not found for presentation: " | 289 DLOG(ERROR) << __func__ << "route id not found for presentation: " |
| 275 << connection.presentation_id; | 290 << connection.presentation_id; |
| 276 return; | 291 return; |
| 277 } | 292 } |
| 278 | 293 |
| 279 const MediaRoute::Id& route_id = it->second; | 294 const MediaRoute::Id& route_id = it->second.media_route_id(); |
| 280 if (connection_state_subscriptions_.find(route_id) != | 295 if (connection_state_subscriptions_.find(route_id) != |
| 281 connection_state_subscriptions_.end()) { | 296 connection_state_subscriptions_.end()) { |
| 282 DLOG(ERROR) << __func__ | 297 DLOG(ERROR) << __func__ |
| 283 << "Already listening connection state change for route: " | 298 << "Already listening connection state change for route: " |
| 284 << route_id; | 299 << route_id; |
| 285 return; | 300 return; |
| 286 } | 301 } |
| 287 | 302 |
| 288 connection_state_subscriptions_.insert(std::make_pair( | 303 connection_state_subscriptions_.insert(std::make_pair( |
| 289 route_id, router_->AddPresentationConnectionStateChangedCallback( | 304 route_id, router_->AddPresentationConnectionStateChangedCallback( |
| 290 it->second, state_changed_cb))); | 305 route_id, state_changed_cb))); |
| 291 } | 306 } |
| 292 | 307 |
| 293 void PresentationFrame::ListenForSessionMessages( | 308 void PresentationFrame::ListenForSessionMessages( |
| 294 const content::PresentationSessionInfo& session, | 309 const content::PresentationSessionInfo& session, |
| 295 const content::PresentationSessionMessageCallback& message_cb) { | 310 const content::PresentationSessionMessageCallback& message_cb) { |
| 296 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 311 auto it = presentation_id_to_route_.find(session.presentation_id); |
| 297 if (it == presentation_id_to_route_id_.end()) { | 312 if (it == presentation_id_to_route_.end()) { |
| 298 DVLOG(2) << "ListenForSessionMessages: no route for " | 313 DVLOG(2) << "ListenForSessionMessages: no route for " |
| 299 << session.presentation_id; | 314 << session.presentation_id; |
| 300 return; | 315 return; |
| 301 } | 316 } |
| 302 | 317 |
| 303 const MediaRoute::Id& route_id = it->second; | 318 if (it->second.is_offscreen_presentation()) { |
| 319 DVLOG(2) << "ListenForSessionMessages: do not listen for offscreen " | |
| 320 << "presentation [id]: " << session.presentation_id; | |
| 321 return; | |
| 322 } | |
| 323 | |
| 324 const MediaRoute::Id& route_id = it->second.media_route_id(); | |
| 304 if (session_messages_observers_.find(route_id) != | 325 if (session_messages_observers_.find(route_id) != |
| 305 session_messages_observers_.end()) { | 326 session_messages_observers_.end()) { |
| 306 DLOG(ERROR) << __func__ | 327 DLOG(ERROR) << __func__ |
| 307 << "Already listening for session messages for route: " | 328 << "Already listening for session messages for route: " |
| 308 << route_id; | 329 << route_id; |
| 309 return; | 330 return; |
| 310 } | 331 } |
| 311 | 332 |
| 312 session_messages_observers_.insert(std::make_pair( | 333 session_messages_observers_.insert(std::make_pair( |
|
imcheng
2016/11/29 00:33:22
It looks like we should be able to invoke one of t
zhaobin
2017/01/13 00:05:49
Yes, we can do a lot of refactoring after introduc
| |
| 313 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( | 334 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( |
| 314 router_, it->second, message_cb))); | 335 router_, route_id, message_cb))); |
| 315 } | 336 } |
| 316 | 337 |
| 317 MediaSource PresentationFrame::GetMediaSourceFromListener( | 338 MediaSource PresentationFrame::GetMediaSourceFromListener( |
| 318 content::PresentationScreenAvailabilityListener* listener) const { | 339 content::PresentationScreenAvailabilityListener* listener) const { |
| 319 // If the default presentation URL is empty then fall back to tab mirroring. | 340 // If the default presentation URL is empty then fall back to tab mirroring. |
| 320 return listener->GetAvailabilityUrl().is_empty() | 341 return listener->GetAvailabilityUrl().is_empty() |
| 321 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 342 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
| 322 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); | 343 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); |
| 323 } | 344 } |
| 324 | 345 |
| 346 bool PresentationFrame::IsOffscreenPresentation( | |
| 347 const std::string& presentation_id) { | |
| 348 DCHECK(base::ContainsKey(presentation_id_to_route_, presentation_id)); | |
| 349 auto it = presentation_id_to_route_.find(presentation_id); | |
| 350 return it->second.is_offscreen_presentation(); | |
| 351 } | |
| 352 | |
| 353 void PresentationFrame::OnBrowserConnectionAvailable( | |
| 354 const content::PresentationSessionInfo& session, | |
| 355 content::PresentationConnectionPtr controller) { | |
| 356 DCHECK(controller); | |
| 357 DCHECK(base::ContainsKey(presentation_id_to_route_, session.presentation_id)); | |
| 358 auto it = presentation_id_to_route_.find(session.presentation_id); | |
| 359 | |
| 360 std::unique_ptr<BrowserPresentationConnectionProxy> proxy = | |
| 361 base::MakeUnique<BrowserPresentationConnectionProxy>(session, router_, | |
| 362 &it->second); | |
| 363 controller->SetTargetConnection(proxy->Bind()); | |
| 364 proxy->SetTargetConnection(std::move(controller)); | |
| 365 | |
| 366 browser_connection_proxies_.insert(std::move(proxy)); | |
| 367 } | |
| 368 | |
| 325 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 369 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
| 326 class PresentationFrameManager { | 370 class PresentationFrameManager { |
| 327 public: | 371 public: |
| 328 PresentationFrameManager(content::WebContents* web_contents, | 372 PresentationFrameManager(content::WebContents* web_contents, |
| 329 MediaRouter* router); | 373 MediaRouter* router); |
| 330 ~PresentationFrameManager(); | 374 ~PresentationFrameManager(); |
| 331 | 375 |
| 332 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 376 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 333 bool SetScreenAvailabilityListener( | 377 bool SetScreenAvailabilityListener( |
| 334 const RenderFrameHostId& render_frame_host_id, | 378 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 const MediaRoute::Id& route_id, | 411 const MediaRoute::Id& route_id, |
| 368 const std::string& presentation_id); | 412 const std::string& presentation_id); |
| 369 bool HasScreenAvailabilityListenerForTest( | 413 bool HasScreenAvailabilityListenerForTest( |
| 370 const RenderFrameHostId& render_frame_host_id, | 414 const RenderFrameHostId& render_frame_host_id, |
| 371 const MediaSource::Id& source_id) const; | 415 const MediaSource::Id& source_id) const; |
| 372 void SetMediaRouterForTest(MediaRouter* router); | 416 void SetMediaRouterForTest(MediaRouter* router); |
| 373 | 417 |
| 374 void OnPresentationSessionStarted( | 418 void OnPresentationSessionStarted( |
| 375 const RenderFrameHostId& render_frame_host_id, | 419 const RenderFrameHostId& render_frame_host_id, |
| 376 const content::PresentationSessionInfo& session, | 420 const content::PresentationSessionInfo& session, |
| 377 const MediaRoute::Id& route_id); | 421 const MediaRoute& route); |
| 378 void OnDefaultPresentationSessionStarted( | 422 void OnDefaultPresentationSessionStarted( |
| 379 const PresentationRequest& request, | 423 const PresentationRequest& request, |
| 380 const content::PresentationSessionInfo& session, | 424 const content::PresentationSessionInfo& session, |
| 381 const MediaRoute::Id& route_id); | 425 const MediaRoute& route); |
| 426 | |
| 427 bool IsOffscreenPresentation(const RenderFrameHostId& render_frame_host_id, | |
| 428 const std::string& presentation_id); | |
| 429 void OnBrowserConnectionAvailable( | |
| 430 const RenderFrameHostId& render_frame_host_id, | |
| 431 const content::PresentationSessionInfo& session, | |
| 432 content::PresentationConnectionPtr controller); | |
| 382 | 433 |
| 383 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 434 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 384 const std::string& presentation_id) const; | 435 const std::string& presentation_id) const; |
| 385 const std::vector<MediaRoute::Id> GetRouteIds( | 436 const std::vector<MediaRoute::Id> GetRouteIds( |
| 386 const RenderFrameHostId& render_frame_host_id) const; | 437 const RenderFrameHostId& render_frame_host_id) const; |
| 387 | 438 |
| 388 const PresentationRequest* default_presentation_request() const { | 439 const PresentationRequest* default_presentation_request() const { |
| 389 return default_presentation_request_.get(); | 440 return default_presentation_request_.get(); |
| 390 } | 441 } |
| 391 | 442 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 : router_(router), web_contents_(web_contents) { | 486 : router_(router), web_contents_(web_contents) { |
| 436 DCHECK(web_contents_); | 487 DCHECK(web_contents_); |
| 437 DCHECK(router_); | 488 DCHECK(router_); |
| 438 } | 489 } |
| 439 | 490 |
| 440 PresentationFrameManager::~PresentationFrameManager() {} | 491 PresentationFrameManager::~PresentationFrameManager() {} |
| 441 | 492 |
| 442 void PresentationFrameManager::OnPresentationSessionStarted( | 493 void PresentationFrameManager::OnPresentationSessionStarted( |
| 443 const RenderFrameHostId& render_frame_host_id, | 494 const RenderFrameHostId& render_frame_host_id, |
| 444 const content::PresentationSessionInfo& session, | 495 const content::PresentationSessionInfo& session, |
| 445 const MediaRoute::Id& route_id) { | 496 const MediaRoute& route) { |
| 446 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 497 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 447 presentation_frame->OnPresentationSessionStarted(session, route_id); | 498 presentation_frame->OnPresentationSessionStarted(session, route); |
| 448 } | 499 } |
| 449 | 500 |
| 450 void PresentationFrameManager::OnDefaultPresentationSessionStarted( | 501 void PresentationFrameManager::OnDefaultPresentationSessionStarted( |
| 451 const PresentationRequest& request, | 502 const PresentationRequest& request, |
| 452 const content::PresentationSessionInfo& session, | 503 const content::PresentationSessionInfo& session, |
| 453 const MediaRoute::Id& route_id) { | 504 const MediaRoute& route) { |
| 454 const auto it = presentation_frames_.find(request.render_frame_host_id()); | 505 const auto it = presentation_frames_.find(request.render_frame_host_id()); |
| 455 if (it != presentation_frames_.end()) | 506 if (it != presentation_frames_.end()) |
| 456 it->second->OnPresentationSessionStarted(session, route_id); | 507 it->second->OnPresentationSessionStarted(session, route); |
| 457 | 508 |
| 458 if (default_presentation_request_ && | 509 if (default_presentation_request_ && |
| 459 default_presentation_request_->Equals(request)) { | 510 default_presentation_request_->Equals(request)) { |
| 460 default_presentation_started_callback_.Run(session); | 511 default_presentation_started_callback_.Run(session); |
| 461 } | 512 } |
| 462 } | 513 } |
| 463 | 514 |
| 515 bool PresentationFrameManager::IsOffscreenPresentation( | |
| 516 const RenderFrameHostId& render_frame_host_id, | |
| 517 const std::string& presentation_id) { | |
| 518 const auto it = presentation_frames_.find(render_frame_host_id); | |
| 519 if (it != presentation_frames_.end()) | |
| 520 return it->second->IsOffscreenPresentation(presentation_id); | |
| 521 return false; | |
| 522 } | |
| 523 | |
| 524 void PresentationFrameManager::OnBrowserConnectionAvailable( | |
| 525 const RenderFrameHostId& render_frame_host_id, | |
| 526 const content::PresentationSessionInfo& session, | |
| 527 content::PresentationConnectionPtr controller) { | |
| 528 const auto it = presentation_frames_.find(render_frame_host_id); | |
| 529 if (it != presentation_frames_.end()) | |
| 530 return it->second->OnBrowserConnectionAvailable(session, | |
| 531 std::move(controller)); | |
| 532 } | |
| 533 | |
| 464 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 534 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 465 const RenderFrameHostId& render_frame_host_id, | 535 const RenderFrameHostId& render_frame_host_id, |
| 466 const std::string& presentation_id) const { | 536 const std::string& presentation_id) const { |
| 467 const auto it = presentation_frames_.find(render_frame_host_id); | 537 const auto it = presentation_frames_.find(render_frame_host_id); |
| 468 return it != presentation_frames_.end() | 538 return it != presentation_frames_.end() |
| 469 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 539 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); |
| 470 } | 540 } |
| 471 | 541 |
| 472 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | 542 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( |
| 473 const RenderFrameHostId& render_frame_host_id) const { | 543 const RenderFrameHostId& render_frame_host_id) const { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 DVLOG(1) << "OnJoinRouteResponse: " | 783 DVLOG(1) << "OnJoinRouteResponse: " |
| 714 << "route_id: " << result.route()->media_route_id() | 784 << "route_id: " << result.route()->media_route_id() |
| 715 << ", presentation URL: " << presentation_url | 785 << ", presentation URL: " << presentation_url |
| 716 << ", presentation ID: " << presentation_id; | 786 << ", presentation ID: " << presentation_id; |
| 717 DCHECK_EQ(presentation_id, result.presentation_id()); | 787 DCHECK_EQ(presentation_id, result.presentation_id()); |
| 718 content::PresentationSessionInfo session( | 788 content::PresentationSessionInfo session( |
| 719 presentation_url, result.presentation_id(), | 789 presentation_url, result.presentation_id(), |
| 720 result.route()->is_offscreen_presentation()); | 790 result.route()->is_offscreen_presentation()); |
| 721 frame_manager_->OnPresentationSessionStarted( | 791 frame_manager_->OnPresentationSessionStarted( |
| 722 RenderFrameHostId(render_process_id, render_frame_id), session, | 792 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 723 result.route()->media_route_id()); | 793 *result.route()); |
| 724 success_cb.Run(session); | 794 success_cb.Run(session); |
| 725 } | 795 } |
| 726 } | 796 } |
| 727 | 797 |
| 728 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 798 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
| 729 int render_process_id, | 799 int render_process_id, |
| 730 int render_frame_id, | 800 int render_frame_id, |
| 731 const content::PresentationSessionStartedCallback& success_cb, | 801 const content::PresentationSessionStartedCallback& success_cb, |
| 732 const content::PresentationSessionInfo& new_session, | 802 const content::PresentationSessionInfo& new_session, |
| 733 const MediaRoute& route) { | 803 const MediaRoute& route) { |
| 734 const MediaRoute::Id& route_id = route.media_route_id(); | 804 const MediaRoute::Id& route_id = route.media_route_id(); |
| 735 DVLOG(1) << "OnStartSessionSucceeded: " | 805 DVLOG(1) << "OnStartSessionSucceeded: " |
| 736 << "route_id: " << route_id | 806 << "route_id: " << route_id |
| 737 << ", presentation URL: " << new_session.presentation_url | 807 << ", presentation URL: " << new_session.presentation_url |
| 738 << ", presentation ID: " << new_session.presentation_id | 808 << ", presentation ID: " << new_session.presentation_id |
| 739 << ", is_offscreen_presentation: " << new_session.is_offscreen; | 809 << ", is_offscreen_presentation: " << new_session.is_offscreen; |
| 740 frame_manager_->OnPresentationSessionStarted( | 810 frame_manager_->OnPresentationSessionStarted( |
| 741 RenderFrameHostId(render_process_id, render_frame_id), new_session, | 811 RenderFrameHostId(render_process_id, render_frame_id), new_session, |
| 742 route_id); | 812 route); |
| 743 success_cb.Run(new_session); | 813 success_cb.Run(new_session); |
| 744 } | 814 } |
| 745 | 815 |
| 746 void PresentationServiceDelegateImpl::StartSession( | 816 void PresentationServiceDelegateImpl::StartSession( |
| 747 int render_process_id, | 817 int render_process_id, |
| 748 int render_frame_id, | 818 int render_frame_id, |
| 749 const std::vector<GURL>& presentation_urls, | 819 const std::vector<GURL>& presentation_urls, |
| 750 const content::PresentationSessionStartedCallback& success_cb, | 820 const content::PresentationSessionStartedCallback& success_cb, |
| 751 const content::PresentationSessionErrorCallback& error_cb) { | 821 const content::PresentationSessionErrorCallback& error_cb) { |
| 752 if (presentation_urls.empty()) { | 822 if (presentation_urls.empty()) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 int render_process_id, | 953 int render_process_id, |
| 884 int render_frame_id, | 954 int render_frame_id, |
| 885 const content::PresentationSessionInfo& connection, | 955 const content::PresentationSessionInfo& connection, |
| 886 const content::PresentationConnectionStateChangedCallback& | 956 const content::PresentationConnectionStateChangedCallback& |
| 887 state_changed_cb) { | 957 state_changed_cb) { |
| 888 frame_manager_->ListenForConnectionStateChange( | 958 frame_manager_->ListenForConnectionStateChange( |
| 889 RenderFrameHostId(render_process_id, render_frame_id), connection, | 959 RenderFrameHostId(render_process_id, render_frame_id), connection, |
| 890 state_changed_cb); | 960 state_changed_cb); |
| 891 } | 961 } |
| 892 | 962 |
| 893 void PresentationServiceDelegateImpl::ConnectToOffscreenPresentation( | 963 void PresentationServiceDelegateImpl::ConnectToPresentation( |
| 894 int render_process_id, | 964 int render_process_id, |
| 895 int render_frame_id, | 965 int render_frame_id, |
| 896 const content::PresentationSessionInfo& session, | 966 const content::PresentationSessionInfo& session, |
| 897 content::PresentationConnectionPtr connection) { | 967 content::PresentationConnectionPtr connection) { |
| 898 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 968 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 899 auto* const offscreen_presentation_manager = | 969 |
| 900 OffscreenPresentationManagerFactory:: | 970 if (frame_manager_->IsOffscreenPresentation(render_frame_host_id, |
| 901 GetOrCreateForControllerBrowserContext(web_contents_); | 971 session.presentation_id)) { |
| 902 offscreen_presentation_manager->RegisterOffscreenPresentationController( | 972 auto* const offscreen_presentation_manager = |
| 903 session.presentation_id, session.presentation_url, render_frame_host_id, | 973 OffscreenPresentationManagerFactory:: |
| 904 std::move(connection)); | 974 GetOrCreateForControllerBrowserContext(web_contents_); |
| 975 offscreen_presentation_manager->RegisterOffscreenPresentationController( | |
| 976 session.presentation_id, session.presentation_url, render_frame_host_id, | |
| 977 std::move(connection)); | |
| 978 } else { | |
| 979 frame_manager_->OnBrowserConnectionAvailable(render_frame_host_id, session, | |
| 980 std::move(connection)); | |
| 981 } | |
| 905 } | 982 } |
| 906 | 983 |
| 907 void PresentationServiceDelegateImpl::OnRouteResponse( | 984 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 908 const PresentationRequest& presentation_request, | 985 const PresentationRequest& presentation_request, |
| 909 const RouteRequestResult& result) { | 986 const RouteRequestResult& result) { |
| 910 if (!result.route()) | 987 if (!result.route()) |
| 911 return; | 988 return; |
| 912 | 989 |
| 913 content::PresentationSessionInfo session_info( | 990 content::PresentationSessionInfo session_info( |
| 914 presentation_request.presentation_url(), result.presentation_id(), | 991 presentation_request.presentation_url(), result.presentation_id(), |
| 915 result.route()->is_offscreen_presentation()); | 992 result.route()->is_offscreen_presentation()); |
| 916 frame_manager_->OnDefaultPresentationSessionStarted( | 993 frame_manager_->OnDefaultPresentationSessionStarted( |
| 917 presentation_request, session_info, result.route()->media_route_id()); | 994 presentation_request, session_info, *result.route()); |
| 918 } | 995 } |
| 919 | 996 |
| 920 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( | 997 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( |
| 921 DefaultPresentationRequestObserver* observer) { | 998 DefaultPresentationRequestObserver* observer) { |
| 922 frame_manager_->AddDefaultPresentationRequestObserver(observer); | 999 frame_manager_->AddDefaultPresentationRequestObserver(observer); |
| 923 } | 1000 } |
| 924 | 1001 |
| 925 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( | 1002 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( |
| 926 DefaultPresentationRequestObserver* observer) { | 1003 DefaultPresentationRequestObserver* observer) { |
| 927 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); | 1004 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 951 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 1028 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 952 int render_process_id, | 1029 int render_process_id, |
| 953 int render_frame_id, | 1030 int render_frame_id, |
| 954 const MediaSource::Id& source_id) const { | 1031 const MediaSource::Id& source_id) const { |
| 955 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 1032 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 956 return frame_manager_->HasScreenAvailabilityListenerForTest( | 1033 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 957 render_frame_host_id, source_id); | 1034 render_frame_host_id, source_id); |
| 958 } | 1035 } |
| 959 | 1036 |
| 960 } // namespace media_router | 1037 } // namespace media_router |
| OLD | NEW |