| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Observes messages originating from the MediaSink connected to a MediaRoute | 69 // Observes messages originating from the MediaSink connected to a MediaRoute |
| 70 // that represents a presentation. Converts the messages into | 70 // that represents a presentation. Converts the messages into |
| 71 // content::PresentationSessionMessages and dispatches them via the provided | 71 // content::PresentationSessionMessages and dispatches them via the provided |
| 72 // PresentationSessionMessageCallback. | 72 // PresentationSessionMessageCallback. |
| 73 class PresentationSessionMessagesObserver : public RouteMessageObserver { | 73 class PresentationSessionMessagesObserver : public RouteMessageObserver { |
| 74 public: | 74 public: |
| 75 // |message_cb|: The callback to invoke whenever messages are received. | 75 // |message_cb|: The callback to invoke whenever messages are received. |
| 76 // |route_id|: ID of MediaRoute to listen for messages. | 76 // |route_id|: ID of MediaRoute to listen for messages. |
| 77 PresentationSessionMessagesObserver( | 77 PresentationSessionMessagesObserver( |
| 78 MediaRouter* router, const MediaRoute::Id& route_id, | 78 MediaRouter* router, |
| 79 const content::PresentationSessionMessageCallback& message_cb) | 79 const MediaRoute::Id& route_id, |
| 80 const content::PresentationConnectionMessageCallback& message_cb) |
| 80 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { | 81 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { |
| 81 DCHECK(!message_cb_.is_null()); | 82 DCHECK(!message_cb_.is_null()); |
| 82 } | 83 } |
| 83 | 84 |
| 84 ~PresentationSessionMessagesObserver() final {} | 85 ~PresentationSessionMessagesObserver() final {} |
| 85 | 86 |
| 86 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { | 87 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { |
| 87 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); | 88 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); |
| 88 ScopedVector<content::PresentationSessionMessage> presentation_messages; | 89 ScopedVector<content::PresentationConnectionMessage> presentation_messages; |
| 89 for (const RouteMessage& message : messages) { | 90 for (const RouteMessage& message : messages) { |
| 90 if (message.type == RouteMessage::TEXT && message.text) { | 91 if (message.type == RouteMessage::TEXT && message.text) { |
| 91 presentation_messages.push_back(new content::PresentationSessionMessage( | 92 presentation_messages.push_back( |
| 92 content::PresentationMessageType::TEXT)); | 93 new content::PresentationConnectionMessage( |
| 94 content::PresentationMessageType::TEXT)); |
| 93 presentation_messages.back()->message = *message.text; | 95 presentation_messages.back()->message = *message.text; |
| 94 } else if (message.type == RouteMessage::BINARY && message.binary) { | 96 } else if (message.type == RouteMessage::BINARY && message.binary) { |
| 95 presentation_messages.push_back(new content::PresentationSessionMessage( | 97 presentation_messages.push_back( |
| 96 content::PresentationMessageType::ARRAY_BUFFER)); | 98 new content::PresentationConnectionMessage( |
| 99 content::PresentationMessageType::BINARY)); |
| 97 presentation_messages.back()->data.reset( | 100 presentation_messages.back()->data.reset( |
| 98 new std::vector<uint8_t>(*message.binary)); | 101 new std::vector<uint8_t>(*message.binary)); |
| 99 } | 102 } |
| 100 } | 103 } |
| 101 // TODO(miu): Remove second argument from PresentationSessionMessageCallback | 104 // TODO(miu): Remove second argument from PresentationSessionMessageCallback |
| 102 // since it's always true now. | 105 // since it's always true now. |
| 103 message_cb_.Run(presentation_messages, true); | 106 message_cb_.Run(presentation_messages, true); |
| 104 } | 107 } |
| 105 | 108 |
| 106 private: | 109 private: |
| 107 const content::PresentationSessionMessageCallback message_cb_; | 110 const content::PresentationConnectionMessageCallback message_cb_; |
| 108 | 111 |
| 109 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); | 112 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); |
| 110 }; | 113 }; |
| 111 | 114 |
| 112 } // namespace | 115 } // namespace |
| 113 | 116 |
| 114 // Used by PresentationServiceDelegateImpl to manage | 117 // Used by PresentationServiceDelegateImpl to manage |
| 115 // listeners and default presentation info in a render frame. | 118 // listeners and default presentation info in a render frame. |
| 116 // Its lifetime: | 119 // Its lifetime: |
| 117 // * PresentationFrameManager AddDelegateObserver | 120 // * PresentationFrameManager AddDelegateObserver |
| (...skipping 13 matching lines...) Expand all Loading... |
| 131 content::PresentationScreenAvailabilityListener* listener); | 134 content::PresentationScreenAvailabilityListener* listener); |
| 132 bool HasScreenAvailabilityListenerForTest( | 135 bool HasScreenAvailabilityListenerForTest( |
| 133 const MediaSource::Id& source_id) const; | 136 const MediaSource::Id& source_id) const; |
| 134 std::string GetDefaultPresentationId() const; | 137 std::string GetDefaultPresentationId() const; |
| 135 void ListenForConnectionStateChange( | 138 void ListenForConnectionStateChange( |
| 136 const content::PresentationSessionInfo& connection, | 139 const content::PresentationSessionInfo& connection, |
| 137 const content::PresentationConnectionStateChangedCallback& | 140 const content::PresentationConnectionStateChangedCallback& |
| 138 state_changed_cb); | 141 state_changed_cb); |
| 139 void ListenForSessionMessages( | 142 void ListenForSessionMessages( |
| 140 const content::PresentationSessionInfo& session, | 143 const content::PresentationSessionInfo& session, |
| 141 const content::PresentationSessionMessageCallback& message_cb); | 144 const content::PresentationConnectionMessageCallback& message_cb); |
| 142 | 145 |
| 143 void Reset(); | 146 void Reset(); |
| 144 void RemoveConnection(const std::string& presentation_id, | 147 void RemoveConnection(const std::string& presentation_id, |
| 145 const MediaRoute::Id& route_id); | 148 const MediaRoute::Id& route_id); |
| 146 | 149 |
| 147 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 150 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 148 const std::vector<MediaRoute::Id> GetRouteIds() const; | 151 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 149 | 152 |
| 150 void OnPresentationSessionStarted( | 153 void OnPresentationSessionStarted( |
| 151 const content::PresentationSessionInfo& session, | 154 const content::PresentationSessionInfo& session, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return; | 305 return; |
| 303 } | 306 } |
| 304 | 307 |
| 305 connection_state_subscriptions_.insert(std::make_pair( | 308 connection_state_subscriptions_.insert(std::make_pair( |
| 306 route_id, router_->AddPresentationConnectionStateChangedCallback( | 309 route_id, router_->AddPresentationConnectionStateChangedCallback( |
| 307 it->second, state_changed_cb))); | 310 it->second, state_changed_cb))); |
| 308 } | 311 } |
| 309 | 312 |
| 310 void PresentationFrame::ListenForSessionMessages( | 313 void PresentationFrame::ListenForSessionMessages( |
| 311 const content::PresentationSessionInfo& session, | 314 const content::PresentationSessionInfo& session, |
| 312 const content::PresentationSessionMessageCallback& message_cb) { | 315 const content::PresentationConnectionMessageCallback& message_cb) { |
| 313 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 316 auto it = presentation_id_to_route_id_.find(session.presentation_id); |
| 314 if (it == presentation_id_to_route_id_.end()) { | 317 if (it == presentation_id_to_route_id_.end()) { |
| 315 DVLOG(2) << "ListenForSessionMessages: no route for " | 318 DVLOG(2) << "ListenForSessionMessages: no route for " |
| 316 << session.presentation_id; | 319 << session.presentation_id; |
| 317 return; | 320 return; |
| 318 } | 321 } |
| 319 | 322 |
| 320 const MediaRoute::Id& route_id = it->second; | 323 const MediaRoute::Id& route_id = it->second; |
| 321 if (session_messages_observers_.find(route_id) != | 324 if (session_messages_observers_.find(route_id) != |
| 322 session_messages_observers_.end()) { | 325 session_messages_observers_.end()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 const RenderFrameHostId& render_frame_host_id, | 357 const RenderFrameHostId& render_frame_host_id, |
| 355 content::PresentationScreenAvailabilityListener* listener); | 358 content::PresentationScreenAvailabilityListener* listener); |
| 356 void ListenForConnectionStateChange( | 359 void ListenForConnectionStateChange( |
| 357 const RenderFrameHostId& render_frame_host_id, | 360 const RenderFrameHostId& render_frame_host_id, |
| 358 const content::PresentationSessionInfo& connection, | 361 const content::PresentationSessionInfo& connection, |
| 359 const content::PresentationConnectionStateChangedCallback& | 362 const content::PresentationConnectionStateChangedCallback& |
| 360 state_changed_cb); | 363 state_changed_cb); |
| 361 void ListenForSessionMessages( | 364 void ListenForSessionMessages( |
| 362 const RenderFrameHostId& render_frame_host_id, | 365 const RenderFrameHostId& render_frame_host_id, |
| 363 const content::PresentationSessionInfo& session, | 366 const content::PresentationSessionInfo& session, |
| 364 const content::PresentationSessionMessageCallback& message_cb); | 367 const content::PresentationConnectionMessageCallback& message_cb); |
| 365 | 368 |
| 366 // Sets or clears the default presentation request and callback for the given | 369 // Sets or clears the default presentation request and callback for the given |
| 367 // frame. Also sets / clears the default presentation requests for the owning | 370 // frame. Also sets / clears the default presentation requests for the owning |
| 368 // tab WebContents. | 371 // tab WebContents. |
| 369 void SetDefaultPresentationUrl( | 372 void SetDefaultPresentationUrl( |
| 370 const RenderFrameHostId& render_frame_host_id, | 373 const RenderFrameHostId& render_frame_host_id, |
| 371 const GURL& default_presentation_url, | 374 const GURL& default_presentation_url, |
| 372 const content::PresentationSessionStartedCallback& callback); | 375 const content::PresentationSessionStartedCallback& callback); |
| 373 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, | 376 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, |
| 374 DelegateObserver* observer); | 377 DelegateObserver* observer); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 const content::PresentationConnectionStateChangedCallback& | 530 const content::PresentationConnectionStateChangedCallback& |
| 528 state_changed_cb) { | 531 state_changed_cb) { |
| 529 const auto it = presentation_frames_.find(render_frame_host_id); | 532 const auto it = presentation_frames_.find(render_frame_host_id); |
| 530 if (it != presentation_frames_.end()) | 533 if (it != presentation_frames_.end()) |
| 531 it->second->ListenForConnectionStateChange(connection, state_changed_cb); | 534 it->second->ListenForConnectionStateChange(connection, state_changed_cb); |
| 532 } | 535 } |
| 533 | 536 |
| 534 void PresentationFrameManager::ListenForSessionMessages( | 537 void PresentationFrameManager::ListenForSessionMessages( |
| 535 const RenderFrameHostId& render_frame_host_id, | 538 const RenderFrameHostId& render_frame_host_id, |
| 536 const content::PresentationSessionInfo& session, | 539 const content::PresentationSessionInfo& session, |
| 537 const content::PresentationSessionMessageCallback& message_cb) { | 540 const content::PresentationConnectionMessageCallback& message_cb) { |
| 538 const auto it = presentation_frames_.find(render_frame_host_id); | 541 const auto it = presentation_frames_.find(render_frame_host_id); |
| 539 if (it == presentation_frames_.end()) { | 542 if (it == presentation_frames_.end()) { |
| 540 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " | 543 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " |
| 541 << "for: (" << render_frame_host_id.first << ", " | 544 << "for: (" << render_frame_host_id.first << ", " |
| 542 << render_frame_host_id.second << ")"; | 545 << render_frame_host_id.second << ")"; |
| 543 return; | 546 return; |
| 544 } | 547 } |
| 545 it->second->ListenForSessionMessages(session, message_cb); | 548 it->second->ListenForSessionMessages(session, message_cb); |
| 546 } | 549 } |
| 547 | 550 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 const MediaRoute::Id& route_id = | 877 const MediaRoute::Id& route_id = |
| 875 frame_manager_->GetRouteId(rfh_id, presentation_id); | 878 frame_manager_->GetRouteId(rfh_id, presentation_id); |
| 876 if (route_id.empty()) { | 879 if (route_id.empty()) { |
| 877 DVLOG(1) << "No active route for: " << presentation_id; | 880 DVLOG(1) << "No active route for: " << presentation_id; |
| 878 return; | 881 return; |
| 879 } | 882 } |
| 880 router_->TerminateRoute(route_id); | 883 router_->TerminateRoute(route_id); |
| 881 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); | 884 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); |
| 882 } | 885 } |
| 883 | 886 |
| 884 void PresentationServiceDelegateImpl::ListenForSessionMessages( | 887 void PresentationServiceDelegateImpl::ListenForConnectionMessages( |
| 885 int render_process_id, | 888 int render_process_id, |
| 886 int render_frame_id, | 889 int render_frame_id, |
| 887 const content::PresentationSessionInfo& session, | 890 const content::PresentationSessionInfo& session, |
| 888 const content::PresentationSessionMessageCallback& message_cb) { | 891 const content::PresentationConnectionMessageCallback& message_cb) { |
| 889 frame_manager_->ListenForSessionMessages( | 892 frame_manager_->ListenForSessionMessages( |
| 890 RenderFrameHostId(render_process_id, render_frame_id), session, | 893 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 891 message_cb); | 894 message_cb); |
| 892 } | 895 } |
| 893 | 896 |
| 894 void PresentationServiceDelegateImpl::SendMessage( | 897 void PresentationServiceDelegateImpl::SendMessage( |
| 895 int render_process_id, | 898 int render_process_id, |
| 896 int render_frame_id, | 899 int render_frame_id, |
| 897 const content::PresentationSessionInfo& session, | 900 const content::PresentationSessionInfo& session, |
| 898 std::unique_ptr<content::PresentationSessionMessage> message, | 901 std::unique_ptr<content::PresentationConnectionMessage> message, |
| 899 const SendMessageCallback& send_message_cb) { | 902 const SendMessageCallback& send_message_cb) { |
| 900 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 903 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( |
| 901 RenderFrameHostId(render_process_id, render_frame_id), | 904 RenderFrameHostId(render_process_id, render_frame_id), |
| 902 session.presentation_id); | 905 session.presentation_id); |
| 903 if (route_id.empty()) { | 906 if (route_id.empty()) { |
| 904 DVLOG(1) << "No active route for " << session.presentation_id; | 907 DVLOG(1) << "No active route for " << session.presentation_id; |
| 905 send_message_cb.Run(false); | 908 send_message_cb.Run(false); |
| 906 return; | 909 return; |
| 907 } | 910 } |
| 908 | 911 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 974 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 972 int render_process_id, | 975 int render_process_id, |
| 973 int render_frame_id, | 976 int render_frame_id, |
| 974 const MediaSource::Id& source_id) const { | 977 const MediaSource::Id& source_id) const { |
| 975 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 978 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 976 return frame_manager_->HasScreenAvailabilityListenerForTest( | 979 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 977 render_frame_host_id, source_id); | 980 render_frame_host_id, source_id); |
| 978 } | 981 } |
| 979 | 982 |
| 980 } // namespace media_router | 983 } // namespace media_router |
| OLD | NEW |