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

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 PresentationServiceDelegateImpl unittest 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 void ConnectToPresentation( 159 void ConnectToPresentation(
160 const content::PresentationSessionInfo& session, 160 const content::PresentationInfo& presentation_info,
161 content::PresentationConnectionPtr controller_connection_ptr, 161 content::PresentationConnectionPtr controller_connection_ptr,
162 content::PresentationConnectionRequest receiver_connection_request); 162 content::PresentationConnectionRequest receiver_connection_request);
163 163
164 private: 164 private:
165 MediaSource GetMediaSourceFromListener( 165 MediaSource GetMediaSourceFromListener(
166 content::PresentationScreenAvailabilityListener* listener) const; 166 content::PresentationScreenAvailabilityListener* listener) const;
167 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; 167 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_;
168 base::SmallMap< 168 base::SmallMap<
169 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> 169 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>>
170 url_to_sinks_observer_; 170 url_to_sinks_observer_;
171 std::unordered_map< 171 std::unordered_map<
172 MediaRoute::Id, 172 MediaRoute::Id,
173 std::unique_ptr<PresentationConnectionStateSubscription>> 173 std::unique_ptr<PresentationConnectionStateSubscription>>
174 connection_state_subscriptions_; 174 connection_state_subscriptions_;
175 std::unordered_map< 175 std::unordered_map<MediaRoute::Id,
176 MediaRoute::Id, 176 std::unique_ptr<PresentationConnectionMessagesObserver>>
177 std::unique_ptr<PresentationSessionMessagesObserver>> 177 connection_messages_observers_;
178 session_messages_observers_;
179 std::unordered_map<MediaRoute::Id, 178 std::unordered_map<MediaRoute::Id,
180 std::unique_ptr<BrowserPresentationConnectionProxy>> 179 std::unique_ptr<BrowserPresentationConnectionProxy>>
181 browser_connection_proxies_; 180 browser_connection_proxies_;
182 181
183 RenderFrameHostId render_frame_host_id_; 182 RenderFrameHostId render_frame_host_id_;
184 183
185 // References to the owning WebContents, and the corresponding MediaRouter. 184 // References to the owning WebContents, and the corresponding MediaRouter.
186 content::WebContents* web_contents_; 185 content::WebContents* web_contents_;
187 MediaRouter* router_; 186 MediaRouter* router_;
188 }; 187 };
189 188
190 PresentationFrame::PresentationFrame( 189 PresentationFrame::PresentationFrame(
191 const RenderFrameHostId& render_frame_host_id, 190 const RenderFrameHostId& render_frame_host_id,
192 content::WebContents* web_contents, 191 content::WebContents* web_contents,
193 MediaRouter* router) 192 MediaRouter* router)
194 : render_frame_host_id_(render_frame_host_id), 193 : render_frame_host_id_(render_frame_host_id),
195 web_contents_(web_contents), 194 web_contents_(web_contents),
196 router_(router) { 195 router_(router) {
197 DCHECK(web_contents_); 196 DCHECK(web_contents_);
198 DCHECK(router_); 197 DCHECK(router_);
199 } 198 }
200 199
201 PresentationFrame::~PresentationFrame() { 200 PresentationFrame::~PresentationFrame() {
202 } 201 }
203 202
204 void PresentationFrame::OnPresentationSessionStarted( 203 void PresentationFrame::OnPresentationConnection(
205 const content::PresentationSessionInfo& session, 204 const content::PresentationInfo& presentation_info,
206 const MediaRoute& route) { 205 const MediaRoute& route) {
207 presentation_id_to_route_.insert( 206 presentation_id_to_route_.insert(
208 std::make_pair(session.presentation_id, route)); 207 std::make_pair(presentation_info.presentation_id, route));
209 } 208 }
210 209
211 const MediaRoute::Id PresentationFrame::GetRouteId( 210 const MediaRoute::Id PresentationFrame::GetRouteId(
212 const std::string& presentation_id) const { 211 const std::string& presentation_id) const {
213 auto it = presentation_id_to_route_.find(presentation_id); 212 auto it = presentation_id_to_route_.find(presentation_id);
214 return it != presentation_id_to_route_.end() ? it->second.media_route_id() 213 return it != presentation_id_to_route_.end() ? it->second.media_route_id()
215 : ""; 214 : "";
216 } 215 }
217 216
218 bool PresentationFrame::SetScreenAvailabilityListener( 217 bool PresentationFrame::SetScreenAvailabilityListener(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 offscreen_presentation_manager->UnregisterOffscreenPresentationController( 261 offscreen_presentation_manager->UnregisterOffscreenPresentationController(
263 pid_route.first, render_frame_host_id_); 262 pid_route.first, render_frame_host_id_);
264 } else { 263 } else {
265 router_->DetachRoute(pid_route.second.media_route_id()); 264 router_->DetachRoute(pid_route.second.media_route_id());
266 } 265 }
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 void PresentationFrame::ConnectToPresentation( 351 void PresentationFrame::ConnectToPresentation(
353 const content::PresentationSessionInfo& session, 352 const content::PresentationInfo& presentation_info,
354 content::PresentationConnectionPtr controller_connection_ptr, 353 content::PresentationConnectionPtr controller_connection_ptr,
355 content::PresentationConnectionRequest receiver_connection_request) { 354 content::PresentationConnectionRequest receiver_connection_request) {
356 const auto pid_route_it = 355 const auto pid_route_it =
357 presentation_id_to_route_.find(session.presentation_id); 356 presentation_id_to_route_.find(presentation_info.presentation_id);
358 357
359 if (pid_route_it == presentation_id_to_route_.end()) { 358 if (pid_route_it == presentation_id_to_route_.end()) {
360 DLOG(WARNING) << "No route for [presentation_id]: " 359 DLOG(WARNING) << "No route for [presentation_id]: "
361 << session.presentation_id; 360 << presentation_info.presentation_id;
362 return; 361 return;
363 } 362 }
364 363
365 if (pid_route_it->second.is_offscreen_presentation()) { 364 if (pid_route_it->second.is_offscreen_presentation()) {
366 auto* offscreen_presentation_manager = 365 auto* offscreen_presentation_manager =
367 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( 366 OffscreenPresentationManagerFactory::GetOrCreateForWebContents(
368 web_contents_); 367 web_contents_);
369 offscreen_presentation_manager->RegisterOffscreenPresentationController( 368 offscreen_presentation_manager->RegisterOffscreenPresentationController(
370 session.presentation_id, session.presentation_url, 369 presentation_info.presentation_id, presentation_info.presentation_url,
371 render_frame_host_id_, std::move(controller_connection_ptr), 370 render_frame_host_id_, std::move(controller_connection_ptr),
372 std::move(receiver_connection_request), pid_route_it->second); 371 std::move(receiver_connection_request), pid_route_it->second);
373 } else { 372 } else {
374 DVLOG(2) 373 DVLOG(2)
375 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " 374 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: "
376 << session.presentation_id; 375 << presentation_info.presentation_id;
377 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); 376 MediaRoute::Id route_id = pid_route_it->second.media_route_id();
378 auto* proxy = new BrowserPresentationConnectionProxy( 377 auto* proxy = new BrowserPresentationConnectionProxy(
379 router_, route_id, std::move(receiver_connection_request), 378 router_, route_id, std::move(receiver_connection_request),
380 std::move(controller_connection_ptr)); 379 std::move(controller_connection_ptr));
381 380
382 browser_connection_proxies_.insert( 381 browser_connection_proxies_.insert(
383 std::make_pair(route_id, base::WrapUnique(proxy))); 382 std::make_pair(route_id, base::WrapUnique(proxy)));
384 } 383 }
385 } 384 }
386 385
387 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. 386 // Used by PresentationServiceDelegateImpl to manage PresentationFrames.
388 class PresentationFrameManager { 387 class PresentationFrameManager {
389 public: 388 public:
390 PresentationFrameManager(content::WebContents* web_contents, 389 PresentationFrameManager(content::WebContents* web_contents,
391 MediaRouter* router); 390 MediaRouter* router);
392 ~PresentationFrameManager(); 391 ~PresentationFrameManager();
393 392
394 // Mirror corresponding APIs in PresentationServiceDelegateImpl. 393 // Mirror corresponding APIs in PresentationServiceDelegateImpl.
395 bool SetScreenAvailabilityListener( 394 bool SetScreenAvailabilityListener(
396 const RenderFrameHostId& render_frame_host_id, 395 const RenderFrameHostId& render_frame_host_id,
397 content::PresentationScreenAvailabilityListener* listener); 396 content::PresentationScreenAvailabilityListener* listener);
398 bool RemoveScreenAvailabilityListener( 397 bool RemoveScreenAvailabilityListener(
399 const RenderFrameHostId& render_frame_host_id, 398 const RenderFrameHostId& render_frame_host_id,
400 content::PresentationScreenAvailabilityListener* listener); 399 content::PresentationScreenAvailabilityListener* listener);
401 void ListenForConnectionStateChange( 400 void ListenForConnectionStateChange(
402 const RenderFrameHostId& render_frame_host_id, 401 const RenderFrameHostId& render_frame_host_id,
403 const content::PresentationSessionInfo& connection, 402 const content::PresentationInfo& connection,
404 const content::PresentationConnectionStateChangedCallback& 403 const content::PresentationConnectionStateChangedCallback&
405 state_changed_cb); 404 state_changed_cb);
406 void ListenForSessionMessages( 405 void ListenForConnectionMessages(
407 const RenderFrameHostId& render_frame_host_id, 406 const RenderFrameHostId& render_frame_host_id,
408 const content::PresentationSessionInfo& session, 407 const content::PresentationInfo& presentation_info,
409 const content::PresentationConnectionMessageCallback& message_cb); 408 const content::PresentationConnectionMessageCallback& message_cb);
410 409
411 // Sets or clears the default presentation request and callback for the given 410 // Sets or clears the default presentation request and callback for the given
412 // frame. Also sets / clears the default presentation requests for the owning 411 // frame. Also sets / clears the default presentation requests for the owning
413 // tab WebContents. 412 // tab WebContents.
414 void SetDefaultPresentationUrls( 413 void SetDefaultPresentationUrls(
415 const RenderFrameHostId& render_frame_host_id, 414 const RenderFrameHostId& render_frame_host_id,
416 const std::vector<GURL>& default_presentation_urls, 415 const std::vector<GURL>& default_presentation_urls,
417 const content::PresentationSessionStartedCallback& callback); 416 const content::PresentationConnectionCallback& callback);
418 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, 417 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id,
419 DelegateObserver* observer); 418 DelegateObserver* observer);
420 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); 419 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id);
421 void AddDefaultPresentationRequestObserver( 420 void AddDefaultPresentationRequestObserver(
422 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 421 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
423 observer); 422 observer);
424 void RemoveDefaultPresentationRequestObserver( 423 void RemoveDefaultPresentationRequestObserver(
425 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 424 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
426 observer); 425 observer);
427 void Reset(const RenderFrameHostId& render_frame_host_id); 426 void Reset(const RenderFrameHostId& render_frame_host_id);
428 void RemoveConnection(const RenderFrameHostId& render_frame_host_id, 427 void RemoveConnection(const RenderFrameHostId& render_frame_host_id,
429 const MediaRoute::Id& route_id, 428 const MediaRoute::Id& route_id,
430 const std::string& presentation_id); 429 const std::string& presentation_id);
431 bool HasScreenAvailabilityListenerForTest( 430 bool HasScreenAvailabilityListenerForTest(
432 const RenderFrameHostId& render_frame_host_id, 431 const RenderFrameHostId& render_frame_host_id,
433 const MediaSource::Id& source_id) const; 432 const MediaSource::Id& source_id) const;
434 void SetMediaRouterForTest(MediaRouter* router); 433 void SetMediaRouterForTest(MediaRouter* router);
435 434
436 void OnPresentationSessionStarted( 435 void OnPresentationConnection(
437 const RenderFrameHostId& render_frame_host_id, 436 const RenderFrameHostId& render_frame_host_id,
438 const content::PresentationSessionInfo& session, 437 const content::PresentationInfo& presentation_info,
439 const MediaRoute& route); 438 const MediaRoute& route);
440 void OnDefaultPresentationSessionStarted( 439 void OnDefaultPresentationStarted(
441 const PresentationRequest& request, 440 const PresentationRequest& request,
442 const content::PresentationSessionInfo& session, 441 const content::PresentationInfo& presentation_info,
443 const MediaRoute& route); 442 const MediaRoute& route);
444 443
445 void ConnectToPresentation( 444 void ConnectToPresentation(
446 const RenderFrameHostId& render_frame_host_id, 445 const RenderFrameHostId& render_frame_host_id,
447 const content::PresentationSessionInfo& session, 446 const content::PresentationInfo& presentation_info,
448 content::PresentationConnectionPtr controller_connection_ptr, 447 content::PresentationConnectionPtr controller_connection_ptr,
449 content::PresentationConnectionRequest receiver_connection_request); 448 content::PresentationConnectionRequest receiver_connection_request);
450 449
451 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, 450 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id,
452 const std::string& presentation_id) const; 451 const std::string& presentation_id) const;
453 452
454 const PresentationRequest* default_presentation_request() const { 453 const PresentationRequest* default_presentation_request() const {
455 return default_presentation_request_.get(); 454 return default_presentation_request_.get();
456 } 455 }
457 456
(...skipping 16 matching lines...) Expand all
474 // Maps a frame identifier to a PresentationFrame object for frames 473 // Maps a frame identifier to a PresentationFrame object for frames
475 // that are using presentation API. 474 // that are using presentation API.
476 std::unordered_map<RenderFrameHostId, std::unique_ptr<PresentationFrame>, 475 std::unordered_map<RenderFrameHostId, std::unique_ptr<PresentationFrame>,
477 RenderFrameHostIdHasher> 476 RenderFrameHostIdHasher>
478 presentation_frames_; 477 presentation_frames_;
479 478
480 // Default presentation request for the owning tab WebContents. 479 // Default presentation request for the owning tab WebContents.
481 std::unique_ptr<PresentationRequest> default_presentation_request_; 480 std::unique_ptr<PresentationRequest> default_presentation_request_;
482 481
483 // Callback to invoke when default presentation has started. 482 // Callback to invoke when default presentation has started.
484 content::PresentationSessionStartedCallback 483 content::PresentationConnectionCallback
485 default_presentation_started_callback_; 484 default_presentation_started_callback_;
486 485
487 // References to the observers listening for changes to this tab WebContent's 486 // References to the observers listening for changes to this tab WebContent's
488 // default presentation. 487 // default presentation.
489 base::ObserverList< 488 base::ObserverList<
490 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver> 489 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver>
491 default_presentation_request_observers_; 490 default_presentation_request_observers_;
492 491
493 // References to the owning WebContents, and the corresponding MediaRouter. 492 // References to the owning WebContents, and the corresponding MediaRouter.
494 MediaRouter* router_; 493 MediaRouter* router_;
495 content::WebContents* web_contents_; 494 content::WebContents* web_contents_;
496 }; 495 };
497 496
498 PresentationFrameManager::PresentationFrameManager( 497 PresentationFrameManager::PresentationFrameManager(
499 content::WebContents* web_contents, 498 content::WebContents* web_contents,
500 MediaRouter* router) 499 MediaRouter* router)
501 : router_(router), web_contents_(web_contents) { 500 : router_(router), web_contents_(web_contents) {
502 DCHECK(web_contents_); 501 DCHECK(web_contents_);
503 DCHECK(router_); 502 DCHECK(router_);
504 } 503 }
505 504
506 PresentationFrameManager::~PresentationFrameManager() {} 505 PresentationFrameManager::~PresentationFrameManager() {}
507 506
508 void PresentationFrameManager::OnPresentationSessionStarted( 507 void PresentationFrameManager::OnPresentationConnection(
509 const RenderFrameHostId& render_frame_host_id, 508 const RenderFrameHostId& render_frame_host_id,
510 const content::PresentationSessionInfo& session, 509 const content::PresentationInfo& presentation_info,
511 const MediaRoute& route) { 510 const MediaRoute& route) {
512 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 511 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
513 presentation_frame->OnPresentationSessionStarted(session, route); 512 presentation_frame->OnPresentationConnection(presentation_info, route);
514 } 513 }
515 514
516 void PresentationFrameManager::OnDefaultPresentationSessionStarted( 515 void PresentationFrameManager::OnDefaultPresentationStarted(
517 const PresentationRequest& request, 516 const PresentationRequest& request,
518 const content::PresentationSessionInfo& session, 517 const content::PresentationInfo& presentation_info,
519 const MediaRoute& route) { 518 const MediaRoute& route) {
520 OnPresentationSessionStarted(request.render_frame_host_id(), session, route); 519 OnPresentationConnection(request.render_frame_host_id(), presentation_info,
520 route);
521 521
522 if (default_presentation_request_ && 522 if (default_presentation_request_ &&
523 default_presentation_request_->Equals(request)) { 523 default_presentation_request_->Equals(request)) {
524 default_presentation_started_callback_.Run(session); 524 default_presentation_started_callback_.Run(presentation_info);
525 } 525 }
526 } 526 }
527 527
528 void PresentationFrameManager::ConnectToPresentation( 528 void PresentationFrameManager::ConnectToPresentation(
529 const RenderFrameHostId& render_frame_host_id, 529 const RenderFrameHostId& render_frame_host_id,
530 const content::PresentationSessionInfo& session, 530 const content::PresentationInfo& presentation_info,
531 content::PresentationConnectionPtr controller_connection_ptr, 531 content::PresentationConnectionPtr controller_connection_ptr,
532 content::PresentationConnectionRequest receiver_connection_request) { 532 content::PresentationConnectionRequest receiver_connection_request) {
533 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 533 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
534 presentation_frame->ConnectToPresentation( 534 presentation_frame->ConnectToPresentation(
535 session, std::move(controller_connection_ptr), 535 presentation_info, std::move(controller_connection_ptr),
536 std::move(receiver_connection_request)); 536 std::move(receiver_connection_request));
537 } 537 }
538 538
539 const MediaRoute::Id PresentationFrameManager::GetRouteId( 539 const MediaRoute::Id PresentationFrameManager::GetRouteId(
540 const RenderFrameHostId& render_frame_host_id, 540 const RenderFrameHostId& render_frame_host_id,
541 const std::string& presentation_id) const { 541 const std::string& presentation_id) const {
542 const auto it = presentation_frames_.find(render_frame_host_id); 542 const auto it = presentation_frames_.find(render_frame_host_id);
543 return it != presentation_frames_.end() 543 return it != presentation_frames_.end()
544 ? it->second->GetRouteId(presentation_id) 544 ? it->second->GetRouteId(presentation_id)
545 : MediaRoute::Id(); 545 : MediaRoute::Id();
(...skipping 19 matching lines...) Expand all
565 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( 565 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest(
566 const RenderFrameHostId& render_frame_host_id, 566 const RenderFrameHostId& render_frame_host_id,
567 const MediaSource::Id& source_id) const { 567 const MediaSource::Id& source_id) const {
568 const auto it = presentation_frames_.find(render_frame_host_id); 568 const auto it = presentation_frames_.find(render_frame_host_id);
569 return it != presentation_frames_.end() && 569 return it != presentation_frames_.end() &&
570 it->second->HasScreenAvailabilityListenerForTest(source_id); 570 it->second->HasScreenAvailabilityListenerForTest(source_id);
571 } 571 }
572 572
573 void PresentationFrameManager::ListenForConnectionStateChange( 573 void PresentationFrameManager::ListenForConnectionStateChange(
574 const RenderFrameHostId& render_frame_host_id, 574 const RenderFrameHostId& render_frame_host_id,
575 const content::PresentationSessionInfo& connection, 575 const content::PresentationInfo& connection,
576 const content::PresentationConnectionStateChangedCallback& 576 const content::PresentationConnectionStateChangedCallback&
577 state_changed_cb) { 577 state_changed_cb) {
578 const auto it = presentation_frames_.find(render_frame_host_id); 578 const auto it = presentation_frames_.find(render_frame_host_id);
579 if (it != presentation_frames_.end()) 579 if (it != presentation_frames_.end())
580 it->second->ListenForConnectionStateChange(connection, state_changed_cb); 580 it->second->ListenForConnectionStateChange(connection, state_changed_cb);
581 } 581 }
582 582
583 void PresentationFrameManager::ListenForSessionMessages( 583 void PresentationFrameManager::ListenForConnectionMessages(
584 const RenderFrameHostId& render_frame_host_id, 584 const RenderFrameHostId& render_frame_host_id,
585 const content::PresentationSessionInfo& session, 585 const content::PresentationInfo& presentation_info,
586 const content::PresentationConnectionMessageCallback& message_cb) { 586 const content::PresentationConnectionMessageCallback& message_cb) {
587 const auto it = presentation_frames_.find(render_frame_host_id); 587 const auto it = presentation_frames_.find(render_frame_host_id);
588 if (it == presentation_frames_.end()) { 588 if (it == presentation_frames_.end()) {
589 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " 589 DVLOG(2) << "ListenForConnectionMessages: PresentationFrame does not exist "
590 << "for: (" << render_frame_host_id.first << ", " 590 << "for: (" << render_frame_host_id.first << ", "
591 << render_frame_host_id.second << ")"; 591 << render_frame_host_id.second << ")";
592 return; 592 return;
593 } 593 }
594 it->second->ListenForSessionMessages(session, message_cb); 594 it->second->ListenForConnectionMessages(presentation_info, message_cb);
595 } 595 }
596 596
597 void PresentationFrameManager::SetDefaultPresentationUrls( 597 void PresentationFrameManager::SetDefaultPresentationUrls(
598 const RenderFrameHostId& render_frame_host_id, 598 const RenderFrameHostId& render_frame_host_id,
599 const std::vector<GURL>& default_presentation_urls, 599 const std::vector<GURL>& default_presentation_urls,
600 const content::PresentationSessionStartedCallback& callback) { 600 const content::PresentationConnectionCallback& callback) {
601 if (!IsMainFrame(render_frame_host_id)) 601 if (!IsMainFrame(render_frame_host_id))
602 return; 602 return;
603 603
604 if (default_presentation_urls.empty()) { 604 if (default_presentation_urls.empty()) {
605 ClearDefaultPresentationRequest(); 605 ClearDefaultPresentationRequest();
606 } else { 606 } else {
607 DCHECK(!callback.is_null()); 607 DCHECK(!callback.is_null());
608 const auto& frame_origin = 608 const auto& frame_origin =
609 GetLastCommittedURLForFrame(render_frame_host_id); 609 GetLastCommittedURLForFrame(render_frame_host_id);
610 PresentationRequest request(render_frame_host_id, default_presentation_urls, 610 PresentationRequest request(render_frame_host_id, default_presentation_urls,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 void PresentationServiceDelegateImpl::Reset(int render_process_id, 749 void PresentationServiceDelegateImpl::Reset(int render_process_id,
750 int render_frame_id) { 750 int render_frame_id) {
751 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 751 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
752 frame_manager_->Reset(render_frame_host_id); 752 frame_manager_->Reset(render_frame_host_id);
753 } 753 }
754 754
755 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( 755 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls(
756 int render_process_id, 756 int render_process_id,
757 int render_frame_id, 757 int render_frame_id,
758 const std::vector<GURL>& default_presentation_urls, 758 const std::vector<GURL>& default_presentation_urls,
759 const content::PresentationSessionStartedCallback& callback) { 759 const content::PresentationConnectionCallback& callback) {
760 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 760 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
761 frame_manager_->SetDefaultPresentationUrls( 761 frame_manager_->SetDefaultPresentationUrls(
762 render_frame_host_id, default_presentation_urls, callback); 762 render_frame_host_id, default_presentation_urls, callback);
763 } 763 }
764 764
765 void PresentationServiceDelegateImpl::OnJoinRouteResponse( 765 void PresentationServiceDelegateImpl::OnJoinRouteResponse(
766 int render_process_id, 766 int render_process_id,
767 int render_frame_id, 767 int render_frame_id,
768 const GURL& presentation_url, 768 const GURL& presentation_url,
769 const std::string& presentation_id, 769 const std::string& presentation_id,
770 const content::PresentationSessionStartedCallback& success_cb, 770 const content::PresentationConnectionCallback& success_cb,
771 const content::PresentationSessionErrorCallback& error_cb, 771 const content::PresentationConnectionErrorCallback& error_cb,
772 const RouteRequestResult& result) { 772 const RouteRequestResult& result) {
773 if (!result.route()) { 773 if (!result.route()) {
774 error_cb.Run(content::PresentationError( 774 error_cb.Run(content::PresentationError(
775 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, result.error())); 775 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, result.error()));
776 } else { 776 } else {
777 DVLOG(1) << "OnJoinRouteResponse: " 777 DVLOG(1) << "OnJoinRouteResponse: "
778 << "route_id: " << result.route()->media_route_id() 778 << "route_id: " << result.route()->media_route_id()
779 << ", presentation URL: " << presentation_url 779 << ", presentation URL: " << presentation_url
780 << ", presentation ID: " << presentation_id; 780 << ", presentation ID: " << presentation_id;
781 DCHECK_EQ(presentation_id, result.presentation_id()); 781 DCHECK_EQ(presentation_id, result.presentation_id());
782 content::PresentationSessionInfo session(presentation_url, 782 content::PresentationInfo presentation_info(presentation_url,
783 result.presentation_id()); 783 result.presentation_id());
784 frame_manager_->OnPresentationSessionStarted( 784 frame_manager_->OnPresentationConnection(
785 RenderFrameHostId(render_process_id, render_frame_id), session, 785 RenderFrameHostId(render_process_id, render_frame_id),
786 *result.route()); 786 presentation_info, *result.route());
787 success_cb.Run(session); 787 success_cb.Run(presentation_info);
788 } 788 }
789 } 789 }
790 790
791 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( 791 void PresentationServiceDelegateImpl::OnStartPresentationSucceeded(
792 int render_process_id, 792 int render_process_id,
793 int render_frame_id, 793 int render_frame_id,
794 const content::PresentationSessionStartedCallback& success_cb, 794 const content::PresentationConnectionCallback& success_cb,
795 const content::PresentationSessionInfo& new_session, 795 const content::PresentationInfo& new_presentation_info,
796 const MediaRoute& route) { 796 const MediaRoute& route) {
797 DVLOG(1) << "OnStartSessionSucceeded: " 797 DVLOG(1) << "OnStartPresentationSucceeded: "
798 << "route_id: " << route.media_route_id() 798 << "route_id: " << route.media_route_id()
799 << ", presentation URL: " << new_session.presentation_url 799 << ", presentation URL: " << new_presentation_info.presentation_url
800 << ", presentation ID: " << new_session.presentation_id; 800 << ", presentation ID: " << new_presentation_info.presentation_id;
801 frame_manager_->OnPresentationSessionStarted( 801 frame_manager_->OnPresentationConnection(
802 RenderFrameHostId(render_process_id, render_frame_id), new_session, 802 RenderFrameHostId(render_process_id, render_frame_id),
803 route); 803 new_presentation_info, route);
804 success_cb.Run(new_session); 804 success_cb.Run(new_presentation_info);
805 } 805 }
806 806
807 void PresentationServiceDelegateImpl::StartSession( 807 void PresentationServiceDelegateImpl::StartPresentation(
808 int render_process_id, 808 int render_process_id,
809 int render_frame_id, 809 int render_frame_id,
810 const std::vector<GURL>& presentation_urls, 810 const std::vector<GURL>& presentation_urls,
811 const content::PresentationSessionStartedCallback& success_cb, 811 const content::PresentationConnectionCallback& success_cb,
812 const content::PresentationSessionErrorCallback& error_cb) { 812 const content::PresentationConnectionErrorCallback& error_cb) {
813 if (presentation_urls.empty()) { 813 if (presentation_urls.empty()) {
814 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 814 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
815 "Invalid presentation arguments.")); 815 "Invalid presentation arguments."));
816 return; 816 return;
817 } 817 }
818 818
819 // TODO(crbug.com/670848): Improve handling of invalid URLs in 819 // TODO(crbug.com/670848): Improve handling of invalid URLs in
820 // PresentationService::start(). 820 // PresentationService::start().
821 if (presentation_urls.empty() || 821 if (presentation_urls.empty() ||
822 std::find_if_not(presentation_urls.begin(), presentation_urls.end(), 822 std::find_if_not(presentation_urls.begin(), presentation_urls.end(),
823 IsValidPresentationUrl) != presentation_urls.end()) { 823 IsValidPresentationUrl) != presentation_urls.end()) {
824 error_cb.Run(content::PresentationError( 824 error_cb.Run(content::PresentationError(
825 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 825 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
826 "Invalid presentation URL.")); 826 "Invalid presentation URL."));
827 return; 827 return;
828 } 828 }
829 829
830 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 830 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
831 std::unique_ptr<CreatePresentationConnectionRequest> request( 831 std::unique_ptr<CreatePresentationConnectionRequest> request(
832 new CreatePresentationConnectionRequest( 832 new CreatePresentationConnectionRequest(
833 render_frame_host_id, presentation_urls, 833 render_frame_host_id, presentation_urls,
834 GetLastCommittedURLForFrame(render_frame_host_id), 834 GetLastCommittedURLForFrame(render_frame_host_id),
835 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, 835 base::Bind(
836 weak_factory_.GetWeakPtr(), render_process_id, 836 &PresentationServiceDelegateImpl::OnStartPresentationSucceeded,
837 render_frame_id, success_cb), 837 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id,
838 success_cb),
838 error_cb)); 839 error_cb));
839 MediaRouterDialogController* controller = 840 MediaRouterDialogController* controller =
840 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); 841 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_);
841 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { 842 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) {
842 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; 843 LOG(ERROR)
844 << "Media router dialog already exists. Ignoring StartPresentation.";
843 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 845 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
844 "Unable to create dialog.")); 846 "Unable to create dialog."));
845 return; 847 return;
846 } 848 }
847 } 849 }
848 850
849 void PresentationServiceDelegateImpl::JoinSession( 851 void PresentationServiceDelegateImpl::ReconnectPresentation(
850 int render_process_id, 852 int render_process_id,
851 int render_frame_id, 853 int render_frame_id,
852 const std::vector<GURL>& presentation_urls, 854 const std::vector<GURL>& presentation_urls,
853 const std::string& presentation_id, 855 const std::string& presentation_id,
854 const content::PresentationSessionStartedCallback& success_cb, 856 const content::PresentationConnectionCallback& success_cb,
855 const content::PresentationSessionErrorCallback& error_cb) { 857 const content::PresentationConnectionErrorCallback& error_cb) {
856 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession"; 858 DVLOG(2) << "PresentationServiceDelegateImpl::ReconnectPresentation";
857 if (presentation_urls.empty()) { 859 if (presentation_urls.empty()) {
858 error_cb.Run(content::PresentationError( 860 error_cb.Run(content::PresentationError(
859 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 861 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
860 "Invalid presentation arguments.")); 862 "Invalid presentation arguments."));
861 return; 863 return;
862 } 864 }
863 865
864 const url::Origin& origin = GetLastCommittedURLForFrame( 866 const url::Origin& origin = GetLastCommittedURLForFrame(
865 RenderFrameHostId(render_process_id, render_frame_id)); 867 RenderFrameHostId(render_process_id, render_frame_id));
866 868
867 #if !defined(OS_ANDROID) 869 #if !defined(OS_ANDROID)
868 if (IsAutoJoinPresentationId(presentation_id) && 870 if (IsAutoJoinPresentationId(presentation_id) &&
869 ShouldCancelAutoJoinForOrigin(origin)) { 871 ShouldCancelAutoJoinForOrigin(origin)) {
870 error_cb.Run(content::PresentationError( 872 error_cb.Run(content::PresentationError(
871 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 873 content::PRESENTATION_ERROR_PRESENTATION_REQUEST_CANCELLED,
872 "Auto-join request cancelled by user preferences.")); 874 "Auto-join request cancelled by user preferences."));
873 return; 875 return;
874 } 876 }
875 #endif // !defined(OS_ANDROID) 877 #endif // !defined(OS_ANDROID)
876 878
877 auto* offscreen_presentation_manager = 879 auto* offscreen_presentation_manager =
878 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( 880 OffscreenPresentationManagerFactory::GetOrCreateForWebContents(
879 web_contents_); 881 web_contents_);
880 // Check offscreen presentation across frames. 882 // Check offscreen presentation across frames.
881 if (offscreen_presentation_manager->IsOffscreenPresentation( 883 if (offscreen_presentation_manager->IsOffscreenPresentation(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 DVLOG(1) << "No active route for: " << presentation_id; 955 DVLOG(1) << "No active route for: " << presentation_id;
954 return; 956 return;
955 } 957 }
956 router_->TerminateRoute(route_id); 958 router_->TerminateRoute(route_id);
957 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); 959 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id);
958 } 960 }
959 961
960 void PresentationServiceDelegateImpl::ListenForConnectionMessages( 962 void PresentationServiceDelegateImpl::ListenForConnectionMessages(
961 int render_process_id, 963 int render_process_id,
962 int render_frame_id, 964 int render_frame_id,
963 const content::PresentationSessionInfo& session, 965 const content::PresentationInfo& presentation_info,
964 const content::PresentationConnectionMessageCallback& message_cb) { 966 const content::PresentationConnectionMessageCallback& message_cb) {
965 frame_manager_->ListenForSessionMessages( 967 frame_manager_->ListenForConnectionMessages(
966 RenderFrameHostId(render_process_id, render_frame_id), session, 968 RenderFrameHostId(render_process_id, render_frame_id), presentation_info,
967 message_cb); 969 message_cb);
968 } 970 }
969 971
970 void PresentationServiceDelegateImpl::SendMessage( 972 void PresentationServiceDelegateImpl::SendMessage(
971 int render_process_id, 973 int render_process_id,
972 int render_frame_id, 974 int render_frame_id,
973 const content::PresentationSessionInfo& session, 975 const content::PresentationInfo& presentation_info,
974 content::PresentationConnectionMessage message, 976 content::PresentationConnectionMessage message,
975 const SendMessageCallback& send_message_cb) { 977 const SendMessageCallback& send_message_cb) {
976 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( 978 const MediaRoute::Id& route_id = frame_manager_->GetRouteId(
977 RenderFrameHostId(render_process_id, render_frame_id), 979 RenderFrameHostId(render_process_id, render_frame_id),
978 session.presentation_id); 980 presentation_info.presentation_id);
979 if (route_id.empty()) { 981 if (route_id.empty()) {
980 DVLOG(1) << "No active route for " << session.presentation_id; 982 DVLOG(1) << "No active route for " << presentation_info.presentation_id;
981 send_message_cb.Run(false); 983 send_message_cb.Run(false);
982 return; 984 return;
983 } 985 }
984 986
985 if (message.is_binary()) { 987 if (message.is_binary()) {
986 router_->SendRouteBinaryMessage( 988 router_->SendRouteBinaryMessage(
987 route_id, 989 route_id,
988 base::MakeUnique<std::vector<uint8_t>>(std::move(message.data.value())), 990 base::MakeUnique<std::vector<uint8_t>>(std::move(message.data.value())),
989 send_message_cb); 991 send_message_cb);
990 } else { 992 } else {
991 router_->SendRouteMessage(route_id, message.message.value(), 993 router_->SendRouteMessage(route_id, message.message.value(),
992 send_message_cb); 994 send_message_cb);
993 } 995 }
994 } 996 }
995 997
996 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( 998 void PresentationServiceDelegateImpl::ListenForConnectionStateChange(
997 int render_process_id, 999 int render_process_id,
998 int render_frame_id, 1000 int render_frame_id,
999 const content::PresentationSessionInfo& connection, 1001 const content::PresentationInfo& connection,
1000 const content::PresentationConnectionStateChangedCallback& 1002 const content::PresentationConnectionStateChangedCallback&
1001 state_changed_cb) { 1003 state_changed_cb) {
1002 frame_manager_->ListenForConnectionStateChange( 1004 frame_manager_->ListenForConnectionStateChange(
1003 RenderFrameHostId(render_process_id, render_frame_id), connection, 1005 RenderFrameHostId(render_process_id, render_frame_id), connection,
1004 state_changed_cb); 1006 state_changed_cb);
1005 } 1007 }
1006 1008
1007 void PresentationServiceDelegateImpl::ConnectToPresentation( 1009 void PresentationServiceDelegateImpl::ConnectToPresentation(
1008 int render_process_id, 1010 int render_process_id,
1009 int render_frame_id, 1011 int render_frame_id,
1010 const content::PresentationSessionInfo& session, 1012 const content::PresentationInfo& presentation_info,
1011 content::PresentationConnectionPtr controller_connection_ptr, 1013 content::PresentationConnectionPtr controller_connection_ptr,
1012 content::PresentationConnectionRequest receiver_connection_request) { 1014 content::PresentationConnectionRequest receiver_connection_request) {
1013 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 1015 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
1014 frame_manager_->ConnectToPresentation(render_frame_host_id, session, 1016 frame_manager_->ConnectToPresentation(render_frame_host_id, presentation_info,
1015 std::move(controller_connection_ptr), 1017 std::move(controller_connection_ptr),
1016 std::move(receiver_connection_request)); 1018 std::move(receiver_connection_request));
1017 } 1019 }
1018 1020
1019 void PresentationServiceDelegateImpl::OnRouteResponse( 1021 void PresentationServiceDelegateImpl::OnRouteResponse(
1020 const PresentationRequest& presentation_request, 1022 const PresentationRequest& presentation_request,
1021 const RouteRequestResult& result) { 1023 const RouteRequestResult& result) {
1022 if (!result.route() || 1024 if (!result.route() ||
1023 !base::ContainsValue(presentation_request.presentation_urls(), 1025 !base::ContainsValue(presentation_request.presentation_urls(),
1024 result.presentation_url())) { 1026 result.presentation_url())) {
1025 return; 1027 return;
1026 } 1028 }
1027 1029
1028 content::PresentationSessionInfo session_info(result.presentation_url(), 1030 content::PresentationInfo presentation_info(result.presentation_url(),
1029 result.presentation_id()); 1031 result.presentation_id());
1030 frame_manager_->OnDefaultPresentationSessionStarted( 1032 frame_manager_->OnDefaultPresentationStarted(
1031 presentation_request, session_info, *result.route()); 1033 presentation_request, presentation_info, *result.route());
1032 } 1034 }
1033 1035
1034 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( 1036 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver(
1035 DefaultPresentationRequestObserver* observer) { 1037 DefaultPresentationRequestObserver* observer) {
1036 frame_manager_->AddDefaultPresentationRequestObserver(observer); 1038 frame_manager_->AddDefaultPresentationRequestObserver(observer);
1037 } 1039 }
1038 1040
1039 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( 1041 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver(
1040 DefaultPresentationRequestObserver* observer) { 1042 DefaultPresentationRequestObserver* observer) {
1041 frame_manager_->RemoveDefaultPresentationRequestObserver(observer); 1043 frame_manager_->RemoveDefaultPresentationRequestObserver(observer);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 const base::ListValue* origins = 1079 const base::ListValue* origins =
1078 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) 1080 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
1079 ->GetPrefs() 1081 ->GetPrefs()
1080 ->GetList(prefs::kMediaRouterTabMirroringSources); 1082 ->GetList(prefs::kMediaRouterTabMirroringSources);
1081 return origins && 1083 return origins &&
1082 origins->Find(base::Value(origin.Serialize())) != origins->end(); 1084 origins->Find(base::Value(origin.Serialize())) != origins->end();
1083 } 1085 }
1084 #endif // !defined(OS_ANDROID) 1086 #endif // !defined(OS_ANDROID)
1085 1087
1086 } // namespace media_router 1088 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698