OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 const NewSessionMojoCallback& callback) { | 288 const NewSessionMojoCallback& callback) { |
289 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) | 289 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
290 return kInvalidRequestSessionId; | 290 return kInvalidRequestSessionId; |
291 | 291 |
292 int request_id = GetNextRequestSessionId(); | 292 int request_id = GetNextRequestSessionId(); |
293 pending_join_session_cbs_[request_id].reset( | 293 pending_join_session_cbs_[request_id].reset( |
294 new NewSessionMojoCallbackWrapper(callback)); | 294 new NewSessionMojoCallbackWrapper(callback)); |
295 return request_id; | 295 return request_id; |
296 } | 296 } |
297 | 297 |
| 298 void PresentationServiceImpl::ListenForConnectionStateChange( |
| 299 const PresentationSessionInfo& connection) { |
| 300 if (delegate_) { |
| 301 delegate_->ListenForConnectionStateChange( |
| 302 render_process_id_, render_frame_id_, connection, |
| 303 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, |
| 304 weak_factory_.GetWeakPtr(), connection)); |
| 305 } |
| 306 } |
| 307 |
298 void PresentationServiceImpl::OnStartSessionSucceeded( | 308 void PresentationServiceImpl::OnStartSessionSucceeded( |
299 int request_session_id, | 309 int request_session_id, |
300 const PresentationSessionInfo& session_info) { | 310 const PresentationSessionInfo& session_info) { |
301 if (request_session_id == start_session_request_id_) { | 311 if (request_session_id != start_session_request_id_) |
302 CHECK(pending_start_session_cb_.get()); | 312 return; |
303 pending_start_session_cb_->Run( | 313 |
304 presentation::PresentationSessionInfo::From(session_info), | 314 CHECK(pending_start_session_cb_.get()); |
305 presentation::PresentationErrorPtr()); | 315 pending_start_session_cb_->Run( |
306 pending_start_session_cb_.reset(); | 316 presentation::PresentationSessionInfo::From(session_info), |
307 start_session_request_id_ = kInvalidRequestSessionId; | 317 presentation::PresentationErrorPtr()); |
308 } | 318 ListenForConnectionStateChange(session_info); |
| 319 pending_start_session_cb_.reset(); |
| 320 start_session_request_id_ = kInvalidRequestSessionId; |
309 } | 321 } |
310 | 322 |
311 void PresentationServiceImpl::OnStartSessionError( | 323 void PresentationServiceImpl::OnStartSessionError( |
312 int request_session_id, | 324 int request_session_id, |
313 const PresentationError& error) { | 325 const PresentationError& error) { |
314 if (request_session_id == start_session_request_id_) { | 326 if (request_session_id != start_session_request_id_) |
315 CHECK(pending_start_session_cb_.get()); | 327 return; |
316 pending_start_session_cb_->Run( | 328 |
317 presentation::PresentationSessionInfoPtr(), | 329 CHECK(pending_start_session_cb_.get()); |
318 presentation::PresentationError::From(error)); | 330 pending_start_session_cb_->Run(presentation::PresentationSessionInfoPtr(), |
319 pending_start_session_cb_.reset(); | 331 presentation::PresentationError::From(error)); |
320 start_session_request_id_ = kInvalidRequestSessionId; | 332 pending_start_session_cb_.reset(); |
321 } | 333 start_session_request_id_ = kInvalidRequestSessionId; |
322 } | 334 } |
323 | 335 |
324 void PresentationServiceImpl::OnJoinSessionSucceeded( | 336 void PresentationServiceImpl::OnJoinSessionSucceeded( |
325 int request_session_id, | 337 int request_session_id, |
326 const PresentationSessionInfo& session_info) { | 338 const PresentationSessionInfo& session_info) { |
327 RunAndEraseJoinSessionMojoCallback( | 339 if (RunAndEraseJoinSessionMojoCallback( |
328 request_session_id, | 340 request_session_id, |
329 presentation::PresentationSessionInfo::From(session_info), | 341 presentation::PresentationSessionInfo::From(session_info), |
330 presentation::PresentationErrorPtr()); | 342 presentation::PresentationErrorPtr())) { |
| 343 ListenForConnectionStateChange(session_info); |
| 344 } |
331 } | 345 } |
332 | 346 |
333 void PresentationServiceImpl::OnJoinSessionError( | 347 void PresentationServiceImpl::OnJoinSessionError( |
334 int request_session_id, | 348 int request_session_id, |
335 const PresentationError& error) { | 349 const PresentationError& error) { |
336 RunAndEraseJoinSessionMojoCallback( | 350 RunAndEraseJoinSessionMojoCallback( |
337 request_session_id, | 351 request_session_id, |
338 presentation::PresentationSessionInfoPtr(), | 352 presentation::PresentationSessionInfoPtr(), |
339 presentation::PresentationError::From(error)); | 353 presentation::PresentationError::From(error)); |
340 } | 354 } |
341 | 355 |
342 void PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( | 356 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( |
343 int request_session_id, | 357 int request_session_id, |
344 presentation::PresentationSessionInfoPtr session, | 358 presentation::PresentationSessionInfoPtr session, |
345 presentation::PresentationErrorPtr error) { | 359 presentation::PresentationErrorPtr error) { |
346 auto it = pending_join_session_cbs_.find(request_session_id); | 360 auto it = pending_join_session_cbs_.find(request_session_id); |
347 if (it == pending_join_session_cbs_.end()) | 361 if (it == pending_join_session_cbs_.end()) |
348 return; | 362 return false; |
349 | 363 |
350 DCHECK(it->second.get()); | 364 DCHECK(it->second.get()); |
351 it->second->Run(session.Pass(), error.Pass()); | 365 it->second->Run(session.Pass(), error.Pass()); |
352 pending_join_session_cbs_.erase(it); | 366 pending_join_session_cbs_.erase(it); |
| 367 return true; |
353 } | 368 } |
354 | 369 |
355 void PresentationServiceImpl::SetDefaultPresentationURL( | 370 void PresentationServiceImpl::SetDefaultPresentationURL( |
356 const mojo::String& url) { | 371 const mojo::String& url) { |
357 DVLOG(2) << "SetDefaultPresentationURL"; | 372 DVLOG(2) << "SetDefaultPresentationURL"; |
358 if (!delegate_) | 373 if (!delegate_) |
359 return; | 374 return; |
360 | 375 |
361 const std::string& new_default_url = url.get(); | 376 const std::string& new_default_url = url.get(); |
362 if (default_presentation_url_ == new_default_url) | 377 if (default_presentation_url_ == new_default_url) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 417 |
403 void PresentationServiceImpl::CloseSession( | 418 void PresentationServiceImpl::CloseSession( |
404 const mojo::String& presentation_url, | 419 const mojo::String& presentation_url, |
405 const mojo::String& presentation_id) { | 420 const mojo::String& presentation_id) { |
406 DVLOG(2) << "CloseSession " << presentation_id; | 421 DVLOG(2) << "CloseSession " << presentation_id; |
407 if (delegate_) | 422 if (delegate_) |
408 delegate_->CloseSession(render_process_id_, render_frame_id_, | 423 delegate_->CloseSession(render_process_id_, render_frame_id_, |
409 presentation_id); | 424 presentation_id); |
410 } | 425 } |
411 | 426 |
412 void PresentationServiceImpl::ListenForSessionStateChange() { | 427 void PresentationServiceImpl::OnConnectionStateChanged( |
413 if (!delegate_) | 428 const PresentationSessionInfo& connection, |
414 return; | 429 PresentationConnectionState state) { |
415 | |
416 delegate_->ListenForSessionStateChange( | |
417 render_process_id_, render_frame_id_, | |
418 base::Bind(&PresentationServiceImpl::OnSessionStateChanged, | |
419 weak_factory_.GetWeakPtr())); | |
420 } | |
421 | |
422 void PresentationServiceImpl::OnSessionStateChanged( | |
423 const PresentationSessionInfo& session_info, | |
424 PresentationConnectionState session_state) { | |
425 DCHECK(client_.get()); | 430 DCHECK(client_.get()); |
426 client_->OnSessionStateChanged( | 431 client_->OnConnectionStateChanged( |
427 presentation::PresentationSessionInfo::From(session_info), | 432 presentation::PresentationSessionInfo::From(connection), |
428 PresentationConnectionStateToMojo(session_state)); | 433 PresentationConnectionStateToMojo(state)); |
429 } | 434 } |
430 | 435 |
431 bool PresentationServiceImpl::FrameMatches( | 436 bool PresentationServiceImpl::FrameMatches( |
432 content::RenderFrameHost* render_frame_host) const { | 437 content::RenderFrameHost* render_frame_host) const { |
433 if (!render_frame_host) | 438 if (!render_frame_host) |
434 return false; | 439 return false; |
435 | 440 |
436 return render_frame_host->GetProcess()->GetID() == render_process_id_ && | 441 return render_frame_host->GetProcess()->GetID() == render_process_id_ && |
437 render_frame_host->GetRoutingID() == render_frame_id_; | 442 render_frame_host->GetRoutingID() == render_frame_id_; |
438 } | 443 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 534 } |
530 } | 535 } |
531 | 536 |
532 void PresentationServiceImpl::OnDelegateDestroyed() { | 537 void PresentationServiceImpl::OnDelegateDestroyed() { |
533 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 538 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
534 delegate_ = nullptr; | 539 delegate_ = nullptr; |
535 Reset(); | 540 Reset(); |
536 } | 541 } |
537 | 542 |
538 void PresentationServiceImpl::OnDefaultPresentationStarted( | 543 void PresentationServiceImpl::OnDefaultPresentationStarted( |
539 const PresentationSessionInfo& session_info) { | 544 const PresentationSessionInfo& connection) { |
540 DCHECK(client_.get()); | 545 DCHECK(client_.get()); |
541 client_->OnDefaultSessionStarted( | 546 client_->OnDefaultSessionStarted( |
542 presentation::PresentationSessionInfo::From(session_info)); | 547 presentation::PresentationSessionInfo::From(connection)); |
| 548 ListenForConnectionStateChange(connection); |
543 } | 549 } |
544 | 550 |
545 PresentationServiceImpl::ScreenAvailabilityListenerImpl | 551 PresentationServiceImpl::ScreenAvailabilityListenerImpl |
546 ::ScreenAvailabilityListenerImpl( | 552 ::ScreenAvailabilityListenerImpl( |
547 const std::string& availability_url, | 553 const std::string& availability_url, |
548 PresentationServiceImpl* service) | 554 PresentationServiceImpl* service) |
549 : availability_url_(availability_url), | 555 : availability_url_(availability_url), |
550 service_(service) { | 556 service_(service) { |
551 DCHECK(service_); | 557 DCHECK(service_); |
552 DCHECK(service_->client_.get()); | 558 DCHECK(service_->client_.get()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 590 |
585 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( | 591 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
586 presentation::PresentationSessionInfoPtr session, | 592 presentation::PresentationSessionInfoPtr session, |
587 presentation::PresentationErrorPtr error) { | 593 presentation::PresentationErrorPtr error) { |
588 DCHECK(!callback_.is_null()); | 594 DCHECK(!callback_.is_null()); |
589 callback_.Run(session.Pass(), error.Pass()); | 595 callback_.Run(session.Pass(), error.Pass()); |
590 callback_.reset(); | 596 callback_.reset(); |
591 } | 597 } |
592 | 598 |
593 } // namespace content | 599 } // namespace content |
OLD | NEW |