| 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 <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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 const NewSessionCallback& callback) { | 277 const NewSessionCallback& callback) { |
| 278 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) | 278 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
| 279 return kInvalidRequestSessionId; | 279 return kInvalidRequestSessionId; |
| 280 | 280 |
| 281 int request_id = GetNextRequestSessionId(); | 281 int request_id = GetNextRequestSessionId(); |
| 282 pending_join_session_cbs_[request_id].reset( | 282 pending_join_session_cbs_[request_id].reset( |
| 283 new NewSessionCallbackWrapper(callback)); | 283 new NewSessionCallbackWrapper(callback)); |
| 284 return request_id; | 284 return request_id; |
| 285 } | 285 } |
| 286 | 286 |
| 287 void PresentationServiceImpl::ListenForConnectionStateChange( | 287 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState( |
| 288 const PresentationSessionInfo& connection) { | 288 const PresentationSessionInfo& connection) { |
| 289 if (delegate_) { | 289 if (delegate_) { |
| 290 delegate_->ListenForConnectionStateChange( | 290 delegate_->ListenForConnectionStateChange( |
| 291 render_process_id_, render_frame_id_, connection, | 291 render_process_id_, render_frame_id_, connection, |
| 292 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, | 292 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, |
| 293 weak_factory_.GetWeakPtr(), connection)); | 293 weak_factory_.GetWeakPtr(), connection)); |
| 294 OnConnectionStateChanged(connection, |
| 295 PresentationConnectionStateChangeInfo( |
| 296 PRESENTATION_CONNECTION_STATE_CONNECTED)); |
| 294 } | 297 } |
| 295 } | 298 } |
| 296 | 299 |
| 297 void PresentationServiceImpl::OnStartSessionSucceeded( | 300 void PresentationServiceImpl::OnStartSessionSucceeded( |
| 298 int request_session_id, | 301 int request_session_id, |
| 299 const PresentationSessionInfo& session_info) { | 302 const PresentationSessionInfo& session_info) { |
| 300 if (request_session_id != start_session_request_id_) | 303 if (request_session_id != start_session_request_id_) |
| 301 return; | 304 return; |
| 302 | 305 |
| 303 CHECK(pending_start_session_cb_.get()); | 306 CHECK(pending_start_session_cb_.get()); |
| 304 pending_start_session_cb_->Run( | 307 pending_start_session_cb_->Run( |
| 305 blink::mojom::PresentationSessionInfo::From(session_info), | 308 blink::mojom::PresentationSessionInfo::From(session_info), |
| 306 blink::mojom::PresentationErrorPtr()); | 309 blink::mojom::PresentationErrorPtr()); |
| 307 ListenForConnectionStateChange(session_info); | 310 ListenForConnectionStateChangeAndChangeState(session_info); |
| 308 pending_start_session_cb_.reset(); | 311 pending_start_session_cb_.reset(); |
| 309 start_session_request_id_ = kInvalidRequestSessionId; | 312 start_session_request_id_ = kInvalidRequestSessionId; |
| 310 } | 313 } |
| 311 | 314 |
| 312 void PresentationServiceImpl::OnStartSessionError( | 315 void PresentationServiceImpl::OnStartSessionError( |
| 313 int request_session_id, | 316 int request_session_id, |
| 314 const PresentationError& error) { | 317 const PresentationError& error) { |
| 315 if (request_session_id != start_session_request_id_) | 318 if (request_session_id != start_session_request_id_) |
| 316 return; | 319 return; |
| 317 | 320 |
| 318 CHECK(pending_start_session_cb_.get()); | 321 CHECK(pending_start_session_cb_.get()); |
| 319 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), | 322 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), |
| 320 blink::mojom::PresentationError::From(error)); | 323 blink::mojom::PresentationError::From(error)); |
| 321 pending_start_session_cb_.reset(); | 324 pending_start_session_cb_.reset(); |
| 322 start_session_request_id_ = kInvalidRequestSessionId; | 325 start_session_request_id_ = kInvalidRequestSessionId; |
| 323 } | 326 } |
| 324 | 327 |
| 325 void PresentationServiceImpl::OnJoinSessionSucceeded( | 328 void PresentationServiceImpl::OnJoinSessionSucceeded( |
| 326 int request_session_id, | 329 int request_session_id, |
| 327 const PresentationSessionInfo& session_info) { | 330 const PresentationSessionInfo& session_info) { |
| 328 if (RunAndEraseJoinSessionMojoCallback( | 331 if (RunAndEraseJoinSessionMojoCallback( |
| 329 request_session_id, | 332 request_session_id, |
| 330 blink::mojom::PresentationSessionInfo::From(session_info), | 333 blink::mojom::PresentationSessionInfo::From(session_info), |
| 331 blink::mojom::PresentationErrorPtr())) { | 334 blink::mojom::PresentationErrorPtr())) { |
| 332 ListenForConnectionStateChange(session_info); | 335 ListenForConnectionStateChangeAndChangeState(session_info); |
| 333 } | 336 } |
| 334 } | 337 } |
| 335 | 338 |
| 336 void PresentationServiceImpl::OnJoinSessionError( | 339 void PresentationServiceImpl::OnJoinSessionError( |
| 337 int request_session_id, | 340 int request_session_id, |
| 338 const PresentationError& error) { | 341 const PresentationError& error) { |
| 339 RunAndEraseJoinSessionMojoCallback( | 342 RunAndEraseJoinSessionMojoCallback( |
| 340 request_session_id, blink::mojom::PresentationSessionInfoPtr(), | 343 request_session_id, blink::mojom::PresentationSessionInfoPtr(), |
| 341 blink::mojom::PresentationError::From(error)); | 344 blink::mojom::PresentationError::From(error)); |
| 342 } | 345 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 void PresentationServiceImpl::Terminate(const GURL& presentation_url, | 417 void PresentationServiceImpl::Terminate(const GURL& presentation_url, |
| 415 const std::string& presentation_id) { | 418 const std::string& presentation_id) { |
| 416 DVLOG(2) << "Terminate " << presentation_id; | 419 DVLOG(2) << "Terminate " << presentation_id; |
| 417 if (delegate_) | 420 if (delegate_) |
| 418 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); | 421 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); |
| 419 } | 422 } |
| 420 | 423 |
| 421 void PresentationServiceImpl::OnConnectionStateChanged( | 424 void PresentationServiceImpl::OnConnectionStateChanged( |
| 422 const PresentationSessionInfo& connection, | 425 const PresentationSessionInfo& connection, |
| 423 const PresentationConnectionStateChangeInfo& info) { | 426 const PresentationConnectionStateChangeInfo& info) { |
| 427 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " |
| 428 << "[presentation_id]: " << connection.presentation_id |
| 429 << " [state]: " << info.state; |
| 424 DCHECK(client_.get()); | 430 DCHECK(client_.get()); |
| 425 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { | 431 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { |
| 426 client_->OnConnectionClosed( | 432 client_->OnConnectionClosed( |
| 427 blink::mojom::PresentationSessionInfo::From(connection), | 433 blink::mojom::PresentationSessionInfo::From(connection), |
| 428 content::PresentationConnectionCloseReasonToMojo(info.close_reason), | 434 content::PresentationConnectionCloseReasonToMojo(info.close_reason), |
| 429 info.message); | 435 info.message); |
| 430 } else { | 436 } else { |
| 431 client_->OnConnectionStateChanged( | 437 client_->OnConnectionStateChanged( |
| 432 blink::mojom::PresentationSessionInfo::From(connection), | 438 blink::mojom::PresentationSessionInfo::From(connection), |
| 433 PresentationConnectionStateToMojo(info.state)); | 439 PresentationConnectionStateToMojo(info.state)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 555 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
| 550 delegate_ = nullptr; | 556 delegate_ = nullptr; |
| 551 Reset(); | 557 Reset(); |
| 552 } | 558 } |
| 553 | 559 |
| 554 void PresentationServiceImpl::OnDefaultPresentationStarted( | 560 void PresentationServiceImpl::OnDefaultPresentationStarted( |
| 555 const PresentationSessionInfo& connection) { | 561 const PresentationSessionInfo& connection) { |
| 556 DCHECK(client_.get()); | 562 DCHECK(client_.get()); |
| 557 client_->OnDefaultSessionStarted( | 563 client_->OnDefaultSessionStarted( |
| 558 blink::mojom::PresentationSessionInfo::From(connection)); | 564 blink::mojom::PresentationSessionInfo::From(connection)); |
| 559 ListenForConnectionStateChange(connection); | 565 ListenForConnectionStateChangeAndChangeState(connection); |
| 560 } | 566 } |
| 561 | 567 |
| 562 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: | 568 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: |
| 563 ScreenAvailabilityListenerImpl(const GURL& availability_url, | 569 ScreenAvailabilityListenerImpl(const GURL& availability_url, |
| 564 PresentationServiceImpl* service) | 570 PresentationServiceImpl* service) |
| 565 : availability_url_(availability_url), service_(service) { | 571 : availability_url_(availability_url), service_(service) { |
| 566 DCHECK(service_); | 572 DCHECK(service_); |
| 567 DCHECK(service_->client_.get()); | 573 DCHECK(service_->client_.get()); |
| 568 } | 574 } |
| 569 | 575 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 599 | 605 |
| 600 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( | 606 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( |
| 601 blink::mojom::PresentationSessionInfoPtr session, | 607 blink::mojom::PresentationSessionInfoPtr session, |
| 602 blink::mojom::PresentationErrorPtr error) { | 608 blink::mojom::PresentationErrorPtr error) { |
| 603 DCHECK(!callback_.is_null()); | 609 DCHECK(!callback_.is_null()); |
| 604 callback_.Run(std::move(session), std::move(error)); | 610 callback_.Run(std::move(session), std::move(error)); |
| 605 callback_.Reset(); | 611 callback_.Reset(); |
| 606 } | 612 } |
| 607 | 613 |
| 608 } // namespace content | 614 } // namespace content |
| OLD | NEW |