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 | 8 |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/containers/small_map.h" | 10 #include "base/containers/small_map.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/media/router/create_presentation_session_request.h" | 14 #include "chrome/browser/media/router/create_presentation_session_request.h" |
| 15 #include "chrome/browser/media/router/media_route.h" | 15 #include "chrome/browser/media/router/media_route.h" |
| 16 #include "chrome/browser/media/router/media_router.h" | 16 #include "chrome/browser/media/router/media_router.h" |
| 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_sink.h" | 19 #include "chrome/browser/media/router/media_sink.h" |
| 20 #include "chrome/browser/media/router/media_source_helper.h" | 20 #include "chrome/browser/media/router/media_source_helper.h" |
| 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | |
| 22 #include "chrome/browser/media/router/presentation_session_state_observer.h" | 23 #include "chrome/browser/media/router/presentation_session_state_observer.h" |
| 23 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
| 24 #include "content/public/browser/presentation_screen_availability_listener.h" | 25 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 25 #include "content/public/browser/presentation_session.h" | 26 #include "content/public/browser/presentation_session.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 28 | 29 |
| 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 30 media_router::PresentationServiceDelegateImpl); | 31 media_router::PresentationServiceDelegateImpl); |
| 31 | 32 |
| 32 using content::RenderFrameHost; | 33 using content::RenderFrameHost; |
| 33 | 34 |
| 34 namespace media_router { | 35 namespace media_router { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 39 using DelegateObserver = content::PresentationServiceDelegate::Observer; |
| 39 using PresentationSessionErrorCallback = | 40 using PresentationSessionErrorCallback = |
| 40 content::PresentationServiceDelegate::PresentationSessionErrorCallback; | 41 content::PresentationServiceDelegate::PresentationSessionErrorCallback; |
| 41 using PresentationSessionSuccessCallback = | 42 using PresentationSessionSuccessCallback = |
| 42 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; | 43 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; |
| 44 | |
| 43 using RenderFrameHostId = std::pair<int, int>; | 45 using RenderFrameHostId = std::pair<int, int>; |
| 44 | 46 |
| 45 // Returns the unique identifier for the supplied RenderFrameHost. | 47 // Returns the unique identifier for the supplied RenderFrameHost. |
| 46 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | 48 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { |
| 47 int render_process_id = render_frame_host->GetProcess()->GetID(); | 49 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 48 int render_frame_id = render_frame_host->GetRoutingID(); | 50 int render_frame_id = render_frame_host->GetRoutingID(); |
| 49 return RenderFrameHostId(render_process_id, render_frame_id); | 51 return RenderFrameHostId(render_process_id, render_frame_id); |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Gets the last committed URL for the render frame specified by | 54 // Gets the last committed URL for the render frame specified by |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 74 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 76 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 75 bool SetScreenAvailabilityListener( | 77 bool SetScreenAvailabilityListener( |
| 76 content::PresentationScreenAvailabilityListener* listener); | 78 content::PresentationScreenAvailabilityListener* listener); |
| 77 bool RemoveScreenAvailabilityListener( | 79 bool RemoveScreenAvailabilityListener( |
| 78 content::PresentationScreenAvailabilityListener* listener); | 80 content::PresentationScreenAvailabilityListener* listener); |
| 79 bool HasScreenAvailabilityListenerForTest( | 81 bool HasScreenAvailabilityListenerForTest( |
| 80 const MediaSource::Id& source_id) const; | 82 const MediaSource::Id& source_id) const; |
| 81 std::string GetDefaultPresentationId() const; | 83 std::string GetDefaultPresentationId() const; |
| 82 void ListenForSessionStateChange( | 84 void ListenForSessionStateChange( |
| 83 const content::SessionStateChangedCallback& state_changed_cb); | 85 const content::SessionStateChangedCallback& state_changed_cb); |
| 86 void ListenForSessionMessages( | |
| 87 const content::PresentationSessionInfo& session, | |
| 88 const content::PresentationSessionMessageCallback& message_cb); | |
| 84 void Reset(); | 89 void Reset(); |
| 85 | 90 |
| 86 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 91 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 87 const std::vector<MediaRoute::Id> GetRouteIds() const; | 92 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 88 void OnPresentationSessionClosed(const std::string& presentation_id); | 93 void OnPresentationSessionClosed(const std::string& presentation_id); |
| 89 | 94 |
| 90 void OnPresentationSessionStarted( | 95 void OnPresentationSessionStarted( |
| 91 bool is_default_presentation, | 96 bool is_default_presentation, |
| 92 const content::PresentationSessionInfo& session, | 97 const content::PresentationSessionInfo& session, |
| 93 const MediaRoute::Id& route_id); | 98 const MediaRoute::Id& route_id); |
| 94 void OnPresentationServiceDelegateDestroyed() const; | 99 void OnPresentationServiceDelegateDestroyed() const; |
| 95 | 100 |
| 96 void set_delegate_observer(DelegateObserver* observer) { | 101 void set_delegate_observer(DelegateObserver* observer) { |
| 97 delegate_observer_ = observer; | 102 delegate_observer_ = observer; |
| 98 } | 103 } |
| 99 | 104 |
| 100 void set_default_presentation_url(const std::string& url) { | 105 void set_default_presentation_url(const std::string& url) { |
| 101 default_presentation_url_ = url; | 106 default_presentation_url_ = url; |
| 102 } | 107 } |
| 103 | 108 |
| 104 private: | 109 private: |
| 105 MediaSource GetMediaSourceFromListener( | 110 MediaSource GetMediaSourceFromListener( |
| 106 content::PresentationScreenAvailabilityListener* listener) const; | 111 content::PresentationScreenAvailabilityListener* listener) const; |
| 107 MediaRouteIdToPresentationSessionMapping route_id_to_presentation_; | 112 MediaRouteIdToPresentationSessionMapping route_id_to_presentation_; |
| 108 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 113 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| 109 presentation_id_to_route_id_; | 114 presentation_id_to_route_id_; |
| 110 std::string default_presentation_url_; | 115 std::string default_presentation_url_; |
| 111 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; | 116 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; |
| 112 scoped_ptr<PresentationSessionStateObserver> session_state_observer_; | 117 scoped_ptr<PresentationSessionStateObserver> session_state_observer_; |
| 118 ScopedVector<PresentationSessionMessagesObserver> session_messages_observers_; | |
| 113 | 119 |
| 114 // References to the owning WebContents, and the corresponding MediaRouter. | 120 // References to the owning WebContents, and the corresponding MediaRouter. |
| 115 const content::WebContents* web_contents_; | 121 const content::WebContents* web_contents_; |
| 116 MediaRouter* router_; | 122 MediaRouter* router_; |
| 117 | 123 |
| 118 DelegateObserver* delegate_observer_; | 124 DelegateObserver* delegate_observer_; |
| 119 }; | 125 }; |
| 120 | 126 |
| 121 PresentationFrame::PresentationFrame(content::WebContents* web_contents, | 127 PresentationFrame::PresentationFrame(content::WebContents* web_contents, |
| 122 MediaRouter* router) | 128 MediaRouter* router) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 return sinks_observer_ && sinks_observer_->source().id() == source_id; | 201 return sinks_observer_ && sinks_observer_->source().id() == source_id; |
| 196 } | 202 } |
| 197 | 203 |
| 198 void PresentationFrame::Reset() { | 204 void PresentationFrame::Reset() { |
| 199 route_id_to_presentation_.Clear(); | 205 route_id_to_presentation_.Clear(); |
| 200 presentation_id_to_route_id_.clear(); | 206 presentation_id_to_route_id_.clear(); |
| 201 sinks_observer_.reset(); | 207 sinks_observer_.reset(); |
| 202 default_presentation_url_.clear(); | 208 default_presentation_url_.clear(); |
| 203 if (session_state_observer_) | 209 if (session_state_observer_) |
| 204 session_state_observer_->Reset(); | 210 session_state_observer_->Reset(); |
| 211 session_messages_observers_.clear(); | |
| 205 } | 212 } |
| 206 | 213 |
| 207 void PresentationFrame::ListenForSessionStateChange( | 214 void PresentationFrame::ListenForSessionStateChange( |
| 208 const content::SessionStateChangedCallback& state_changed_cb) { | 215 const content::SessionStateChangedCallback& state_changed_cb) { |
| 209 CHECK(!session_state_observer_.get()); | 216 CHECK(!session_state_observer_.get()); |
| 210 session_state_observer_.reset(new PresentationSessionStateObserver( | 217 session_state_observer_.reset(new PresentationSessionStateObserver( |
| 211 state_changed_cb, &route_id_to_presentation_, router_)); | 218 state_changed_cb, &route_id_to_presentation_, router_)); |
| 212 } | 219 } |
| 213 | 220 |
| 221 void PresentationFrame::ListenForSessionMessages( | |
| 222 const content::PresentationSessionInfo& session, | |
| 223 const content::PresentationSessionMessageCallback& message_cb) { | |
| 224 auto it = presentation_id_to_route_id_.find(session.presentation_id); | |
| 225 if (it == presentation_id_to_route_id_.end()) { | |
| 226 DVLOG(2) << "ListenForSessionMessages: no route for " | |
| 227 << session.presentation_id; | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 session_messages_observers_.push_back( | |
| 232 new PresentationSessionMessagesObserver(message_cb, it->second, router_)); | |
| 233 } | |
| 234 | |
| 214 MediaSource PresentationFrame::GetMediaSourceFromListener( | 235 MediaSource PresentationFrame::GetMediaSourceFromListener( |
| 215 content::PresentationScreenAvailabilityListener* listener) const { | 236 content::PresentationScreenAvailabilityListener* listener) const { |
| 216 // If the default presentation URL is empty then fall back to tab mirroring. | 237 // If the default presentation URL is empty then fall back to tab mirroring. |
| 217 std::string presentation_url(listener->GetPresentationUrl()); | 238 std::string presentation_url(listener->GetPresentationUrl()); |
| 218 return presentation_url.empty() | 239 return presentation_url.empty() |
| 219 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 240 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
| 220 : MediaSourceForPresentationUrl(presentation_url); | 241 : MediaSourceForPresentationUrl(presentation_url); |
| 221 } | 242 } |
| 222 | 243 |
| 223 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 244 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
| 224 class PresentationFrameManager { | 245 class PresentationFrameManager { |
| 225 public: | 246 public: |
| 226 PresentationFrameManager(content::WebContents* web_contents, | 247 PresentationFrameManager(content::WebContents* web_contents, |
| 227 MediaRouter* router); | 248 MediaRouter* router); |
| 228 ~PresentationFrameManager(); | 249 ~PresentationFrameManager(); |
| 229 | 250 |
| 230 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 251 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 231 bool SetScreenAvailabilityListener( | 252 bool SetScreenAvailabilityListener( |
| 232 const RenderFrameHostId& render_frame_host_id, | 253 const RenderFrameHostId& render_frame_host_id, |
| 233 content::PresentationScreenAvailabilityListener* listener); | 254 content::PresentationScreenAvailabilityListener* listener); |
| 234 bool RemoveScreenAvailabilityListener( | 255 bool RemoveScreenAvailabilityListener( |
| 235 const RenderFrameHostId& render_frame_host_id, | 256 const RenderFrameHostId& render_frame_host_id, |
| 236 content::PresentationScreenAvailabilityListener* listener); | 257 content::PresentationScreenAvailabilityListener* listener); |
| 237 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, | 258 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, |
| 238 const std::string& default_presentation_url); | 259 const std::string& default_presentation_url); |
| 239 void ListenForSessionStateChange( | 260 void ListenForSessionStateChange( |
| 240 const RenderFrameHostId& render_frame_host_id, | 261 const RenderFrameHostId& render_frame_host_id, |
| 241 const content::SessionStateChangedCallback& state_changed_cb); | 262 const content::SessionStateChangedCallback& state_changed_cb); |
| 263 void ListenForSessionMessages( | |
| 264 const RenderFrameHostId& render_frame_host_id, | |
| 265 const content::PresentationSessionInfo& session, | |
| 266 const content::PresentationSessionMessageCallback& message_cb); | |
| 242 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, | 267 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, |
| 243 DelegateObserver* observer); | 268 DelegateObserver* observer); |
| 244 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); | 269 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); |
| 245 void Reset(const RenderFrameHostId& render_frame_host_id); | 270 void Reset(const RenderFrameHostId& render_frame_host_id); |
| 246 bool HasScreenAvailabilityListenerForTest( | 271 bool HasScreenAvailabilityListenerForTest( |
| 247 const RenderFrameHostId& render_frame_host_id, | 272 const RenderFrameHostId& render_frame_host_id, |
| 248 const MediaSource::Id& source_id) const; | 273 const MediaSource::Id& source_id) const; |
| 249 void SetMediaRouterForTest(MediaRouter* router); | 274 void SetMediaRouterForTest(MediaRouter* router); |
| 250 | 275 |
| 251 void OnPresentationSessionStarted( | 276 void OnPresentationSessionStarted( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 } | 381 } |
| 357 | 382 |
| 358 void PresentationFrameManager::ListenForSessionStateChange( | 383 void PresentationFrameManager::ListenForSessionStateChange( |
| 359 const RenderFrameHostId& render_frame_host_id, | 384 const RenderFrameHostId& render_frame_host_id, |
| 360 const content::SessionStateChangedCallback& state_changed_cb) { | 385 const content::SessionStateChangedCallback& state_changed_cb) { |
| 361 PresentationFrame* presentation_frame = | 386 PresentationFrame* presentation_frame = |
| 362 GetOrAddPresentationFrame(render_frame_host_id); | 387 GetOrAddPresentationFrame(render_frame_host_id); |
| 363 presentation_frame->ListenForSessionStateChange(state_changed_cb); | 388 presentation_frame->ListenForSessionStateChange(state_changed_cb); |
| 364 } | 389 } |
| 365 | 390 |
| 391 void PresentationFrameManager::ListenForSessionMessages( | |
| 392 const RenderFrameHostId& render_frame_host_id, | |
| 393 const content::PresentationSessionInfo& session, | |
| 394 const content::PresentationSessionMessageCallback& message_cb) { | |
| 395 PresentationFrame* presentation_frame = | |
| 396 presentation_frames_.get(render_frame_host_id); | |
| 397 if (!presentation_frame) { | |
| 398 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " | |
| 399 << "for: (" << render_frame_host_id.first << ", " | |
| 400 << render_frame_host_id.second << ")"; | |
| 401 return; | |
| 402 } | |
| 403 presentation_frame->ListenForSessionMessages(session, message_cb); | |
| 404 } | |
| 405 | |
| 366 void PresentationFrameManager::AddDelegateObserver( | 406 void PresentationFrameManager::AddDelegateObserver( |
| 367 const RenderFrameHostId& render_frame_host_id, | 407 const RenderFrameHostId& render_frame_host_id, |
| 368 DelegateObserver* observer) { | 408 DelegateObserver* observer) { |
| 369 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 409 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 370 presentation_frame->set_delegate_observer(observer); | 410 presentation_frame->set_delegate_observer(observer); |
| 371 } | 411 } |
| 372 | 412 |
| 373 void PresentationFrameManager::RemoveDelegateObserver( | 413 void PresentationFrameManager::RemoveDelegateObserver( |
| 374 const RenderFrameHostId& render_frame_host_id) { | 414 const RenderFrameHostId& render_frame_host_id) { |
| 375 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 415 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 } | 546 } |
| 507 } | 547 } |
| 508 | 548 |
| 509 void PresentationServiceDelegateImpl::OnJoinRouteResponse( | 549 void PresentationServiceDelegateImpl::OnJoinRouteResponse( |
| 510 int render_process_id, | 550 int render_process_id, |
| 511 int render_frame_id, | 551 int render_frame_id, |
| 512 const content::PresentationSessionInfo& session, | 552 const content::PresentationSessionInfo& session, |
| 513 const PresentationSessionSuccessCallback& success_cb, | 553 const PresentationSessionSuccessCallback& success_cb, |
| 514 const PresentationSessionErrorCallback& error_cb, | 554 const PresentationSessionErrorCallback& error_cb, |
| 515 const MediaRoute* route, | 555 const MediaRoute* route, |
| 556 const std::string& presentation_id, | |
| 516 const std::string& error_text) { | 557 const std::string& error_text) { |
| 517 if (!route) { | 558 if (!route) { |
| 518 error_cb.Run(content::PresentationError( | 559 error_cb.Run(content::PresentationError( |
| 519 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); | 560 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); |
| 520 } else { | 561 } else { |
| 521 DVLOG(1) << "OnJoinRouteResponse: " | 562 DVLOG(1) << "OnJoinRouteResponse: " |
| 522 << "route_id: " << route->media_route_id() | 563 << "route_id: " << route->media_route_id() |
| 523 << ", presentation URL: " << session.presentation_url | 564 << ", presentation URL: " << session.presentation_url |
| 524 << ", presentation ID: " << session.presentation_id; | 565 << ", presentation ID: " << session.presentation_id; |
| 566 DCHECK_EQ(session.presentation_id, presentation_id); | |
| 525 frame_manager_->OnPresentationSessionStarted( | 567 frame_manager_->OnPresentationSessionStarted( |
| 526 RenderFrameHostId(render_process_id, render_frame_id), false, session, | 568 RenderFrameHostId(render_process_id, render_frame_id), false, session, |
| 527 route->media_route_id()); | 569 route->media_route_id()); |
| 528 success_cb.Run(session); | 570 success_cb.Run(session); |
| 529 } | 571 } |
| 530 } | 572 } |
| 531 | 573 |
| 532 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 574 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
| 533 int render_process_id, | 575 int render_process_id, |
| 534 int render_frame_id, | 576 int render_frame_id, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 if (route_id.empty()) { | 653 if (route_id.empty()) { |
| 612 DVLOG(1) << "No active route for: " << presentation_id; | 654 DVLOG(1) << "No active route for: " << presentation_id; |
| 613 return; | 655 return; |
| 614 } | 656 } |
| 615 router_->CloseRoute(route_id); | 657 router_->CloseRoute(route_id); |
| 616 } | 658 } |
| 617 | 659 |
| 618 void PresentationServiceDelegateImpl::ListenForSessionMessages( | 660 void PresentationServiceDelegateImpl::ListenForSessionMessages( |
| 619 int render_process_id, | 661 int render_process_id, |
| 620 int render_frame_id, | 662 int render_frame_id, |
| 621 const PresentationSessionMessageCallback& message_cb) { | 663 const content::PresentationSessionInfo& session, |
| 622 const std::vector<MediaRoute::Id>& route_ids = frame_manager_->GetRouteIds( | 664 const content::PresentationSessionMessageCallback& message_cb) { |
| 623 RenderFrameHostId(render_process_id, render_frame_id)); | 665 frame_manager_->ListenForSessionMessages( |
| 624 if (route_ids.empty()) { | 666 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 625 DVLOG(1) << "No media routes found"; | 667 message_cb); |
| 626 message_cb.Run( | |
| 627 scoped_ptr<ScopedVector<content::PresentationSessionMessage>>()); | |
| 628 return; | |
| 629 } | |
| 630 | |
| 631 router_->ListenForRouteMessages(route_ids, message_cb); | |
| 632 } | 668 } |
| 633 | 669 |
| 634 void PresentationServiceDelegateImpl::SendMessage( | 670 void PresentationServiceDelegateImpl::SendMessage( |
| 635 int render_process_id, | 671 int render_process_id, |
| 636 int render_frame_id, | 672 int render_frame_id, |
| 637 scoped_ptr<content::PresentationSessionMessage> message_request, | 673 const content::PresentationSessionInfo& session, |
| 674 scoped_ptr<content::PresentationSessionMessage> message, | |
| 638 const SendMessageCallback& send_message_cb) { | 675 const SendMessageCallback& send_message_cb) { |
| 639 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 676 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( |
| 640 RenderFrameHostId(render_process_id, render_frame_id), | 677 RenderFrameHostId(render_process_id, render_frame_id), |
| 641 message_request->presentation_id); | 678 session.presentation_id); |
| 642 if (route_id.empty()) { | 679 if (route_id.empty()) { |
| 643 DVLOG(1) << "No active route for " << message_request->presentation_id; | 680 DVLOG(1) << "No active route for " << session.presentation_id; |
| 644 send_message_cb.Run(false); | 681 send_message_cb.Run(false); |
| 645 return; | 682 return; |
| 646 } | 683 } |
| 647 | 684 |
| 648 if (message_request->is_binary()) { | 685 if (message->is_binary()) { |
| 649 router_->SendRouteBinaryMessage(route_id, message_request->data.Pass(), | 686 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), |
| 650 send_message_cb); | 687 send_message_cb); |
| 651 } else { | 688 } else { |
| 652 router_->SendRouteMessage(route_id, *(message_request->message), | 689 router_->SendRouteMessage(route_id, message->message, send_message_cb); |
| 653 send_message_cb); | |
| 654 } | 690 } |
| 655 } | 691 } |
| 656 | 692 |
| 657 void PresentationServiceDelegateImpl::ListenForSessionStateChange( | 693 void PresentationServiceDelegateImpl::ListenForSessionStateChange( |
| 658 int render_process_id, | 694 int render_process_id, |
| 659 int render_frame_id, | 695 int render_frame_id, |
| 660 const content::SessionStateChangedCallback& state_changed_cb) { | 696 const content::SessionStateChangedCallback& state_changed_cb) { |
| 661 frame_manager_->ListenForSessionStateChange( | 697 frame_manager_->ListenForSessionStateChange( |
| 662 RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb); | 698 RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb); |
| 663 } | 699 } |
| 664 | 700 |
| 665 void PresentationServiceDelegateImpl::OnRouteResponse( | 701 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 666 const MediaRoute* route, | 702 const MediaRoute* route, |
| 703 const std::string& presentation_id, | |
|
mark a. foltz
2015/08/04 23:47:02
Should OnRouteReponse just take a content::Present
imcheng
2015/08/05 21:38:35
Taking presentation_id here is easier because it c
| |
| 667 const std::string& error) { | 704 const std::string& error) { |
| 668 if (!route) | 705 if (!route) |
| 669 return; | 706 return; |
| 670 const MediaSource& source = route->media_source(); | 707 const MediaSource& source = route->media_source(); |
| 671 DCHECK(!source.Empty()); | 708 DCHECK(!source.Empty()); |
| 672 if (!default_source_.Equals(source)) | 709 if (!default_source_.Equals(source)) |
| 673 return; | 710 return; |
| 674 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); | 711 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); |
| 675 if (!main_frame) | 712 if (!main_frame) |
| 676 return; | 713 return; |
| 677 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); | 714 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); |
| 678 std::string presentation_id = | |
| 679 GetPresentationIdAndUrl(route->media_route_id()).first; | |
| 680 frame_manager_->OnPresentationSessionStarted( | 715 frame_manager_->OnPresentationSessionStarted( |
| 681 render_frame_host_id, true, | 716 render_frame_host_id, true, |
| 682 content::PresentationSessionInfo(PresentationUrlFromMediaSource(source), | 717 content::PresentationSessionInfo(PresentationUrlFromMediaSource(source), |
| 683 presentation_id), | 718 presentation_id), |
| 684 route->media_route_id()); | 719 route->media_route_id()); |
| 685 } | 720 } |
| 686 | 721 |
| 687 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( | 722 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( |
| 688 DefaultMediaSourceObserver* observer) { | 723 DefaultMediaSourceObserver* observer) { |
| 689 default_media_source_observers_.AddObserver(observer); | 724 default_media_source_observers_.AddObserver(observer); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 708 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 743 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 709 int render_process_id, | 744 int render_process_id, |
| 710 int render_frame_id, | 745 int render_frame_id, |
| 711 const MediaSource::Id& source_id) const { | 746 const MediaSource::Id& source_id) const { |
| 712 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 747 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 713 return frame_manager_->HasScreenAvailabilityListenerForTest( | 748 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 714 render_frame_host_id, source_id); | 749 render_frame_host_id, source_id); |
| 715 } | 750 } |
| 716 | 751 |
| 717 } // namespace media_router | 752 } // namespace media_router |
| OLD | NEW |