Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 2737413003: [Presentation API] Remove references to presentation sessions. (Closed)
Patch Set: Update presentation service mock. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" 25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h"
26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h"
27 #include "chrome/browser/media/router/route_message.h" 27 #include "chrome/browser/media/router/route_message.h"
28 #include "chrome/browser/media/router/route_message_observer.h" 28 #include "chrome/browser/media/router/route_message_observer.h"
29 #include "chrome/browser/media/router/route_request_result.h" 29 #include "chrome/browser/media/router/route_request_result.h"
30 #include "chrome/browser/sessions/session_tab_helper.h" 30 #include "chrome/browser/sessions/session_tab_helper.h"
31 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
32 #include "content/public/browser/presentation_screen_availability_listener.h" 32 #include "content/public/browser/presentation_screen_availability_listener.h"
33 #include "content/public/browser/render_frame_host.h" 33 #include "content/public/browser/render_frame_host.h"
34 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
35 #include "content/public/common/presentation_session.h" 35 #include "content/public/common/presentation_info.h"
36 #include "url/gurl.h" 36 #include "url/gurl.h"
37 37
38 #if !defined(OS_ANDROID) 38 #if !defined(OS_ANDROID)
39 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
41 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
42 #endif 42 #endif
43 43
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
45 media_router::PresentationServiceDelegateImpl); 45 media_router::PresentationServiceDelegateImpl);
(...skipping 18 matching lines...) Expand all
64 url::Origin GetLastCommittedURLForFrame( 64 url::Origin GetLastCommittedURLForFrame(
65 RenderFrameHostId render_frame_host_id) { 65 RenderFrameHostId render_frame_host_id) {
66 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( 66 RenderFrameHost* render_frame_host = RenderFrameHost::FromID(
67 render_frame_host_id.first, render_frame_host_id.second); 67 render_frame_host_id.first, render_frame_host_id.second);
68 DCHECK(render_frame_host); 68 DCHECK(render_frame_host);
69 return render_frame_host->GetLastCommittedOrigin(); 69 return render_frame_host->GetLastCommittedOrigin();
70 } 70 }
71 71
72 // Observes messages originating from the MediaSink connected to a MediaRoute 72 // Observes messages originating from the MediaSink connected to a MediaRoute
73 // that represents a presentation. Converts the messages into 73 // that represents a presentation. Converts the messages into
74 // content::PresentationSessionMessages and dispatches them via the provided 74 // content::PresentationConnectionMessages and dispatches them via the provided
75 // PresentationSessionMessageCallback. 75 // PresentationConnectionMessageCallback.
76 class PresentationSessionMessagesObserver : public RouteMessageObserver { 76 class PresentationConnectionMessagesObserver : public RouteMessageObserver {
77 public: 77 public:
78 // |message_cb|: The callback to invoke whenever messages are received. 78 // |message_cb|: The callback to invoke whenever messages are received.
79 // |route_id|: ID of MediaRoute to listen for messages. 79 // |route_id|: ID of MediaRoute to listen for messages.
80 PresentationSessionMessagesObserver( 80 PresentationConnectionMessagesObserver(
81 MediaRouter* router, 81 MediaRouter* router,
82 const MediaRoute::Id& route_id, 82 const MediaRoute::Id& route_id,
83 const content::PresentationConnectionMessageCallback& message_cb) 83 const content::PresentationConnectionMessageCallback& message_cb)
84 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { 84 : RouteMessageObserver(router, route_id), message_cb_(message_cb) {
85 DCHECK(!message_cb_.is_null()); 85 DCHECK(!message_cb_.is_null());
86 } 86 }
87 87
88 ~PresentationSessionMessagesObserver() final {} 88 ~PresentationConnectionMessagesObserver() final {}
89 89
90 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { 90 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final {
91 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); 91 DVLOG(2) << __func__ << ", number of messages : " << messages.size();
92 // TODO(mfoltz): Remove RouteMessage and replace with move-only 92 // TODO(mfoltz): Remove RouteMessage and replace with move-only
93 // PresentationConnectionMessage. 93 // PresentationConnectionMessage.
94 std::vector<content::PresentationConnectionMessage> presentation_messages; 94 std::vector<content::PresentationConnectionMessage> presentation_messages;
95 for (const RouteMessage& message : messages) { 95 for (const RouteMessage& message : messages) {
96 if (message.type == RouteMessage::TEXT && message.text) { 96 if (message.type == RouteMessage::TEXT && message.text) {
97 presentation_messages.emplace_back(message.text.value()); 97 presentation_messages.emplace_back(message.text.value());
98 } else if (message.type == RouteMessage::BINARY && message.binary) { 98 } else if (message.type == RouteMessage::BINARY && message.binary) {
99 presentation_messages.emplace_back(message.binary.value()); 99 presentation_messages.emplace_back(message.binary.value());
100 } else { 100 } else {
101 NOTREACHED() << "Unknown route message type"; 101 NOTREACHED() << "Unknown route message type";
102 } 102 }
103 } 103 }
104 message_cb_.Run(std::move(presentation_messages)); 104 message_cb_.Run(std::move(presentation_messages));
105 } 105 }
106 106
107 private: 107 private:
108 const content::PresentationConnectionMessageCallback message_cb_; 108 const content::PresentationConnectionMessageCallback message_cb_;
109 109
110 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); 110 DISALLOW_COPY_AND_ASSIGN(PresentationConnectionMessagesObserver);
111 }; 111 };
112 112
113 } // namespace 113 } // namespace
114 114
115 // Used by PresentationServiceDelegateImpl to manage 115 // Used by PresentationServiceDelegateImpl to manage
116 // listeners and default presentation info in a render frame. 116 // listeners and default presentation info in a render frame.
117 // Its lifetime: 117 // Its lifetime:
118 // * Create an instance with |render_frame_host_id_| if no instance with the 118 // * Create an instance with |render_frame_host_id_| if no instance with the
119 // same |render_frame_host_id_| exists in: 119 // same |render_frame_host_id_| exists in:
120 // PresentationFrameManager::OnPresentationSessionStarted 120 // PresentationFrameManager::OnPresentationConnection
121 // PresentationFrameManager::OnDefaultPresentationSessionStarted 121 // PresentationFrameManager::OnDefaultPresentationStarted
122 // PresentationFrameManager::SetScreenAvailabilityListener 122 // PresentationFrameManager::SetScreenAvailabilityListener
123 // * Destroy the instance in: 123 // * Destroy the instance in:
124 // PresentationFrameManager::Reset 124 // PresentationFrameManager::Reset
125 class PresentationFrame { 125 class PresentationFrame {
126 public: 126 public:
127 PresentationFrame(const RenderFrameHostId& render_frame_host_id, 127 PresentationFrame(const RenderFrameHostId& render_frame_host_id,
128 content::WebContents* web_contents, 128 content::WebContents* web_contents,
129 MediaRouter* router); 129 MediaRouter* router);
130 ~PresentationFrame(); 130 ~PresentationFrame();
131 131
132 // Mirror corresponding APIs in PresentationServiceDelegateImpl. 132 // Mirror corresponding APIs in PresentationServiceDelegateImpl.
133 bool SetScreenAvailabilityListener( 133 bool SetScreenAvailabilityListener(
134 content::PresentationScreenAvailabilityListener* listener); 134 content::PresentationScreenAvailabilityListener* listener);
135 bool RemoveScreenAvailabilityListener( 135 bool RemoveScreenAvailabilityListener(
136 content::PresentationScreenAvailabilityListener* listener); 136 content::PresentationScreenAvailabilityListener* listener);
137 bool HasScreenAvailabilityListenerForTest( 137 bool HasScreenAvailabilityListenerForTest(
138 const MediaSource::Id& source_id) const; 138 const MediaSource::Id& source_id) const;
139 std::string GetDefaultPresentationId() const; 139 std::string GetDefaultPresentationId() const;
140 void ListenForConnectionStateChange( 140 void ListenForConnectionStateChange(
141 const content::PresentationSessionInfo& connection, 141 const content::PresentationInfo& connection,
142 const content::PresentationConnectionStateChangedCallback& 142 const content::PresentationConnectionStateChangedCallback&
143 state_changed_cb); 143 state_changed_cb);
144 void ListenForSessionMessages( 144 void ListenForConnectionMessages(
145 const content::PresentationSessionInfo& session, 145 const content::PresentationInfo& presentation_info,
146 const content::PresentationConnectionMessageCallback& message_cb); 146 const content::PresentationConnectionMessageCallback& message_cb);
147 147
148 void Reset(); 148 void Reset();
149 void RemoveConnection(const std::string& presentation_id, 149 void RemoveConnection(const std::string& presentation_id,
150 const MediaRoute::Id& route_id); 150 const MediaRoute::Id& route_id);
151 151
152 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; 152 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const;
153 153
154 void OnPresentationSessionStarted( 154 void OnPresentationConnection(
155 const content::PresentationSessionInfo& session, 155 const content::PresentationInfo& presentation_info,
156 const MediaRoute& route); 156 const MediaRoute& route);
157 void OnPresentationServiceDelegateDestroyed() const; 157 void OnPresentationServiceDelegateDestroyed() const;
158 158
159 bool IsOffscreenPresentation(const std::string& presentation_id) const; 159 bool IsOffscreenPresentation(const std::string& presentation_id) const;
160 void ConnectToPresentation( 160 void ConnectToPresentation(
161 const content::PresentationSessionInfo& session, 161 const content::PresentationInfo& presentation_info,
162 content::PresentationConnectionPtr controller_connection_ptr, 162 content::PresentationConnectionPtr controller_connection_ptr,
163 content::PresentationConnectionRequest receiver_connection_request); 163 content::PresentationConnectionRequest receiver_connection_request);
164 164
165 private: 165 private:
166 MediaSource GetMediaSourceFromListener( 166 MediaSource GetMediaSourceFromListener(
167 content::PresentationScreenAvailabilityListener* listener) const; 167 content::PresentationScreenAvailabilityListener* listener) const;
168 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; 168 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_;
169 base::SmallMap< 169 base::SmallMap<
170 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> 170 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>>
171 url_to_sinks_observer_; 171 url_to_sinks_observer_;
172 std::unordered_map< 172 std::unordered_map<
173 MediaRoute::Id, 173 MediaRoute::Id,
174 std::unique_ptr<PresentationConnectionStateSubscription>> 174 std::unique_ptr<PresentationConnectionStateSubscription>>
175 connection_state_subscriptions_; 175 connection_state_subscriptions_;
176 std::unordered_map< 176 std::unordered_map<MediaRoute::Id,
177 MediaRoute::Id, 177 std::unique_ptr<PresentationConnectionMessagesObserver>>
178 std::unique_ptr<PresentationSessionMessagesObserver>> 178 connection_messages_observers_;
179 session_messages_observers_;
180 std::unordered_map<MediaRoute::Id, 179 std::unordered_map<MediaRoute::Id,
181 std::unique_ptr<BrowserPresentationConnectionProxy>> 180 std::unique_ptr<BrowserPresentationConnectionProxy>>
182 browser_connection_proxies_; 181 browser_connection_proxies_;
183 182
184 RenderFrameHostId render_frame_host_id_; 183 RenderFrameHostId render_frame_host_id_;
185 184
186 // References to the owning WebContents, and the corresponding MediaRouter. 185 // References to the owning WebContents, and the corresponding MediaRouter.
187 content::WebContents* web_contents_; 186 content::WebContents* web_contents_;
188 MediaRouter* router_; 187 MediaRouter* router_;
189 }; 188 };
190 189
191 PresentationFrame::PresentationFrame( 190 PresentationFrame::PresentationFrame(
192 const RenderFrameHostId& render_frame_host_id, 191 const RenderFrameHostId& render_frame_host_id,
193 content::WebContents* web_contents, 192 content::WebContents* web_contents,
194 MediaRouter* router) 193 MediaRouter* router)
195 : render_frame_host_id_(render_frame_host_id), 194 : render_frame_host_id_(render_frame_host_id),
196 web_contents_(web_contents), 195 web_contents_(web_contents),
197 router_(router) { 196 router_(router) {
198 DCHECK(web_contents_); 197 DCHECK(web_contents_);
199 DCHECK(router_); 198 DCHECK(router_);
200 } 199 }
201 200
202 PresentationFrame::~PresentationFrame() { 201 PresentationFrame::~PresentationFrame() {
203 } 202 }
204 203
205 void PresentationFrame::OnPresentationSessionStarted( 204 void PresentationFrame::OnPresentationConnection(
206 const content::PresentationSessionInfo& session, 205 const content::PresentationInfo& presentation_info,
207 const MediaRoute& route) { 206 const MediaRoute& route) {
208 presentation_id_to_route_.insert( 207 presentation_id_to_route_.insert(
209 std::make_pair(session.presentation_id, route)); 208 std::make_pair(presentation_info.presentation_id, route));
210 } 209 }
211 210
212 const MediaRoute::Id PresentationFrame::GetRouteId( 211 const MediaRoute::Id PresentationFrame::GetRouteId(
213 const std::string& presentation_id) const { 212 const std::string& presentation_id) const {
214 auto it = presentation_id_to_route_.find(presentation_id); 213 auto it = presentation_id_to_route_.find(presentation_id);
215 return it != presentation_id_to_route_.end() ? it->second.media_route_id() 214 return it != presentation_id_to_route_.end() ? it->second.media_route_id()
216 : ""; 215 : "";
217 } 216 }
218 217
219 bool PresentationFrame::SetScreenAvailabilityListener( 218 bool PresentationFrame::SetScreenAvailabilityListener(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (IsOffscreenPresentation(pid_route.first)) { 261 if (IsOffscreenPresentation(pid_route.first)) {
263 offscreen_presentation_manager->UnregisterOffscreenPresentationController( 262 offscreen_presentation_manager->UnregisterOffscreenPresentationController(
264 pid_route.first, render_frame_host_id_); 263 pid_route.first, render_frame_host_id_);
265 } 264 }
266 router_->DetachRoute(pid_route.second.media_route_id()); 265 router_->DetachRoute(pid_route.second.media_route_id());
267 } 266 }
268 267
269 presentation_id_to_route_.clear(); 268 presentation_id_to_route_.clear();
270 url_to_sinks_observer_.clear(); 269 url_to_sinks_observer_.clear();
271 connection_state_subscriptions_.clear(); 270 connection_state_subscriptions_.clear();
272 session_messages_observers_.clear(); 271 connection_messages_observers_.clear();
273 browser_connection_proxies_.clear(); 272 browser_connection_proxies_.clear();
274 } 273 }
275 274
276 void PresentationFrame::RemoveConnection(const std::string& presentation_id, 275 void PresentationFrame::RemoveConnection(const std::string& presentation_id,
277 const MediaRoute::Id& route_id) { 276 const MediaRoute::Id& route_id) {
278 // Remove the presentation id mapping so a later call to Reset is a no-op. 277 // Remove the presentation id mapping so a later call to Reset is a no-op.
279 presentation_id_to_route_.erase(presentation_id); 278 presentation_id_to_route_.erase(presentation_id);
280 279
281 // We no longer need to observe route messages. 280 // We no longer need to observe route messages.
282 session_messages_observers_.erase(route_id); 281 connection_messages_observers_.erase(route_id);
283 282
284 browser_connection_proxies_.erase(route_id); 283 browser_connection_proxies_.erase(route_id);
285 // We keep the PresentationConnectionStateChangedCallback registered with MR 284 // We keep the PresentationConnectionStateChangedCallback registered with MR
286 // so the MRP can tell us when terminate() completed. 285 // so the MRP can tell us when terminate() completed.
287 } 286 }
288 287
289 void PresentationFrame::ListenForConnectionStateChange( 288 void PresentationFrame::ListenForConnectionStateChange(
290 const content::PresentationSessionInfo& connection, 289 const content::PresentationInfo& connection,
291 const content::PresentationConnectionStateChangedCallback& 290 const content::PresentationConnectionStateChangedCallback&
292 state_changed_cb) { 291 state_changed_cb) {
293 auto it = presentation_id_to_route_.find(connection.presentation_id); 292 auto it = presentation_id_to_route_.find(connection.presentation_id);
294 if (it == presentation_id_to_route_.end()) { 293 if (it == presentation_id_to_route_.end()) {
295 DLOG(ERROR) << __func__ << "route id not found for presentation: " 294 DLOG(ERROR) << __func__ << "route id not found for presentation: "
296 << connection.presentation_id; 295 << connection.presentation_id;
297 return; 296 return;
298 } 297 }
299 298
300 const MediaRoute::Id& route_id = it->second.media_route_id(); 299 const MediaRoute::Id& route_id = it->second.media_route_id();
301 if (connection_state_subscriptions_.find(route_id) != 300 if (connection_state_subscriptions_.find(route_id) !=
302 connection_state_subscriptions_.end()) { 301 connection_state_subscriptions_.end()) {
303 DLOG(ERROR) << __func__ 302 DLOG(ERROR) << __func__
304 << "Already listening connection state change for route: " 303 << "Already listening connection state change for route: "
305 << route_id; 304 << route_id;
306 return; 305 return;
307 } 306 }
308 307
309 connection_state_subscriptions_.insert(std::make_pair( 308 connection_state_subscriptions_.insert(std::make_pair(
310 route_id, router_->AddPresentationConnectionStateChangedCallback( 309 route_id, router_->AddPresentationConnectionStateChangedCallback(
311 route_id, state_changed_cb))); 310 route_id, state_changed_cb)));
312 } 311 }
313 312
314 void PresentationFrame::ListenForSessionMessages( 313 void PresentationFrame::ListenForConnectionMessages(
315 const content::PresentationSessionInfo& session, 314 const content::PresentationInfo& presentation_info,
316 const content::PresentationConnectionMessageCallback& message_cb) { 315 const content::PresentationConnectionMessageCallback& message_cb) {
317 auto it = presentation_id_to_route_.find(session.presentation_id); 316 auto it = presentation_id_to_route_.find(presentation_info.presentation_id);
318 if (it == presentation_id_to_route_.end()) { 317 if (it == presentation_id_to_route_.end()) {
319 DVLOG(2) << "ListenForSessionMessages: no route for " 318 DVLOG(2) << "ListenForConnectionMessages: no route for "
320 << session.presentation_id; 319 << presentation_info.presentation_id;
321 return; 320 return;
322 } 321 }
323 322
324 if (it->second.is_offscreen_presentation()) { 323 if (it->second.is_offscreen_presentation()) {
325 DVLOG(2) << "ListenForSessionMessages: do not listen for offscreen " 324 DVLOG(2) << "ListenForConnectionMessages: do not listen for offscreen "
326 << "presentation [id]: " << session.presentation_id; 325 << "presentation [id]: " << presentation_info.presentation_id;
327 return; 326 return;
328 } 327 }
329 328
330 const MediaRoute::Id& route_id = it->second.media_route_id(); 329 const MediaRoute::Id& route_id = it->second.media_route_id();
331 if (session_messages_observers_.find(route_id) != 330 if (connection_messages_observers_.find(route_id) !=
332 session_messages_observers_.end()) { 331 connection_messages_observers_.end()) {
333 DLOG(ERROR) << __func__ 332 DLOG(ERROR) << __func__
334 << "Already listening for session messages for route: " 333 << "Already listening for connection messages for route: "
335 << route_id; 334 << route_id;
336 return; 335 return;
337 } 336 }
338 337
339 session_messages_observers_.insert(std::make_pair( 338 connection_messages_observers_.insert(std::make_pair(
340 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( 339 route_id, base::MakeUnique<PresentationConnectionMessagesObserver>(
341 router_, route_id, message_cb))); 340 router_, route_id, message_cb)));
342 } 341 }
343 342
344 MediaSource PresentationFrame::GetMediaSourceFromListener( 343 MediaSource PresentationFrame::GetMediaSourceFromListener(
345 content::PresentationScreenAvailabilityListener* listener) const { 344 content::PresentationScreenAvailabilityListener* listener) const {
346 // If the default presentation URL is empty then fall back to tab mirroring. 345 // If the default presentation URL is empty then fall back to tab mirroring.
347 return listener->GetAvailabilityUrl().is_empty() 346 return listener->GetAvailabilityUrl().is_empty()
348 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) 347 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_))
349 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); 348 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl());
350 } 349 }
351 350
352 bool PresentationFrame::IsOffscreenPresentation( 351 bool PresentationFrame::IsOffscreenPresentation(
353 const std::string& presentation_id) const { 352 const std::string& presentation_id) const {
354 const auto it = presentation_id_to_route_.find(presentation_id); 353 const auto it = presentation_id_to_route_.find(presentation_id);
355 if (it == presentation_id_to_route_.end()) { 354 if (it == presentation_id_to_route_.end()) {
356 DLOG(WARNING) << "No route for [presentation_id]: " << presentation_id; 355 DLOG(WARNING) << "No route for [presentation_id]: " << presentation_id;
357 return false; 356 return false;
358 } 357 }
359 358
360 return it->second.is_offscreen_presentation(); 359 return it->second.is_offscreen_presentation();
361 } 360 }
362 361
363 void PresentationFrame::ConnectToPresentation( 362 void PresentationFrame::ConnectToPresentation(
364 const content::PresentationSessionInfo& session, 363 const content::PresentationInfo& presentation_info,
365 content::PresentationConnectionPtr controller_connection_ptr, 364 content::PresentationConnectionPtr controller_connection_ptr,
366 content::PresentationConnectionRequest receiver_connection_request) { 365 content::PresentationConnectionRequest receiver_connection_request) {
367 const auto pid_route_it = 366 const auto pid_route_it =
368 presentation_id_to_route_.find(session.presentation_id); 367 presentation_id_to_route_.find(presentation_info.presentation_id);
369 368
370 if (pid_route_it == presentation_id_to_route_.end()) { 369 if (pid_route_it == presentation_id_to_route_.end()) {
371 DLOG(WARNING) << "No route for [presentation_id]: " 370 DLOG(WARNING) << "No route for [presentation_id]: "
372 << session.presentation_id; 371 << presentation_info.presentation_id;
373 return; 372 return;
374 } 373 }
375 374
376 if (IsOffscreenPresentation(session.presentation_id)) { 375 if (IsOffscreenPresentation(presentation_info.presentation_id)) {
377 auto* const offscreen_presentation_manager = 376 auto* const offscreen_presentation_manager =
378 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( 377 OffscreenPresentationManagerFactory::GetOrCreateForWebContents(
379 web_contents_); 378 web_contents_);
380 offscreen_presentation_manager->RegisterOffscreenPresentationController( 379 offscreen_presentation_manager->RegisterOffscreenPresentationController(
381 session.presentation_id, session.presentation_url, 380 presentation_info.presentation_id, presentation_info.presentation_url,
382 render_frame_host_id_, std::move(controller_connection_ptr), 381 render_frame_host_id_, std::move(controller_connection_ptr),
383 std::move(receiver_connection_request)); 382 std::move(receiver_connection_request));
384 } else { 383 } else {
385 DVLOG(2) 384 DVLOG(2)
386 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " 385 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: "
387 << session.presentation_id; 386 << presentation_info.presentation_id;
388 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); 387 MediaRoute::Id route_id = pid_route_it->second.media_route_id();
389 auto* proxy = new BrowserPresentationConnectionProxy( 388 auto* proxy = new BrowserPresentationConnectionProxy(
390 router_, route_id, std::move(receiver_connection_request), 389 router_, route_id, std::move(receiver_connection_request),
391 std::move(controller_connection_ptr)); 390 std::move(controller_connection_ptr));
392 391
393 browser_connection_proxies_.insert( 392 browser_connection_proxies_.insert(
394 std::make_pair(route_id, base::WrapUnique(proxy))); 393 std::make_pair(route_id, base::WrapUnique(proxy)));
395 } 394 }
396 } 395 }
397 396
398 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. 397 // Used by PresentationServiceDelegateImpl to manage PresentationFrames.
399 class PresentationFrameManager { 398 class PresentationFrameManager {
400 public: 399 public:
401 PresentationFrameManager(content::WebContents* web_contents, 400 PresentationFrameManager(content::WebContents* web_contents,
402 MediaRouter* router); 401 MediaRouter* router);
403 ~PresentationFrameManager(); 402 ~PresentationFrameManager();
404 403
405 // Mirror corresponding APIs in PresentationServiceDelegateImpl. 404 // Mirror corresponding APIs in PresentationServiceDelegateImpl.
406 bool SetScreenAvailabilityListener( 405 bool SetScreenAvailabilityListener(
407 const RenderFrameHostId& render_frame_host_id, 406 const RenderFrameHostId& render_frame_host_id,
408 content::PresentationScreenAvailabilityListener* listener); 407 content::PresentationScreenAvailabilityListener* listener);
409 bool RemoveScreenAvailabilityListener( 408 bool RemoveScreenAvailabilityListener(
410 const RenderFrameHostId& render_frame_host_id, 409 const RenderFrameHostId& render_frame_host_id,
411 content::PresentationScreenAvailabilityListener* listener); 410 content::PresentationScreenAvailabilityListener* listener);
412 void ListenForConnectionStateChange( 411 void ListenForConnectionStateChange(
413 const RenderFrameHostId& render_frame_host_id, 412 const RenderFrameHostId& render_frame_host_id,
414 const content::PresentationSessionInfo& connection, 413 const content::PresentationInfo& connection,
415 const content::PresentationConnectionStateChangedCallback& 414 const content::PresentationConnectionStateChangedCallback&
416 state_changed_cb); 415 state_changed_cb);
417 void ListenForSessionMessages( 416 void ListenForConnectionMessages(
418 const RenderFrameHostId& render_frame_host_id, 417 const RenderFrameHostId& render_frame_host_id,
419 const content::PresentationSessionInfo& session, 418 const content::PresentationInfo& presentation_info,
420 const content::PresentationConnectionMessageCallback& message_cb); 419 const content::PresentationConnectionMessageCallback& message_cb);
421 420
422 // Sets or clears the default presentation request and callback for the given 421 // Sets or clears the default presentation request and callback for the given
423 // frame. Also sets / clears the default presentation requests for the owning 422 // frame. Also sets / clears the default presentation requests for the owning
424 // tab WebContents. 423 // tab WebContents.
425 void SetDefaultPresentationUrls( 424 void SetDefaultPresentationUrls(
426 const RenderFrameHostId& render_frame_host_id, 425 const RenderFrameHostId& render_frame_host_id,
427 const std::vector<GURL>& default_presentation_urls, 426 const std::vector<GURL>& default_presentation_urls,
428 const content::PresentationSessionStartedCallback& callback); 427 const content::PresentationConnectionCallback& callback);
429 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, 428 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id,
430 DelegateObserver* observer); 429 DelegateObserver* observer);
431 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); 430 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id);
432 void AddDefaultPresentationRequestObserver( 431 void AddDefaultPresentationRequestObserver(
433 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 432 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
434 observer); 433 observer);
435 void RemoveDefaultPresentationRequestObserver( 434 void RemoveDefaultPresentationRequestObserver(
436 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 435 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
437 observer); 436 observer);
438 void Reset(const RenderFrameHostId& render_frame_host_id); 437 void Reset(const RenderFrameHostId& render_frame_host_id);
439 void RemoveConnection(const RenderFrameHostId& render_frame_host_id, 438 void RemoveConnection(const RenderFrameHostId& render_frame_host_id,
440 const MediaRoute::Id& route_id, 439 const MediaRoute::Id& route_id,
441 const std::string& presentation_id); 440 const std::string& presentation_id);
442 bool HasScreenAvailabilityListenerForTest( 441 bool HasScreenAvailabilityListenerForTest(
443 const RenderFrameHostId& render_frame_host_id, 442 const RenderFrameHostId& render_frame_host_id,
444 const MediaSource::Id& source_id) const; 443 const MediaSource::Id& source_id) const;
445 void SetMediaRouterForTest(MediaRouter* router); 444 void SetMediaRouterForTest(MediaRouter* router);
446 445
447 void OnPresentationSessionStarted( 446 void OnPresentationConnection(
448 const RenderFrameHostId& render_frame_host_id, 447 const RenderFrameHostId& render_frame_host_id,
449 const content::PresentationSessionInfo& session, 448 const content::PresentationInfo& presentation_info,
450 const MediaRoute& route); 449 const MediaRoute& route);
451 void OnDefaultPresentationSessionStarted( 450 void OnDefaultPresentationStarted(
452 const PresentationRequest& request, 451 const PresentationRequest& request,
453 const content::PresentationSessionInfo& session, 452 const content::PresentationInfo& presentation_info,
454 const MediaRoute& route); 453 const MediaRoute& route);
455 454
456 void ConnectToPresentation( 455 void ConnectToPresentation(
457 const RenderFrameHostId& render_frame_host_id, 456 const RenderFrameHostId& render_frame_host_id,
458 const content::PresentationSessionInfo& session, 457 const content::PresentationInfo& presentation_info,
459 content::PresentationConnectionPtr controller_connection_ptr, 458 content::PresentationConnectionPtr controller_connection_ptr,
460 content::PresentationConnectionRequest receiver_connection_request); 459 content::PresentationConnectionRequest receiver_connection_request);
461 460
462 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, 461 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id,
463 const std::string& presentation_id) const; 462 const std::string& presentation_id) const;
464 463
465 const PresentationRequest* default_presentation_request() const { 464 const PresentationRequest* default_presentation_request() const {
466 return default_presentation_request_.get(); 465 return default_presentation_request_.get();
467 } 466 }
468 467
(...skipping 16 matching lines...) Expand all
485 // Maps a frame identifier to a PresentationFrame object for frames 484 // Maps a frame identifier to a PresentationFrame object for frames
486 // that are using presentation API. 485 // that are using presentation API.
487 std::unordered_map<RenderFrameHostId, std::unique_ptr<PresentationFrame>, 486 std::unordered_map<RenderFrameHostId, std::unique_ptr<PresentationFrame>,
488 RenderFrameHostIdHasher> 487 RenderFrameHostIdHasher>
489 presentation_frames_; 488 presentation_frames_;
490 489
491 // Default presentation request for the owning tab WebContents. 490 // Default presentation request for the owning tab WebContents.
492 std::unique_ptr<PresentationRequest> default_presentation_request_; 491 std::unique_ptr<PresentationRequest> default_presentation_request_;
493 492
494 // Callback to invoke when default presentation has started. 493 // Callback to invoke when default presentation has started.
495 content::PresentationSessionStartedCallback 494 content::PresentationConnectionCallback
496 default_presentation_started_callback_; 495 default_presentation_started_callback_;
497 496
498 // References to the observers listening for changes to this tab WebContent's 497 // References to the observers listening for changes to this tab WebContent's
499 // default presentation. 498 // default presentation.
500 base::ObserverList< 499 base::ObserverList<
501 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver> 500 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver>
502 default_presentation_request_observers_; 501 default_presentation_request_observers_;
503 502
504 // References to the owning WebContents, and the corresponding MediaRouter. 503 // References to the owning WebContents, and the corresponding MediaRouter.
505 MediaRouter* router_; 504 MediaRouter* router_;
506 content::WebContents* web_contents_; 505 content::WebContents* web_contents_;
507 }; 506 };
508 507
509 PresentationFrameManager::PresentationFrameManager( 508 PresentationFrameManager::PresentationFrameManager(
510 content::WebContents* web_contents, 509 content::WebContents* web_contents,
511 MediaRouter* router) 510 MediaRouter* router)
512 : router_(router), web_contents_(web_contents) { 511 : router_(router), web_contents_(web_contents) {
513 DCHECK(web_contents_); 512 DCHECK(web_contents_);
514 DCHECK(router_); 513 DCHECK(router_);
515 } 514 }
516 515
517 PresentationFrameManager::~PresentationFrameManager() {} 516 PresentationFrameManager::~PresentationFrameManager() {}
518 517
519 void PresentationFrameManager::OnPresentationSessionStarted( 518 void PresentationFrameManager::OnPresentationConnection(
520 const RenderFrameHostId& render_frame_host_id, 519 const RenderFrameHostId& render_frame_host_id,
521 const content::PresentationSessionInfo& session, 520 const content::PresentationInfo& presentation_info,
522 const MediaRoute& route) { 521 const MediaRoute& route) {
523 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 522 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
524 presentation_frame->OnPresentationSessionStarted(session, route); 523 presentation_frame->OnPresentationConnection(presentation_info, route);
525 } 524 }
526 525
527 void PresentationFrameManager::OnDefaultPresentationSessionStarted( 526 void PresentationFrameManager::OnDefaultPresentationStarted(
528 const PresentationRequest& request, 527 const PresentationRequest& request,
529 const content::PresentationSessionInfo& session, 528 const content::PresentationInfo& presentation_info,
530 const MediaRoute& route) { 529 const MediaRoute& route) {
531 OnPresentationSessionStarted(request.render_frame_host_id(), session, route); 530 OnPresentationConnection(request.render_frame_host_id(), presentation_info,
531 route);
532 532
533 if (default_presentation_request_ && 533 if (default_presentation_request_ &&
534 default_presentation_request_->Equals(request)) { 534 default_presentation_request_->Equals(request)) {
535 default_presentation_started_callback_.Run(session); 535 default_presentation_started_callback_.Run(presentation_info);
536 } 536 }
537 } 537 }
538 538
539 void PresentationFrameManager::ConnectToPresentation( 539 void PresentationFrameManager::ConnectToPresentation(
540 const RenderFrameHostId& render_frame_host_id, 540 const RenderFrameHostId& render_frame_host_id,
541 const content::PresentationSessionInfo& session, 541 const content::PresentationInfo& presentation_info,
542 content::PresentationConnectionPtr controller_connection_ptr, 542 content::PresentationConnectionPtr controller_connection_ptr,
543 content::PresentationConnectionRequest receiver_connection_request) { 543 content::PresentationConnectionRequest receiver_connection_request) {
544 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 544 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
545 presentation_frame->ConnectToPresentation( 545 presentation_frame->ConnectToPresentation(
546 session, std::move(controller_connection_ptr), 546 presentation_info, std::move(controller_connection_ptr),
547 std::move(receiver_connection_request)); 547 std::move(receiver_connection_request));
548 } 548 }
549 549
550 const MediaRoute::Id PresentationFrameManager::GetRouteId( 550 const MediaRoute::Id PresentationFrameManager::GetRouteId(
551 const RenderFrameHostId& render_frame_host_id, 551 const RenderFrameHostId& render_frame_host_id,
552 const std::string& presentation_id) const { 552 const std::string& presentation_id) const {
553 const auto it = presentation_frames_.find(render_frame_host_id); 553 const auto it = presentation_frames_.find(render_frame_host_id);
554 return it != presentation_frames_.end() 554 return it != presentation_frames_.end()
555 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); 555 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id();
556 } 556 }
(...skipping 18 matching lines...) Expand all
575 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( 575 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest(
576 const RenderFrameHostId& render_frame_host_id, 576 const RenderFrameHostId& render_frame_host_id,
577 const MediaSource::Id& source_id) const { 577 const MediaSource::Id& source_id) const {
578 const auto it = presentation_frames_.find(render_frame_host_id); 578 const auto it = presentation_frames_.find(render_frame_host_id);
579 return it != presentation_frames_.end() && 579 return it != presentation_frames_.end() &&
580 it->second->HasScreenAvailabilityListenerForTest(source_id); 580 it->second->HasScreenAvailabilityListenerForTest(source_id);
581 } 581 }
582 582
583 void PresentationFrameManager::ListenForConnectionStateChange( 583 void PresentationFrameManager::ListenForConnectionStateChange(
584 const RenderFrameHostId& render_frame_host_id, 584 const RenderFrameHostId& render_frame_host_id,
585 const content::PresentationSessionInfo& connection, 585 const content::PresentationInfo& connection,
586 const content::PresentationConnectionStateChangedCallback& 586 const content::PresentationConnectionStateChangedCallback&
587 state_changed_cb) { 587 state_changed_cb) {
588 const auto it = presentation_frames_.find(render_frame_host_id); 588 const auto it = presentation_frames_.find(render_frame_host_id);
589 if (it != presentation_frames_.end()) 589 if (it != presentation_frames_.end())
590 it->second->ListenForConnectionStateChange(connection, state_changed_cb); 590 it->second->ListenForConnectionStateChange(connection, state_changed_cb);
591 } 591 }
592 592
593 void PresentationFrameManager::ListenForSessionMessages( 593 void PresentationFrameManager::ListenForConnectionMessages(
594 const RenderFrameHostId& render_frame_host_id, 594 const RenderFrameHostId& render_frame_host_id,
595 const content::PresentationSessionInfo& session, 595 const content::PresentationInfo& presentation_info,
596 const content::PresentationConnectionMessageCallback& message_cb) { 596 const content::PresentationConnectionMessageCallback& message_cb) {
597 const auto it = presentation_frames_.find(render_frame_host_id); 597 const auto it = presentation_frames_.find(render_frame_host_id);
598 if (it == presentation_frames_.end()) { 598 if (it == presentation_frames_.end()) {
599 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " 599 DVLOG(2) << "ListenForConnectionMessages: PresentationFrame does not exist "
600 << "for: (" << render_frame_host_id.first << ", " 600 << "for: (" << render_frame_host_id.first << ", "
601 << render_frame_host_id.second << ")"; 601 << render_frame_host_id.second << ")";
602 return; 602 return;
603 } 603 }
604 it->second->ListenForSessionMessages(session, message_cb); 604 it->second->ListenForConnectionMessages(presentation_info, message_cb);
605 } 605 }
606 606
607 void PresentationFrameManager::SetDefaultPresentationUrls( 607 void PresentationFrameManager::SetDefaultPresentationUrls(
608 const RenderFrameHostId& render_frame_host_id, 608 const RenderFrameHostId& render_frame_host_id,
609 const std::vector<GURL>& default_presentation_urls, 609 const std::vector<GURL>& default_presentation_urls,
610 const content::PresentationSessionStartedCallback& callback) { 610 const content::PresentationConnectionCallback& callback) {
611 if (!IsMainFrame(render_frame_host_id)) 611 if (!IsMainFrame(render_frame_host_id))
612 return; 612 return;
613 613
614 if (default_presentation_urls.empty()) { 614 if (default_presentation_urls.empty()) {
615 ClearDefaultPresentationRequest(); 615 ClearDefaultPresentationRequest();
616 } else { 616 } else {
617 DCHECK(!callback.is_null()); 617 DCHECK(!callback.is_null());
618 const auto& frame_origin = 618 const auto& frame_origin =
619 GetLastCommittedURLForFrame(render_frame_host_id); 619 GetLastCommittedURLForFrame(render_frame_host_id);
620 PresentationRequest request(render_frame_host_id, default_presentation_urls, 620 PresentationRequest request(render_frame_host_id, default_presentation_urls,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 void PresentationServiceDelegateImpl::Reset(int render_process_id, 759 void PresentationServiceDelegateImpl::Reset(int render_process_id,
760 int render_frame_id) { 760 int render_frame_id) {
761 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 761 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
762 frame_manager_->Reset(render_frame_host_id); 762 frame_manager_->Reset(render_frame_host_id);
763 } 763 }
764 764
765 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( 765 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls(
766 int render_process_id, 766 int render_process_id,
767 int render_frame_id, 767 int render_frame_id,
768 const std::vector<GURL>& default_presentation_urls, 768 const std::vector<GURL>& default_presentation_urls,
769 const content::PresentationSessionStartedCallback& callback) { 769 const content::PresentationConnectionCallback& callback) {
770 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 770 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
771 frame_manager_->SetDefaultPresentationUrls( 771 frame_manager_->SetDefaultPresentationUrls(
772 render_frame_host_id, default_presentation_urls, callback); 772 render_frame_host_id, default_presentation_urls, callback);
773 } 773 }
774 774
775 void PresentationServiceDelegateImpl::OnJoinRouteResponse( 775 void PresentationServiceDelegateImpl::OnJoinRouteResponse(
776 int render_process_id, 776 int render_process_id,
777 int render_frame_id, 777 int render_frame_id,
778 const GURL& presentation_url, 778 const GURL& presentation_url,
779 const std::string& presentation_id, 779 const std::string& presentation_id,
780 const content::PresentationSessionStartedCallback& success_cb, 780 const content::PresentationConnectionCallback& success_cb,
781 const content::PresentationSessionErrorCallback& error_cb, 781 const content::PresentationConnectionErrorCallback& error_cb,
782 const RouteRequestResult& result) { 782 const RouteRequestResult& result) {
783 if (!result.route()) { 783 if (!result.route()) {
784 error_cb.Run(content::PresentationError( 784 error_cb.Run(content::PresentationError(
785 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, result.error())); 785 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, result.error()));
786 } else { 786 } else {
787 DVLOG(1) << "OnJoinRouteResponse: " 787 DVLOG(1) << "OnJoinRouteResponse: "
788 << "route_id: " << result.route()->media_route_id() 788 << "route_id: " << result.route()->media_route_id()
789 << ", presentation URL: " << presentation_url 789 << ", presentation URL: " << presentation_url
790 << ", presentation ID: " << presentation_id; 790 << ", presentation ID: " << presentation_id;
791 DCHECK_EQ(presentation_id, result.presentation_id()); 791 DCHECK_EQ(presentation_id, result.presentation_id());
792 content::PresentationSessionInfo session(presentation_url, 792 content::PresentationInfo presentation_info(presentation_url,
793 result.presentation_id()); 793 result.presentation_id());
794 frame_manager_->OnPresentationSessionStarted( 794 frame_manager_->OnPresentationConnection(
795 RenderFrameHostId(render_process_id, render_frame_id), session, 795 RenderFrameHostId(render_process_id, render_frame_id),
796 *result.route()); 796 presentation_info, *result.route());
797 success_cb.Run(session); 797 success_cb.Run(presentation_info);
798 } 798 }
799 } 799 }
800 800
801 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( 801 void PresentationServiceDelegateImpl::OnStartPresentationSucceeded(
802 int render_process_id, 802 int render_process_id,
803 int render_frame_id, 803 int render_frame_id,
804 const content::PresentationSessionStartedCallback& success_cb, 804 const content::PresentationConnectionCallback& success_cb,
805 const content::PresentationSessionInfo& new_session, 805 const content::PresentationInfo& new_presentation_info,
806 const MediaRoute& route) { 806 const MediaRoute& route) {
807 DVLOG(1) << "OnStartSessionSucceeded: " 807 DVLOG(1) << "OnStartPresentationSucceeded: "
808 << "route_id: " << route.media_route_id() 808 << "route_id: " << route.media_route_id()
809 << ", presentation URL: " << new_session.presentation_url 809 << ", presentation URL: " << new_presentation_info.presentation_url
810 << ", presentation ID: " << new_session.presentation_id; 810 << ", presentation ID: " << new_presentation_info.presentation_id;
811 frame_manager_->OnPresentationSessionStarted( 811 frame_manager_->OnPresentationConnection(
812 RenderFrameHostId(render_process_id, render_frame_id), new_session, 812 RenderFrameHostId(render_process_id, render_frame_id),
813 route); 813 new_presentation_info, route);
814 success_cb.Run(new_session); 814 success_cb.Run(new_presentation_info);
815 } 815 }
816 816
817 void PresentationServiceDelegateImpl::StartSession( 817 void PresentationServiceDelegateImpl::StartPresentation(
818 int render_process_id, 818 int render_process_id,
819 int render_frame_id, 819 int render_frame_id,
820 const std::vector<GURL>& presentation_urls, 820 const std::vector<GURL>& presentation_urls,
821 const content::PresentationSessionStartedCallback& success_cb, 821 const content::PresentationConnectionCallback& success_cb,
822 const content::PresentationSessionErrorCallback& error_cb) { 822 const content::PresentationConnectionErrorCallback& error_cb) {
823 if (presentation_urls.empty()) { 823 if (presentation_urls.empty()) {
824 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 824 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
825 "Invalid presentation arguments.")); 825 "Invalid presentation arguments."));
826 return; 826 return;
827 } 827 }
828 828
829 // TODO(crbug.com/670848): Improve handling of invalid URLs in 829 // TODO(crbug.com/670848): Improve handling of invalid URLs in
830 // PresentationService::start(). 830 // PresentationService::start().
831 if (presentation_urls.empty() || 831 if (presentation_urls.empty() ||
832 std::find_if_not(presentation_urls.begin(), presentation_urls.end(), 832 std::find_if_not(presentation_urls.begin(), presentation_urls.end(),
833 IsValidPresentationUrl) != presentation_urls.end()) { 833 IsValidPresentationUrl) != presentation_urls.end()) {
834 error_cb.Run(content::PresentationError( 834 error_cb.Run(content::PresentationError(
835 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 835 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
836 "Invalid presentation URL.")); 836 "Invalid presentation URL."));
837 return; 837 return;
838 } 838 }
839 839
840 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 840 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
841 std::unique_ptr<CreatePresentationConnectionRequest> request( 841 std::unique_ptr<CreatePresentationConnectionRequest> request(
842 new CreatePresentationConnectionRequest( 842 new CreatePresentationConnectionRequest(
843 render_frame_host_id, presentation_urls, 843 render_frame_host_id, presentation_urls,
844 GetLastCommittedURLForFrame(render_frame_host_id), 844 GetLastCommittedURLForFrame(render_frame_host_id),
845 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, 845 base::Bind(
846 weak_factory_.GetWeakPtr(), render_process_id, 846 &PresentationServiceDelegateImpl::OnStartPresentationSucceeded,
847 render_frame_id, success_cb), 847 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id,
848 success_cb),
848 error_cb)); 849 error_cb));
849 MediaRouterDialogController* controller = 850 MediaRouterDialogController* controller =
850 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); 851 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_);
851 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { 852 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) {
852 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; 853 LOG(ERROR)
854 << "Media router dialog already exists. Ignoring StartPresentation.";
853 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 855 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
854 "Unable to create dialog.")); 856 "Unable to create dialog."));
855 return; 857 return;
856 } 858 }
857 } 859 }
858 860
859 void PresentationServiceDelegateImpl::JoinSession( 861 void PresentationServiceDelegateImpl::ReconnectPresentation(
860 int render_process_id, 862 int render_process_id,
861 int render_frame_id, 863 int render_frame_id,
862 const std::vector<GURL>& presentation_urls, 864 const std::vector<GURL>& presentation_urls,
863 const std::string& presentation_id, 865 const std::string& presentation_id,
864 const content::PresentationSessionStartedCallback& success_cb, 866 const content::PresentationConnectionCallback& success_cb,
865 const content::PresentationSessionErrorCallback& error_cb) { 867 const content::PresentationConnectionErrorCallback& error_cb) {
866 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession"; 868 DVLOG(2) << "PresentationServiceDelegateImpl::ReconnectPresentation";
867 if (presentation_urls.empty()) { 869 if (presentation_urls.empty()) {
868 error_cb.Run(content::PresentationError( 870 error_cb.Run(content::PresentationError(
869 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 871 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
870 "Invalid presentation arguments.")); 872 "Invalid presentation arguments."));
871 return; 873 return;
872 } 874 }
873 875
874 const url::Origin& origin = GetLastCommittedURLForFrame( 876 const url::Origin& origin = GetLastCommittedURLForFrame(
875 RenderFrameHostId(render_process_id, render_frame_id)); 877 RenderFrameHostId(render_process_id, render_frame_id));
876 878
877 #if !defined(OS_ANDROID) 879 #if !defined(OS_ANDROID)
878 if (IsAutoJoinPresentationId(presentation_id) && 880 if (IsAutoJoinPresentationId(presentation_id) &&
879 ShouldCancelAutoJoinForOrigin(origin)) { 881 ShouldCancelAutoJoinForOrigin(origin)) {
880 error_cb.Run(content::PresentationError( 882 error_cb.Run(content::PresentationError(
881 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 883 content::PRESENTATION_ERROR_PRESENTATION_REQUEST_CANCELLED,
882 "Auto-join request cancelled by user preferences.")); 884 "Auto-join request cancelled by user preferences."));
883 return; 885 return;
884 } 886 }
885 #endif // !defined(OS_ANDROID) 887 #endif // !defined(OS_ANDROID)
886 888
887 // TODO(crbug.com/627655): Handle multiple URLs. 889 // TODO(crbug.com/627655): Handle multiple URLs.
888 const GURL& presentation_url = presentation_urls[0]; 890 const GURL& presentation_url = presentation_urls[0];
889 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); 891 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord();
890 std::vector<MediaRouteResponseCallback> route_response_callbacks; 892 std::vector<MediaRouteResponseCallback> route_response_callbacks;
891 route_response_callbacks.push_back( 893 route_response_callbacks.push_back(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 DVLOG(1) << "No active route for: " << presentation_id; 929 DVLOG(1) << "No active route for: " << presentation_id;
928 return; 930 return;
929 } 931 }
930 router_->TerminateRoute(route_id); 932 router_->TerminateRoute(route_id);
931 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); 933 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id);
932 } 934 }
933 935
934 void PresentationServiceDelegateImpl::ListenForConnectionMessages( 936 void PresentationServiceDelegateImpl::ListenForConnectionMessages(
935 int render_process_id, 937 int render_process_id,
936 int render_frame_id, 938 int render_frame_id,
937 const content::PresentationSessionInfo& session, 939 const content::PresentationInfo& presentation_info,
938 const content::PresentationConnectionMessageCallback& message_cb) { 940 const content::PresentationConnectionMessageCallback& message_cb) {
939 frame_manager_->ListenForSessionMessages( 941 frame_manager_->ListenForConnectionMessages(
940 RenderFrameHostId(render_process_id, render_frame_id), session, 942 RenderFrameHostId(render_process_id, render_frame_id), presentation_info,
941 message_cb); 943 message_cb);
942 } 944 }
943 945
944 void PresentationServiceDelegateImpl::SendMessage( 946 void PresentationServiceDelegateImpl::SendMessage(
945 int render_process_id, 947 int render_process_id,
946 int render_frame_id, 948 int render_frame_id,
947 const content::PresentationSessionInfo& session, 949 const content::PresentationInfo& presentation_info,
948 content::PresentationConnectionMessage message, 950 content::PresentationConnectionMessage message,
949 const SendMessageCallback& send_message_cb) { 951 const SendMessageCallback& send_message_cb) {
950 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( 952 const MediaRoute::Id& route_id = frame_manager_->GetRouteId(
951 RenderFrameHostId(render_process_id, render_frame_id), 953 RenderFrameHostId(render_process_id, render_frame_id),
952 session.presentation_id); 954 presentation_info.presentation_id);
953 if (route_id.empty()) { 955 if (route_id.empty()) {
954 DVLOG(1) << "No active route for " << session.presentation_id; 956 DVLOG(1) << "No active route for " << presentation_info.presentation_id;
955 send_message_cb.Run(false); 957 send_message_cb.Run(false);
956 return; 958 return;
957 } 959 }
958 960
959 if (message.is_binary()) { 961 if (message.is_binary()) {
960 router_->SendRouteBinaryMessage( 962 router_->SendRouteBinaryMessage(
961 route_id, 963 route_id,
962 base::MakeUnique<std::vector<uint8_t>>(std::move(message.data.value())), 964 base::MakeUnique<std::vector<uint8_t>>(std::move(message.data.value())),
963 send_message_cb); 965 send_message_cb);
964 } else { 966 } else {
965 router_->SendRouteMessage(route_id, message.message.value(), 967 router_->SendRouteMessage(route_id, message.message.value(),
966 send_message_cb); 968 send_message_cb);
967 } 969 }
968 } 970 }
969 971
970 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( 972 void PresentationServiceDelegateImpl::ListenForConnectionStateChange(
971 int render_process_id, 973 int render_process_id,
972 int render_frame_id, 974 int render_frame_id,
973 const content::PresentationSessionInfo& connection, 975 const content::PresentationInfo& connection,
974 const content::PresentationConnectionStateChangedCallback& 976 const content::PresentationConnectionStateChangedCallback&
975 state_changed_cb) { 977 state_changed_cb) {
976 frame_manager_->ListenForConnectionStateChange( 978 frame_manager_->ListenForConnectionStateChange(
977 RenderFrameHostId(render_process_id, render_frame_id), connection, 979 RenderFrameHostId(render_process_id, render_frame_id), connection,
978 state_changed_cb); 980 state_changed_cb);
979 } 981 }
980 982
981 void PresentationServiceDelegateImpl::ConnectToPresentation( 983 void PresentationServiceDelegateImpl::ConnectToPresentation(
982 int render_process_id, 984 int render_process_id,
983 int render_frame_id, 985 int render_frame_id,
984 const content::PresentationSessionInfo& session, 986 const content::PresentationInfo& presentation_info,
985 content::PresentationConnectionPtr controller_connection_ptr, 987 content::PresentationConnectionPtr controller_connection_ptr,
986 content::PresentationConnectionRequest receiver_connection_request) { 988 content::PresentationConnectionRequest receiver_connection_request) {
987 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 989 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
988 frame_manager_->ConnectToPresentation(render_frame_host_id, session, 990 frame_manager_->ConnectToPresentation(render_frame_host_id, presentation_info,
989 std::move(controller_connection_ptr), 991 std::move(controller_connection_ptr),
990 std::move(receiver_connection_request)); 992 std::move(receiver_connection_request));
991 } 993 }
992 994
993 void PresentationServiceDelegateImpl::OnRouteResponse( 995 void PresentationServiceDelegateImpl::OnRouteResponse(
994 const PresentationRequest& presentation_request, 996 const PresentationRequest& presentation_request,
995 const RouteRequestResult& result) { 997 const RouteRequestResult& result) {
996 if (!result.route() || 998 if (!result.route() ||
997 !base::ContainsValue(presentation_request.presentation_urls(), 999 !base::ContainsValue(presentation_request.presentation_urls(),
998 result.presentation_url())) { 1000 result.presentation_url())) {
999 return; 1001 return;
1000 } 1002 }
1001 1003
1002 content::PresentationSessionInfo session_info(result.presentation_url(), 1004 content::PresentationInfo presentation_info(result.presentation_url(),
1003 result.presentation_id()); 1005 result.presentation_id());
1004 frame_manager_->OnDefaultPresentationSessionStarted( 1006 frame_manager_->OnDefaultPresentationStarted(
1005 presentation_request, session_info, *result.route()); 1007 presentation_request, presentation_info, *result.route());
1006 } 1008 }
1007 1009
1008 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( 1010 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver(
1009 DefaultPresentationRequestObserver* observer) { 1011 DefaultPresentationRequestObserver* observer) {
1010 frame_manager_->AddDefaultPresentationRequestObserver(observer); 1012 frame_manager_->AddDefaultPresentationRequestObserver(observer);
1011 } 1013 }
1012 1014
1013 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( 1015 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver(
1014 DefaultPresentationRequestObserver* observer) { 1016 DefaultPresentationRequestObserver* observer) {
1015 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); 1017 frame_manager_->RemoveDefaultPresentationRequestObserver(observer);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 const base::ListValue* origins = 1053 const base::ListValue* origins =
1052 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) 1054 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
1053 ->GetPrefs() 1055 ->GetPrefs()
1054 ->GetList(prefs::kMediaRouterTabMirroringSources); 1056 ->GetList(prefs::kMediaRouterTabMirroringSources);
1055 return origins && 1057 return origins &&
1056 origins->Find(base::Value(origin.Serialize())) != origins->end(); 1058 origins->Find(base::Value(origin.Serialize())) != origins->end();
1057 } 1059 }
1058 #endif // !defined(OS_ANDROID) 1060 #endif // !defined(OS_ANDROID)
1059 1061
1060 } // namespace media_router 1062 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698