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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // Observes messages originating from the MediaSink connected to a MediaRoute | 75 // Observes messages originating from the MediaSink connected to a MediaRoute |
76 // that represents a presentation. Converts the messages into | 76 // that represents a presentation. Converts the messages into |
77 // content::PresentationSessionMessages and dispatches them via the provided | 77 // content::PresentationSessionMessages and dispatches them via the provided |
78 // PresentationSessionMessageCallback. | 78 // PresentationSessionMessageCallback. |
79 class PresentationSessionMessagesObserver : public RouteMessageObserver { | 79 class PresentationSessionMessagesObserver : public RouteMessageObserver { |
80 public: | 80 public: |
81 // |message_cb|: The callback to invoke whenever messages are received. | 81 // |message_cb|: The callback to invoke whenever messages are received. |
82 // |route_id|: ID of MediaRoute to listen for messages. | 82 // |route_id|: ID of MediaRoute to listen for messages. |
83 PresentationSessionMessagesObserver( | 83 PresentationSessionMessagesObserver( |
84 MediaRouter* router, const MediaRoute::Id& route_id, | 84 MediaRouter* router, |
85 const content::PresentationSessionMessageCallback& message_cb) | 85 const MediaRoute::Id& route_id, |
| 86 const content::PresentationConnectionMessageCallback& message_cb) |
86 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { | 87 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { |
87 DCHECK(!message_cb_.is_null()); | 88 DCHECK(!message_cb_.is_null()); |
88 } | 89 } |
89 | 90 |
90 ~PresentationSessionMessagesObserver() final {} | 91 ~PresentationSessionMessagesObserver() final {} |
91 | 92 |
92 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { | 93 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { |
93 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); | 94 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); |
94 ScopedVector<content::PresentationSessionMessage> presentation_messages; | 95 ScopedVector<content::PresentationConnectionMessage> presentation_messages; |
95 for (const RouteMessage& message : messages) { | 96 for (const RouteMessage& message : messages) { |
96 if (message.type == RouteMessage::TEXT && message.text) { | 97 if (message.type == RouteMessage::TEXT && message.text) { |
97 presentation_messages.push_back(new content::PresentationSessionMessage( | 98 presentation_messages.push_back( |
98 content::PresentationMessageType::TEXT)); | 99 new content::PresentationConnectionMessage( |
| 100 content::PresentationMessageType::TEXT)); |
99 presentation_messages.back()->message = *message.text; | 101 presentation_messages.back()->message = *message.text; |
100 } else if (message.type == RouteMessage::BINARY && message.binary) { | 102 } else if (message.type == RouteMessage::BINARY && message.binary) { |
101 presentation_messages.push_back(new content::PresentationSessionMessage( | 103 presentation_messages.push_back( |
102 content::PresentationMessageType::ARRAY_BUFFER)); | 104 new content::PresentationConnectionMessage( |
| 105 content::PresentationMessageType::BINARY)); |
103 presentation_messages.back()->data.reset( | 106 presentation_messages.back()->data.reset( |
104 new std::vector<uint8_t>(*message.binary)); | 107 new std::vector<uint8_t>(*message.binary)); |
105 } | 108 } |
106 } | 109 } |
107 // TODO(miu): Remove second argument from PresentationSessionMessageCallback | 110 // TODO(miu): Remove second argument from PresentationSessionMessageCallback |
108 // since it's always true now. | 111 // since it's always true now. |
109 message_cb_.Run(presentation_messages, true); | 112 message_cb_.Run(presentation_messages, true); |
110 } | 113 } |
111 | 114 |
112 private: | 115 private: |
113 const content::PresentationSessionMessageCallback message_cb_; | 116 const content::PresentationConnectionMessageCallback message_cb_; |
114 | 117 |
115 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); | 118 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); |
116 }; | 119 }; |
117 | 120 |
118 } // namespace | 121 } // namespace |
119 | 122 |
120 // Used by PresentationServiceDelegateImpl to manage | 123 // Used by PresentationServiceDelegateImpl to manage |
121 // listeners and default presentation info in a render frame. | 124 // listeners and default presentation info in a render frame. |
122 // Its lifetime: | 125 // Its lifetime: |
123 // * PresentationFrameManager AddDelegateObserver | 126 // * PresentationFrameManager AddDelegateObserver |
(...skipping 13 matching lines...) Expand all Loading... |
137 content::PresentationScreenAvailabilityListener* listener); | 140 content::PresentationScreenAvailabilityListener* listener); |
138 bool HasScreenAvailabilityListenerForTest( | 141 bool HasScreenAvailabilityListenerForTest( |
139 const MediaSource::Id& source_id) const; | 142 const MediaSource::Id& source_id) const; |
140 std::string GetDefaultPresentationId() const; | 143 std::string GetDefaultPresentationId() const; |
141 void ListenForConnectionStateChange( | 144 void ListenForConnectionStateChange( |
142 const content::PresentationSessionInfo& connection, | 145 const content::PresentationSessionInfo& connection, |
143 const content::PresentationConnectionStateChangedCallback& | 146 const content::PresentationConnectionStateChangedCallback& |
144 state_changed_cb); | 147 state_changed_cb); |
145 void ListenForSessionMessages( | 148 void ListenForSessionMessages( |
146 const content::PresentationSessionInfo& session, | 149 const content::PresentationSessionInfo& session, |
147 const content::PresentationSessionMessageCallback& message_cb); | 150 const content::PresentationConnectionMessageCallback& message_cb); |
148 | 151 |
149 void Reset(); | 152 void Reset(); |
150 void RemoveConnection(const std::string& presentation_id, | 153 void RemoveConnection(const std::string& presentation_id, |
151 const MediaRoute::Id& route_id); | 154 const MediaRoute::Id& route_id); |
152 | 155 |
153 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 156 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
154 const std::vector<MediaRoute::Id> GetRouteIds() const; | 157 const std::vector<MediaRoute::Id> GetRouteIds() const; |
155 | 158 |
156 void OnPresentationSessionStarted( | 159 void OnPresentationSessionStarted( |
157 const content::PresentationSessionInfo& session, | 160 const content::PresentationSessionInfo& session, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return; | 311 return; |
309 } | 312 } |
310 | 313 |
311 connection_state_subscriptions_.insert(std::make_pair( | 314 connection_state_subscriptions_.insert(std::make_pair( |
312 route_id, router_->AddPresentationConnectionStateChangedCallback( | 315 route_id, router_->AddPresentationConnectionStateChangedCallback( |
313 it->second, state_changed_cb))); | 316 it->second, state_changed_cb))); |
314 } | 317 } |
315 | 318 |
316 void PresentationFrame::ListenForSessionMessages( | 319 void PresentationFrame::ListenForSessionMessages( |
317 const content::PresentationSessionInfo& session, | 320 const content::PresentationSessionInfo& session, |
318 const content::PresentationSessionMessageCallback& message_cb) { | 321 const content::PresentationConnectionMessageCallback& message_cb) { |
319 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 322 auto it = presentation_id_to_route_id_.find(session.presentation_id); |
320 if (it == presentation_id_to_route_id_.end()) { | 323 if (it == presentation_id_to_route_id_.end()) { |
321 DVLOG(2) << "ListenForSessionMessages: no route for " | 324 DVLOG(2) << "ListenForSessionMessages: no route for " |
322 << session.presentation_id; | 325 << session.presentation_id; |
323 return; | 326 return; |
324 } | 327 } |
325 | 328 |
326 const MediaRoute::Id& route_id = it->second; | 329 const MediaRoute::Id& route_id = it->second; |
327 if (session_messages_observers_.find(route_id) != | 330 if (session_messages_observers_.find(route_id) != |
328 session_messages_observers_.end()) { | 331 session_messages_observers_.end()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 const RenderFrameHostId& render_frame_host_id, | 363 const RenderFrameHostId& render_frame_host_id, |
361 content::PresentationScreenAvailabilityListener* listener); | 364 content::PresentationScreenAvailabilityListener* listener); |
362 void ListenForConnectionStateChange( | 365 void ListenForConnectionStateChange( |
363 const RenderFrameHostId& render_frame_host_id, | 366 const RenderFrameHostId& render_frame_host_id, |
364 const content::PresentationSessionInfo& connection, | 367 const content::PresentationSessionInfo& connection, |
365 const content::PresentationConnectionStateChangedCallback& | 368 const content::PresentationConnectionStateChangedCallback& |
366 state_changed_cb); | 369 state_changed_cb); |
367 void ListenForSessionMessages( | 370 void ListenForSessionMessages( |
368 const RenderFrameHostId& render_frame_host_id, | 371 const RenderFrameHostId& render_frame_host_id, |
369 const content::PresentationSessionInfo& session, | 372 const content::PresentationSessionInfo& session, |
370 const content::PresentationSessionMessageCallback& message_cb); | 373 const content::PresentationConnectionMessageCallback& message_cb); |
371 | 374 |
372 // Sets or clears the default presentation request and callback for the given | 375 // Sets or clears the default presentation request and callback for the given |
373 // frame. Also sets / clears the default presentation requests for the owning | 376 // frame. Also sets / clears the default presentation requests for the owning |
374 // tab WebContents. | 377 // tab WebContents. |
375 void SetDefaultPresentationUrls( | 378 void SetDefaultPresentationUrls( |
376 const RenderFrameHostId& render_frame_host_id, | 379 const RenderFrameHostId& render_frame_host_id, |
377 const std::vector<GURL>& default_presentation_urls, | 380 const std::vector<GURL>& default_presentation_urls, |
378 const content::PresentationSessionStartedCallback& callback); | 381 const content::PresentationSessionStartedCallback& callback); |
379 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, | 382 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, |
380 DelegateObserver* observer); | 383 DelegateObserver* observer); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 const content::PresentationConnectionStateChangedCallback& | 536 const content::PresentationConnectionStateChangedCallback& |
534 state_changed_cb) { | 537 state_changed_cb) { |
535 const auto it = presentation_frames_.find(render_frame_host_id); | 538 const auto it = presentation_frames_.find(render_frame_host_id); |
536 if (it != presentation_frames_.end()) | 539 if (it != presentation_frames_.end()) |
537 it->second->ListenForConnectionStateChange(connection, state_changed_cb); | 540 it->second->ListenForConnectionStateChange(connection, state_changed_cb); |
538 } | 541 } |
539 | 542 |
540 void PresentationFrameManager::ListenForSessionMessages( | 543 void PresentationFrameManager::ListenForSessionMessages( |
541 const RenderFrameHostId& render_frame_host_id, | 544 const RenderFrameHostId& render_frame_host_id, |
542 const content::PresentationSessionInfo& session, | 545 const content::PresentationSessionInfo& session, |
543 const content::PresentationSessionMessageCallback& message_cb) { | 546 const content::PresentationConnectionMessageCallback& message_cb) { |
544 const auto it = presentation_frames_.find(render_frame_host_id); | 547 const auto it = presentation_frames_.find(render_frame_host_id); |
545 if (it == presentation_frames_.end()) { | 548 if (it == presentation_frames_.end()) { |
546 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " | 549 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " |
547 << "for: (" << render_frame_host_id.first << ", " | 550 << "for: (" << render_frame_host_id.first << ", " |
548 << render_frame_host_id.second << ")"; | 551 << render_frame_host_id.second << ")"; |
549 return; | 552 return; |
550 } | 553 } |
551 it->second->ListenForSessionMessages(session, message_cb); | 554 it->second->ListenForSessionMessages(session, message_cb); |
552 } | 555 } |
553 | 556 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 const MediaRoute::Id& route_id = | 890 const MediaRoute::Id& route_id = |
888 frame_manager_->GetRouteId(rfh_id, presentation_id); | 891 frame_manager_->GetRouteId(rfh_id, presentation_id); |
889 if (route_id.empty()) { | 892 if (route_id.empty()) { |
890 DVLOG(1) << "No active route for: " << presentation_id; | 893 DVLOG(1) << "No active route for: " << presentation_id; |
891 return; | 894 return; |
892 } | 895 } |
893 router_->TerminateRoute(route_id); | 896 router_->TerminateRoute(route_id); |
894 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); | 897 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); |
895 } | 898 } |
896 | 899 |
897 void PresentationServiceDelegateImpl::ListenForSessionMessages( | 900 void PresentationServiceDelegateImpl::ListenForConnectionMessages( |
898 int render_process_id, | 901 int render_process_id, |
899 int render_frame_id, | 902 int render_frame_id, |
900 const content::PresentationSessionInfo& session, | 903 const content::PresentationSessionInfo& session, |
901 const content::PresentationSessionMessageCallback& message_cb) { | 904 const content::PresentationConnectionMessageCallback& message_cb) { |
902 frame_manager_->ListenForSessionMessages( | 905 frame_manager_->ListenForSessionMessages( |
903 RenderFrameHostId(render_process_id, render_frame_id), session, | 906 RenderFrameHostId(render_process_id, render_frame_id), session, |
904 message_cb); | 907 message_cb); |
905 } | 908 } |
906 | 909 |
907 void PresentationServiceDelegateImpl::SendMessage( | 910 void PresentationServiceDelegateImpl::SendMessage( |
908 int render_process_id, | 911 int render_process_id, |
909 int render_frame_id, | 912 int render_frame_id, |
910 const content::PresentationSessionInfo& session, | 913 const content::PresentationSessionInfo& session, |
911 std::unique_ptr<content::PresentationSessionMessage> message, | 914 std::unique_ptr<content::PresentationConnectionMessage> message, |
912 const SendMessageCallback& send_message_cb) { | 915 const SendMessageCallback& send_message_cb) { |
913 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 916 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( |
914 RenderFrameHostId(render_process_id, render_frame_id), | 917 RenderFrameHostId(render_process_id, render_frame_id), |
915 session.presentation_id); | 918 session.presentation_id); |
916 if (route_id.empty()) { | 919 if (route_id.empty()) { |
917 DVLOG(1) << "No active route for " << session.presentation_id; | 920 DVLOG(1) << "No active route for " << session.presentation_id; |
918 send_message_cb.Run(false); | 921 send_message_cb.Run(false); |
919 return; | 922 return; |
920 } | 923 } |
921 | 924 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 const base::ListValue* origins = | 1002 const base::ListValue* origins = |
1000 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1003 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
1001 ->GetPrefs() | 1004 ->GetPrefs() |
1002 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1005 ->GetList(prefs::kMediaRouterTabMirroringSources); |
1003 return origins && | 1006 return origins && |
1004 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1007 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
1005 } | 1008 } |
1006 #endif // !defined(OS_ANDROID) | 1009 #endif // !defined(OS_ANDROID) |
1007 | 1010 |
1008 } // namespace media_router | 1011 } // namespace media_router |
OLD | NEW |