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

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: fix windows compile error Created 3 years, 11 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 "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 110 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
111 blink::mojom::PresentationError::From(PresentationError( 111 blink::mojom::PresentationError::From(PresentationError(
112 PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 112 PRESENTATION_ERROR_UNKNOWN, "Internal error")));
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 PresentationServiceImpl::PresentationServiceImpl( 117 PresentationServiceImpl::PresentationServiceImpl(
118 RenderFrameHost* render_frame_host, 118 RenderFrameHost* render_frame_host,
119 WebContents* web_contents, 119 WebContents* web_contents,
120 PresentationServiceDelegate* delegate) 120 ControllerPresentationServiceDelegate* controller_delegate,
121 ReceiverPresentationServiceDelegate* receiver_delegate)
121 : WebContentsObserver(web_contents), 122 : WebContentsObserver(web_contents),
122 delegate_(delegate), 123 controller_delegate_(controller_delegate),
124 receiver_delegate_(receiver_delegate),
123 start_session_request_id_(kInvalidRequestSessionId), 125 start_session_request_id_(kInvalidRequestSessionId),
124 weak_factory_(this) { 126 weak_factory_(this) {
125 DCHECK(render_frame_host); 127 DCHECK(render_frame_host);
126 DCHECK(web_contents); 128 DCHECK(web_contents);
127 CHECK(render_frame_host->IsRenderFrameLive()); 129 CHECK(render_frame_host->IsRenderFrameLive());
128 130
129 render_process_id_ = render_frame_host->GetProcess()->GetID(); 131 render_process_id_ = render_frame_host->GetProcess()->GetID();
130 render_frame_id_ = render_frame_host->GetRoutingID(); 132 render_frame_id_ = render_frame_host->GetRoutingID();
131 DVLOG(2) << "PresentationServiceImpl: " 133 DVLOG(2) << "PresentationServiceImpl: "
132 << render_process_id_ << ", " << render_frame_id_; 134 << render_process_id_ << ", " << render_frame_id_;
133 if (delegate_) 135
134 delegate_->AddObserver(render_process_id_, render_frame_id_, this); 136 if (auto* delegate = GetPresentationServiceDelegate())
137 delegate->AddObserver(render_process_id_, render_frame_id_, this);
135 } 138 }
136 139
137 PresentationServiceImpl::~PresentationServiceImpl() { 140 PresentationServiceImpl::~PresentationServiceImpl() {
138 if (delegate_) 141 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", "
139 delegate_->RemoveObserver(render_process_id_, render_frame_id_); 142 << render_frame_id_;
143
144 if (auto* delegate = GetPresentationServiceDelegate())
145 delegate->RemoveObserver(render_process_id_, render_frame_id_);
140 } 146 }
141 147
142 // static 148 // static
143 void PresentationServiceImpl::CreateMojoService( 149 void PresentationServiceImpl::CreateMojoService(
144 RenderFrameHost* render_frame_host, 150 RenderFrameHost* render_frame_host,
145 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 151 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
146 DVLOG(2) << "CreateMojoService"; 152 DVLOG(2) << "CreateMojoService";
147 WebContents* web_contents = 153 WebContents* web_contents =
148 WebContents::FromRenderFrameHost(render_frame_host); 154 WebContents::FromRenderFrameHost(render_frame_host);
149 DCHECK(web_contents); 155 DCHECK(web_contents);
150 156
157 auto* browser = GetContentClient()->browser();
158 auto* receiver_delegate =
159 browser->GetReceiverPresentationServiceDelegate(web_contents);
160
161 // In current implementation, web_contents can be controller or receiver
162 // but not both.
163 auto* controller_delegate =
164 receiver_delegate
165 ? nullptr
166 : browser->GetControllerPresentationServiceDelegate(web_contents);
167
151 // This object will be deleted when the RenderFrameHost is about to be 168 // This object will be deleted when the RenderFrameHost is about to be
152 // deleted (RenderFrameDeleted). 169 // deleted (RenderFrameDeleted).
153 PresentationServiceImpl* impl = new PresentationServiceImpl( 170 PresentationServiceImpl* impl = new PresentationServiceImpl(
154 render_frame_host, 171 render_frame_host, web_contents, controller_delegate, receiver_delegate);
155 web_contents,
156 GetContentClient()->browser()->GetPresentationServiceDelegate(
157 web_contents));
158 impl->Bind(std::move(request)); 172 impl->Bind(std::move(request));
159 } 173 }
160 174
161 void PresentationServiceImpl::Bind( 175 void PresentationServiceImpl::Bind(
162 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 176 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
163 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 177 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>(
164 this, std::move(request))); 178 this, std::move(request)));
165 } 179 }
166 180
167 void PresentationServiceImpl::SetClient( 181 void PresentationServiceImpl::SetClient(
168 blink::mojom::PresentationServiceClientPtr client) { 182 blink::mojom::PresentationServiceClientPtr client) {
169 DCHECK(!client_.get()); 183 DCHECK(!client_.get());
170 // TODO(imcheng): Set ErrorHandler to listen for errors. 184 // TODO(imcheng): Set ErrorHandler to listen for errors.
171 client_ = std::move(client); 185 client_ = std::move(client);
186
187 if (receiver_delegate_) {
188 receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
189 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
190 weak_factory_.GetWeakPtr()));
191 }
172 } 192 }
173 193
174 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { 194 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
175 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); 195 DVLOG(2) << "ListenForScreenAvailability " << url.spec();
176 if (!delegate_) { 196 if (!controller_delegate_) {
177 client_->OnScreenAvailabilityUpdated(url, false); 197 client_->OnScreenAvailabilityUpdated(url, false);
178 return; 198 return;
179 } 199 }
180 200
181 if (screen_availability_listeners_.count(url)) 201 if (screen_availability_listeners_.count(url))
182 return; 202 return;
183 203
184 std::unique_ptr<ScreenAvailabilityListenerImpl> listener( 204 std::unique_ptr<ScreenAvailabilityListenerImpl> listener(
185 new ScreenAvailabilityListenerImpl(url, this)); 205 new ScreenAvailabilityListenerImpl(url, this));
186 if (delegate_->AddScreenAvailabilityListener( 206 if (controller_delegate_->AddScreenAvailabilityListener(
187 render_process_id_, 207 render_process_id_, render_frame_id_, listener.get())) {
188 render_frame_id_,
189 listener.get())) {
190 screen_availability_listeners_[url] = std::move(listener); 208 screen_availability_listeners_[url] = std::move(listener);
191 } else { 209 } else {
192 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; 210 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request.";
193 } 211 }
194 } 212 }
195 213
196 void PresentationServiceImpl::StopListeningForScreenAvailability( 214 void PresentationServiceImpl::StopListeningForScreenAvailability(
197 const GURL& url) { 215 const GURL& url) {
198 DVLOG(2) << "StopListeningForScreenAvailability " << url.spec(); 216 DVLOG(2) << "StopListeningForScreenAvailability " << url.spec();
199 if (!delegate_) 217 if (!controller_delegate_)
200 return; 218 return;
201 219
202 auto listener_it = screen_availability_listeners_.find(url); 220 auto listener_it = screen_availability_listeners_.find(url);
203 if (listener_it == screen_availability_listeners_.end()) 221 if (listener_it == screen_availability_listeners_.end())
204 return; 222 return;
205 223
206 delegate_->RemoveScreenAvailabilityListener( 224 controller_delegate_->RemoveScreenAvailabilityListener(
207 render_process_id_, render_frame_id_, listener_it->second.get()); 225 render_process_id_, render_frame_id_, listener_it->second.get());
208 screen_availability_listeners_.erase(listener_it); 226 screen_availability_listeners_.erase(listener_it);
209 } 227 }
210 228
211 void PresentationServiceImpl::StartSession( 229 void PresentationServiceImpl::StartSession(
212 const std::vector<GURL>& presentation_urls, 230 const std::vector<GURL>& presentation_urls,
213 const NewSessionCallback& callback) { 231 const NewSessionCallback& callback) {
214 DVLOG(2) << "StartSession"; 232 DVLOG(2) << "StartSession";
215 if (!delegate_) { 233 if (!controller_delegate_) {
216 callback.Run( 234 callback.Run(
217 blink::mojom::PresentationSessionInfoPtr(), 235 blink::mojom::PresentationSessionInfoPtr(),
218 blink::mojom::PresentationError::From(PresentationError( 236 blink::mojom::PresentationError::From(PresentationError(
219 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 237 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
220 return; 238 return;
221 } 239 }
222 240
223 // There is a StartSession request in progress. To avoid queueing up 241 // There is a StartSession request in progress. To avoid queueing up
224 // requests, the incoming request is rejected. 242 // requests, the incoming request is rejected.
225 if (start_session_request_id_ != kInvalidRequestSessionId) { 243 if (start_session_request_id_ != kInvalidRequestSessionId) {
226 InvokeNewSessionCallbackWithError(callback); 244 InvokeNewSessionCallbackWithError(callback);
227 return; 245 return;
228 } 246 }
229 247
230 start_session_request_id_ = GetNextRequestSessionId(); 248 start_session_request_id_ = GetNextRequestSessionId();
231 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 249 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
232 delegate_->StartSession( 250 controller_delegate_->StartSession(
233 render_process_id_, render_frame_id_, presentation_urls, 251 render_process_id_, render_frame_id_, presentation_urls,
234 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 252 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
235 weak_factory_.GetWeakPtr(), start_session_request_id_), 253 weak_factory_.GetWeakPtr(), start_session_request_id_),
236 base::Bind(&PresentationServiceImpl::OnStartSessionError, 254 base::Bind(&PresentationServiceImpl::OnStartSessionError,
237 weak_factory_.GetWeakPtr(), start_session_request_id_)); 255 weak_factory_.GetWeakPtr(), start_session_request_id_));
238 } 256 }
239 257
240 void PresentationServiceImpl::JoinSession( 258 void PresentationServiceImpl::JoinSession(
241 const std::vector<GURL>& presentation_urls, 259 const std::vector<GURL>& presentation_urls,
242 const base::Optional<std::string>& presentation_id, 260 const base::Optional<std::string>& presentation_id,
243 const NewSessionCallback& callback) { 261 const NewSessionCallback& callback) {
244 DVLOG(2) << "JoinSession"; 262 DVLOG(2) << "JoinSession";
245 if (!delegate_) { 263 if (!controller_delegate_) {
246 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 264 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
247 blink::mojom::PresentationError::From(PresentationError( 265 blink::mojom::PresentationError::From(PresentationError(
248 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 266 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
249 "Error joining route: No matching route"))); 267 "Error joining route: No matching route")));
250 return; 268 return;
251 } 269 }
252 270
253 int request_session_id = RegisterJoinSessionCallback(callback); 271 int request_session_id = RegisterJoinSessionCallback(callback);
254 if (request_session_id == kInvalidRequestSessionId) { 272 if (request_session_id == kInvalidRequestSessionId) {
255 InvokeNewSessionCallbackWithError(callback); 273 InvokeNewSessionCallbackWithError(callback);
256 return; 274 return;
257 } 275 }
258 delegate_->JoinSession( 276 controller_delegate_->JoinSession(
259 render_process_id_, render_frame_id_, presentation_urls, 277 render_process_id_, render_frame_id_, presentation_urls,
260 presentation_id.value_or(std::string()), 278 presentation_id.value_or(std::string()),
261 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 279 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
262 weak_factory_.GetWeakPtr(), request_session_id), 280 weak_factory_.GetWeakPtr(), request_session_id),
263 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 281 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
264 weak_factory_.GetWeakPtr(), request_session_id)); 282 weak_factory_.GetWeakPtr(), request_session_id));
265 } 283 }
266 284
267 int PresentationServiceImpl::RegisterJoinSessionCallback( 285 int PresentationServiceImpl::RegisterJoinSessionCallback(
268 const NewSessionCallback& callback) { 286 const NewSessionCallback& callback) {
269 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 287 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
270 return kInvalidRequestSessionId; 288 return kInvalidRequestSessionId;
271 289
272 int request_id = GetNextRequestSessionId(); 290 int request_id = GetNextRequestSessionId();
273 pending_join_session_cbs_[request_id].reset( 291 pending_join_session_cbs_[request_id].reset(
274 new NewSessionCallbackWrapper(callback)); 292 new NewSessionCallbackWrapper(callback));
275 return request_id; 293 return request_id;
276 } 294 }
277 295
278 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState( 296 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState(
279 const PresentationSessionInfo& connection) { 297 const PresentationSessionInfo& connection) {
280 if (delegate_) { 298 if (controller_delegate_) {
281 delegate_->ListenForConnectionStateChange( 299 controller_delegate_->ListenForConnectionStateChange(
282 render_process_id_, render_frame_id_, connection, 300 render_process_id_, render_frame_id_, connection,
283 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, 301 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged,
284 weak_factory_.GetWeakPtr(), connection)); 302 weak_factory_.GetWeakPtr(), connection));
285 OnConnectionStateChanged(connection, 303 OnConnectionStateChanged(connection,
286 PresentationConnectionStateChangeInfo( 304 PresentationConnectionStateChangeInfo(
287 PRESENTATION_CONNECTION_STATE_CONNECTED)); 305 PRESENTATION_CONNECTION_STATE_CONNECTED));
288 } 306 }
289 } 307 }
290 308
291 void PresentationServiceImpl::OnStartSessionSucceeded( 309 void PresentationServiceImpl::OnStartSessionSucceeded(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 363
346 DCHECK(it->second.get()); 364 DCHECK(it->second.get());
347 it->second->Run(std::move(session), std::move(error)); 365 it->second->Run(std::move(session), std::move(error));
348 pending_join_session_cbs_.erase(it); 366 pending_join_session_cbs_.erase(it);
349 return true; 367 return true;
350 } 368 }
351 369
352 void PresentationServiceImpl::SetDefaultPresentationUrls( 370 void PresentationServiceImpl::SetDefaultPresentationUrls(
353 const std::vector<GURL>& presentation_urls) { 371 const std::vector<GURL>& presentation_urls) {
354 DVLOG(2) << "SetDefaultPresentationUrls"; 372 DVLOG(2) << "SetDefaultPresentationUrls";
355 if (!delegate_) 373 if (!controller_delegate_)
356 return; 374 return;
357 375
358 if (default_presentation_urls_ == presentation_urls) 376 if (default_presentation_urls_ == presentation_urls)
359 return; 377 return;
360 378
361 default_presentation_urls_ = presentation_urls; 379 default_presentation_urls_ = presentation_urls;
362 delegate_->SetDefaultPresentationUrls( 380 controller_delegate_->SetDefaultPresentationUrls(
363 render_process_id_, render_frame_id_, presentation_urls, 381 render_process_id_, render_frame_id_, presentation_urls,
364 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 382 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
365 weak_factory_.GetWeakPtr())); 383 weak_factory_.GetWeakPtr()));
366 } 384 }
367 385
368 void PresentationServiceImpl::SendConnectionMessage( 386 void PresentationServiceImpl::SendConnectionMessage(
369 blink::mojom::PresentationSessionInfoPtr session, 387 blink::mojom::PresentationSessionInfoPtr session,
370 blink::mojom::ConnectionMessagePtr connection_message, 388 blink::mojom::ConnectionMessagePtr connection_message,
371 const SendConnectionMessageCallback& callback) { 389 const SendConnectionMessageCallback& callback) {
372 DVLOG(2) << "SendConnectionMessage"; 390 DVLOG(2) << "SendConnectionMessage"
391 << " [id]: " << session->id;
373 DCHECK(!connection_message.is_null()); 392 DCHECK(!connection_message.is_null());
374 // send_message_callback_ should be null by now, otherwise resetting of 393 // send_message_callback_ should be null by now, otherwise resetting of
375 // send_message_callback_ with new callback will drop the old callback. 394 // send_message_callback_ with new callback will drop the old callback.
376 if (!delegate_ || send_message_callback_) { 395 if (!controller_delegate_ || send_message_callback_) {
377 callback.Run(false); 396 callback.Run(false);
378 return; 397 return;
379 } 398 }
380 399
381 send_message_callback_.reset(new SendConnectionMessageCallback(callback)); 400 send_message_callback_.reset(new SendConnectionMessageCallback(callback));
382 delegate_->SendMessage( 401 controller_delegate_->SendMessage(
383 render_process_id_, render_frame_id_, 402 render_process_id_, render_frame_id_,
384 session.To<PresentationSessionInfo>(), 403 session.To<PresentationSessionInfo>(),
385 GetPresentationConnectionMessage(std::move(connection_message)), 404 GetPresentationConnectionMessage(std::move(connection_message)),
386 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, 405 base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
387 weak_factory_.GetWeakPtr())); 406 weak_factory_.GetWeakPtr()));
388 } 407 }
389 408
390 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { 409 void PresentationServiceImpl::OnSendMessageCallback(bool sent) {
391 // It is possible that Reset() is invoked before receiving this callback. 410 // It is possible that Reset() is invoked before receiving this callback.
392 // So, always check send_message_callback_ for non-null. 411 // So, always check send_message_callback_ for non-null.
393 if (send_message_callback_) { 412 if (send_message_callback_) {
394 send_message_callback_->Run(sent); 413 send_message_callback_->Run(sent);
395 send_message_callback_.reset(); 414 send_message_callback_.reset();
396 } 415 }
397 } 416 }
398 417
399 void PresentationServiceImpl::CloseConnection( 418 void PresentationServiceImpl::CloseConnection(
400 const GURL& presentation_url, 419 const GURL& presentation_url,
401 const std::string& presentation_id) { 420 const std::string& presentation_id) {
402 DVLOG(2) << "CloseConnection " << presentation_id; 421 DVLOG(2) << "CloseConnection " << presentation_id;
403 if (delegate_) 422 if (controller_delegate_)
404 delegate_->CloseConnection(render_process_id_, render_frame_id_, 423 controller_delegate_->CloseConnection(render_process_id_, render_frame_id_,
405 presentation_id); 424 presentation_id);
406 } 425 }
407 426
408 void PresentationServiceImpl::Terminate(const GURL& presentation_url, 427 void PresentationServiceImpl::Terminate(const GURL& presentation_url,
409 const std::string& presentation_id) { 428 const std::string& presentation_id) {
410 DVLOG(2) << "Terminate " << presentation_id; 429 DVLOG(2) << "Terminate " << presentation_id;
411 if (delegate_) 430 if (controller_delegate_)
412 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); 431 controller_delegate_->Terminate(render_process_id_, render_frame_id_,
432 presentation_id);
413 } 433 }
414 434
415 void PresentationServiceImpl::OnConnectionStateChanged( 435 void PresentationServiceImpl::OnConnectionStateChanged(
416 const PresentationSessionInfo& connection, 436 const PresentationSessionInfo& connection,
417 const PresentationConnectionStateChangeInfo& info) { 437 const PresentationConnectionStateChangeInfo& info) {
418 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " 438 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged "
419 << "[presentation_id]: " << connection.presentation_id 439 << "[presentation_id]: " << connection.presentation_id
420 << " [state]: " << info.state; 440 << " [state]: " << info.state;
421 DCHECK(client_.get()); 441 DCHECK(client_.get());
422 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { 442 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
(...skipping 10 matching lines...) Expand all
433 453
434 bool PresentationServiceImpl::FrameMatches( 454 bool PresentationServiceImpl::FrameMatches(
435 content::RenderFrameHost* render_frame_host) const { 455 content::RenderFrameHost* render_frame_host) const {
436 if (!render_frame_host) 456 if (!render_frame_host)
437 return false; 457 return false;
438 458
439 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 459 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
440 render_frame_host->GetRoutingID() == render_frame_id_; 460 render_frame_host->GetRoutingID() == render_frame_id_;
441 } 461 }
442 462
463 PresentationServiceDelegate*
464 PresentationServiceImpl::GetPresentationServiceDelegate() {
465 return receiver_delegate_
466 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_)
467 : static_cast<PresentationServiceDelegate*>(controller_delegate_);
468 }
469
443 void PresentationServiceImpl::ListenForConnectionMessages( 470 void PresentationServiceImpl::ListenForConnectionMessages(
444 blink::mojom::PresentationSessionInfoPtr session) { 471 blink::mojom::PresentationSessionInfoPtr session) {
445 DVLOG(2) << "ListenForConnectionMessages"; 472 DVLOG(2) << "ListenForConnectionMessages";
446 if (!delegate_) 473 if (!controller_delegate_)
447 return; 474 return;
448 475
449 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 476 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
450 delegate_->ListenForConnectionMessages( 477 controller_delegate_->ListenForConnectionMessages(
451 render_process_id_, render_frame_id_, session_info, 478 render_process_id_, render_frame_id_, session_info,
452 base::Bind(&PresentationServiceImpl::OnConnectionMessages, 479 base::Bind(&PresentationServiceImpl::OnConnectionMessages,
453 weak_factory_.GetWeakPtr(), session_info)); 480 weak_factory_.GetWeakPtr(), session_info));
454 } 481 }
455 482
483 void PresentationServiceImpl::SetPresentationConnection(
484 blink::mojom::PresentationSessionInfoPtr session,
485 blink::mojom::PresentationConnectionPtr controller_connection_ptr,
486 blink::mojom::PresentationConnectionRequest receiver_connection_request) {
487 DVLOG(2) << "SetPresentationConnection";
488
489 if (!controller_delegate_)
490 return;
491
492 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
493 controller_delegate_->ConnectToOffscreenPresentation(
494 render_process_id_, render_frame_id_, session_info,
495 std::move(controller_connection_ptr),
496 std::move(receiver_connection_request));
497 }
498
456 void PresentationServiceImpl::OnConnectionMessages( 499 void PresentationServiceImpl::OnConnectionMessages(
457 const PresentationSessionInfo& session, 500 const PresentationSessionInfo& session,
458 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, 501 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages,
459 bool pass_ownership) { 502 bool pass_ownership) {
460 DCHECK(client_); 503 DCHECK(client_);
461 504
462 DVLOG(2) << "OnConnectionMessages"; 505 DVLOG(2) << "OnConnectionMessages"
506 << " [id]: " << session.presentation_id;
463 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( 507 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages(
464 messages.size()); 508 messages.size());
465 std::transform( 509 std::transform(
466 messages.begin(), messages.end(), mojo_messages.begin(), 510 messages.begin(), messages.end(), mojo_messages.begin(),
467 [pass_ownership]( 511 [pass_ownership](
468 const std::unique_ptr<PresentationConnectionMessage>& message) { 512 const std::unique_ptr<PresentationConnectionMessage>& message) {
469 return ToMojoConnectionMessage(message.get(), pass_ownership); 513 return ToMojoConnectionMessage(message.get(), pass_ownership);
470 }); 514 });
471 515
472 client_->OnConnectionMessagesReceived( 516 client_->OnConnectionMessagesReceived(
473 blink::mojom::PresentationSessionInfo::From(session), 517 blink::mojom::PresentationSessionInfo::From(session),
474 std::move(mojo_messages)); 518 std::move(mojo_messages));
475 } 519 }
476 520
521 void PresentationServiceImpl::OnReceiverConnectionAvailable(
522 const content::PresentationSessionInfo& session_info,
523 PresentationConnectionPtr controller_connection_ptr,
524 PresentationConnectionRequest receiver_connection_request) {
525 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
526
527 client_->OnReceiverConnectionAvailable(
528 blink::mojom::PresentationSessionInfo::From(session_info),
529 std::move(controller_connection_ptr),
530 std::move(receiver_connection_request));
531 }
532
477 void PresentationServiceImpl::DidNavigateAnyFrame( 533 void PresentationServiceImpl::DidNavigateAnyFrame(
478 content::RenderFrameHost* render_frame_host, 534 content::RenderFrameHost* render_frame_host,
479 const content::LoadCommittedDetails& details, 535 const content::LoadCommittedDetails& details,
480 const content::FrameNavigateParams& params) { 536 const content::FrameNavigateParams& params) {
481 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 537 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
482 if (!FrameMatches(render_frame_host)) 538 if (!FrameMatches(render_frame_host))
483 return; 539 return;
484 540
485 std::string prev_url_host = details.previous_url.host(); 541 std::string prev_url_host = details.previous_url.host();
486 std::string curr_url_host = params.url.host(); 542 std::string curr_url_host = params.url.host();
(...skipping 25 matching lines...) Expand all
512 void PresentationServiceImpl::WebContentsDestroyed() { 568 void PresentationServiceImpl::WebContentsDestroyed() {
513 LOG(ERROR) << "PresentationServiceImpl is being deleted in " 569 LOG(ERROR) << "PresentationServiceImpl is being deleted in "
514 << "WebContentsDestroyed()! This shouldn't happen since it " 570 << "WebContentsDestroyed()! This shouldn't happen since it "
515 << "should've been deleted during RenderFrameDeleted()."; 571 << "should've been deleted during RenderFrameDeleted().";
516 Reset(); 572 Reset();
517 delete this; 573 delete this;
518 } 574 }
519 575
520 void PresentationServiceImpl::Reset() { 576 void PresentationServiceImpl::Reset() {
521 DVLOG(2) << "PresentationServiceImpl::Reset"; 577 DVLOG(2) << "PresentationServiceImpl::Reset";
522 if (delegate_) 578
523 delegate_->Reset(render_process_id_, render_frame_id_); 579 if (auto* delegate = GetPresentationServiceDelegate())
580 delegate->Reset(render_process_id_, render_frame_id_);
524 581
525 default_presentation_urls_.clear(); 582 default_presentation_urls_.clear();
526 583
527 screen_availability_listeners_.clear(); 584 screen_availability_listeners_.clear();
528 585
529 start_session_request_id_ = kInvalidRequestSessionId; 586 start_session_request_id_ = kInvalidRequestSessionId;
530 pending_start_session_cb_.reset(); 587 pending_start_session_cb_.reset();
531 588
532 pending_join_session_cbs_.clear(); 589 pending_join_session_cbs_.clear();
533 590
534 if (on_connection_messages_callback_.get()) { 591 if (on_connection_messages_callback_.get()) {
535 on_connection_messages_callback_->Run( 592 on_connection_messages_callback_->Run(
536 std::vector<blink::mojom::ConnectionMessagePtr>()); 593 std::vector<blink::mojom::ConnectionMessagePtr>());
537 on_connection_messages_callback_.reset(); 594 on_connection_messages_callback_.reset();
538 } 595 }
539 596
540 if (send_message_callback_) { 597 if (send_message_callback_) {
541 // Run the callback with false, indicating the renderer to stop sending 598 // Run the callback with false, indicating the renderer to stop sending
542 // the requests and invalidate all pending requests. 599 // the requests and invalidate all pending requests.
543 send_message_callback_->Run(false); 600 send_message_callback_->Run(false);
544 send_message_callback_.reset(); 601 send_message_callback_.reset();
545 } 602 }
546 } 603 }
547 604
548 void PresentationServiceImpl::OnDelegateDestroyed() { 605 void PresentationServiceImpl::OnDelegateDestroyed() {
549 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 606 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
550 delegate_ = nullptr; 607 controller_delegate_ = nullptr;
608 receiver_delegate_ = nullptr;
551 Reset(); 609 Reset();
552 } 610 }
553 611
554 void PresentationServiceImpl::OnDefaultPresentationStarted( 612 void PresentationServiceImpl::OnDefaultPresentationStarted(
555 const PresentationSessionInfo& connection) { 613 const PresentationSessionInfo& connection) {
556 DCHECK(client_.get()); 614 DCHECK(client_.get());
557 client_->OnDefaultSessionStarted( 615 client_->OnDefaultSessionStarted(
558 blink::mojom::PresentationSessionInfo::From(connection)); 616 blink::mojom::PresentationSessionInfo::From(connection));
559 ListenForConnectionStateChangeAndChangeState(connection); 617 ListenForConnectionStateChangeAndChangeState(connection);
560 } 618 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 657
600 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 658 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
601 blink::mojom::PresentationSessionInfoPtr session, 659 blink::mojom::PresentationSessionInfoPtr session,
602 blink::mojom::PresentationErrorPtr error) { 660 blink::mojom::PresentationErrorPtr error) {
603 DCHECK(!callback_.is_null()); 661 DCHECK(!callback_.is_null());
604 callback_.Run(std::move(session), std::move(error)); 662 callback_.Run(std::move(session), std::move(error));
605 callback_.Reset(); 663 callback_.Reset();
606 } 664 }
607 665
608 } // namespace content 666 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698