| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/presentation/presentation_type_converters.h" | 10 #include "content/browser/presentation/presentation_type_converters.h" |
| 11 #include "content/public/browser/content_browser_client.h" | 11 #include "content/public/browser/content_browser_client.h" |
| 12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/browser/presentation_session_message.h" | 13 #include "content/public/browser/presentation_session_message.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 18 #include "content/public/common/frame_navigate_params.h" | 18 #include "content/public/common/frame_navigate_params.h" |
| 19 #include "content/public/common/presentation_constants.h" | 19 #include "content/public/common/presentation_constants.h" |
| 20 | 20 |
| 21 namespace content { |
| 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 25 const int kInvalidRequestSessionId = -1; |
| 26 |
| 23 // The return value takes ownership of the contents of |input|. | 27 // The return value takes ownership of the contents of |input|. |
| 24 presentation::SessionMessagePtr ToMojoSessionMessage( | 28 presentation::SessionMessagePtr ToMojoSessionMessage( |
| 25 content::PresentationSessionMessage* input) { | 29 content::PresentationSessionMessage* input) { |
| 26 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); | 30 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); |
| 27 output->presentation_url.Swap(&input->presentation_url); | 31 output->presentation_url.Swap(&input->presentation_url); |
| 28 output->presentation_id.Swap(&input->presentation_id); | 32 output->presentation_id.Swap(&input->presentation_id); |
| 29 if (input->is_binary()) { | 33 if (input->is_binary()) { |
| 30 // binary data | 34 // binary data |
| 31 output->type = presentation::PresentationMessageType:: | 35 output->type = presentation::PresentationMessageType:: |
| 32 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | 36 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 output = content::PresentationSessionMessage::CreateBinaryMessage( | 73 output = content::PresentationSessionMessage::CreateBinaryMessage( |
| 70 input->presentation_url, | 74 input->presentation_url, |
| 71 input->presentation_id, | 75 input->presentation_id, |
| 72 make_scoped_ptr(new std::vector<uint8_t>)); | 76 make_scoped_ptr(new std::vector<uint8_t>)); |
| 73 input->data.Swap(output->data.get()); | 77 input->data.Swap(output->data.get()); |
| 74 } | 78 } |
| 75 | 79 |
| 76 return output.Pass(); | 80 return output.Pass(); |
| 77 } | 81 } |
| 78 | 82 |
| 83 void InvokeNewSessionMojoCallbackWithError( |
| 84 const NewSessionMojoCallback& callback) { |
| 85 callback.Run( |
| 86 presentation::PresentationSessionInfoPtr(), |
| 87 presentation::PresentationError::From( |
| 88 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
| 89 } |
| 90 |
| 79 } // namespace | 91 } // namespace |
| 80 | 92 |
| 81 namespace content { | |
| 82 | |
| 83 PresentationServiceImpl::PresentationServiceImpl( | 93 PresentationServiceImpl::PresentationServiceImpl( |
| 84 RenderFrameHost* render_frame_host, | 94 RenderFrameHost* render_frame_host, |
| 85 WebContents* web_contents, | 95 WebContents* web_contents, |
| 86 PresentationServiceDelegate* delegate) | 96 PresentationServiceDelegate* delegate) |
| 87 : WebContentsObserver(web_contents), | 97 : WebContentsObserver(web_contents), |
| 88 delegate_(delegate), | 98 delegate_(delegate), |
| 89 is_start_session_pending_(false), | 99 start_session_request_id_(kInvalidRequestSessionId), |
| 90 next_request_session_id_(0), | 100 next_request_session_id_(0), |
| 91 weak_factory_(this) { | 101 weak_factory_(this) { |
| 92 DCHECK(render_frame_host); | 102 DCHECK(render_frame_host); |
| 93 DCHECK(web_contents); | 103 DCHECK(web_contents); |
| 94 | 104 |
| 95 render_process_id_ = render_frame_host->GetProcess()->GetID(); | 105 render_process_id_ = render_frame_host->GetProcess()->GetID(); |
| 96 render_frame_id_ = render_frame_host->GetRoutingID(); | 106 render_frame_id_ = render_frame_host->GetRoutingID(); |
| 97 DVLOG(2) << "PresentationServiceImpl: " | 107 DVLOG(2) << "PresentationServiceImpl: " |
| 98 << render_process_id_ << ", " << render_frame_id_; | 108 << render_process_id_ << ", " << render_frame_id_; |
| 99 if (delegate_) | 109 if (delegate_) |
| 100 delegate_->AddObserver(render_process_id_, render_frame_id_, this); | 110 delegate_->AddObserver(render_process_id_, render_frame_id_, this); |
| 101 } | 111 } |
| 102 | 112 |
| 103 PresentationServiceImpl::~PresentationServiceImpl() { | 113 PresentationServiceImpl::~PresentationServiceImpl() { |
| 104 if (delegate_) | 114 if (delegate_) |
| 105 delegate_->RemoveObserver(render_process_id_, render_frame_id_); | 115 delegate_->RemoveObserver(render_process_id_, render_frame_id_); |
| 106 FlushNewSessionCallbacks(); | |
| 107 } | 116 } |
| 108 | 117 |
| 109 // static | 118 // static |
| 110 void PresentationServiceImpl::CreateMojoService( | 119 void PresentationServiceImpl::CreateMojoService( |
| 111 RenderFrameHost* render_frame_host, | 120 RenderFrameHost* render_frame_host, |
| 112 mojo::InterfaceRequest<presentation::PresentationService> request) { | 121 mojo::InterfaceRequest<presentation::PresentationService> request) { |
| 113 DVLOG(2) << "CreateMojoService"; | 122 DVLOG(2) << "CreateMojoService"; |
| 114 WebContents* web_contents = | 123 WebContents* web_contents = |
| 115 WebContents::FromRenderFrameHost(render_frame_host); | 124 WebContents::FromRenderFrameHost(render_frame_host); |
| 116 DCHECK(web_contents); | 125 DCHECK(web_contents); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void PresentationServiceImpl::StartSession( | 215 void PresentationServiceImpl::StartSession( |
| 207 const mojo::String& presentation_url, | 216 const mojo::String& presentation_url, |
| 208 const mojo::String& presentation_id, | 217 const mojo::String& presentation_id, |
| 209 const NewSessionMojoCallback& callback) { | 218 const NewSessionMojoCallback& callback) { |
| 210 DVLOG(2) << "StartSession"; | 219 DVLOG(2) << "StartSession"; |
| 211 if (!delegate_) { | 220 if (!delegate_) { |
| 212 InvokeNewSessionMojoCallbackWithError(callback); | 221 InvokeNewSessionMojoCallbackWithError(callback); |
| 213 return; | 222 return; |
| 214 } | 223 } |
| 215 | 224 |
| 216 if (is_start_session_pending_) { | 225 // Currently not processing a request, so no need for queueing. |
| 217 queued_start_session_requests_.push_back(make_linked_ptr( | 226 if (start_session_request_id_ == kInvalidRequestSessionId) { |
| 218 new StartSessionRequest(presentation_url, presentation_id, callback))); | 227 DoStartSession(make_scoped_ptr(new StartSessionRequest( |
| 228 presentation_url, presentation_id, callback))); |
| 219 return; | 229 return; |
| 220 } | 230 } |
| 221 | 231 |
| 222 DoStartSession(presentation_url, presentation_id, callback); | 232 if (queued_start_session_requests_.size() >= kMaxNumQueuedSessionRequests) { |
| 233 InvokeNewSessionMojoCallbackWithError(callback); |
| 234 return; |
| 235 } |
| 236 |
| 237 queued_start_session_requests_.push_back( |
| 238 make_linked_ptr(new StartSessionRequest( |
| 239 presentation_url, presentation_id, callback))); |
| 223 } | 240 } |
| 224 | 241 |
| 225 void PresentationServiceImpl::JoinSession( | 242 void PresentationServiceImpl::JoinSession( |
| 226 const mojo::String& presentation_url, | 243 const mojo::String& presentation_url, |
| 227 const mojo::String& presentation_id, | 244 const mojo::String& presentation_id, |
| 228 const NewSessionMojoCallback& callback) { | 245 const NewSessionMojoCallback& callback) { |
| 229 DVLOG(2) << "JoinSession"; | 246 DVLOG(2) << "JoinSession"; |
| 230 if (!delegate_) { | 247 if (!delegate_) { |
| 231 InvokeNewSessionMojoCallbackWithError(callback); | 248 InvokeNewSessionMojoCallbackWithError(callback); |
| 232 return; | 249 return; |
| 233 } | 250 } |
| 234 | 251 |
| 235 int request_session_id = RegisterNewSessionCallback(callback); | 252 int request_session_id = RegisterJoinSessionCallback(callback); |
| 253 if (request_session_id == kInvalidRequestSessionId) { |
| 254 InvokeNewSessionMojoCallbackWithError(callback); |
| 255 return; |
| 256 } |
| 236 delegate_->JoinSession( | 257 delegate_->JoinSession( |
| 237 render_process_id_, | 258 render_process_id_, |
| 238 render_frame_id_, | 259 render_frame_id_, |
| 239 presentation_url, | 260 presentation_url, |
| 240 presentation_id, | 261 presentation_id, |
| 241 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 262 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, |
| 242 weak_factory_.GetWeakPtr(), false, request_session_id), | 263 weak_factory_.GetWeakPtr(), request_session_id), |
| 243 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 264 base::Bind(&PresentationServiceImpl::OnJoinSessionError, |
| 244 weak_factory_.GetWeakPtr(), false, request_session_id)); | 265 weak_factory_.GetWeakPtr(), request_session_id)); |
| 245 } | 266 } |
| 246 | 267 |
| 247 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { | 268 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { |
| 248 if (queued_start_session_requests_.empty()) { | 269 if (queued_start_session_requests_.empty()) |
| 249 is_start_session_pending_ = false; | |
| 250 return; | 270 return; |
| 251 } | 271 |
| 252 linked_ptr<StartSessionRequest> request = | 272 linked_ptr<StartSessionRequest> request = |
| 253 queued_start_session_requests_.front(); | 273 queued_start_session_requests_.front(); |
| 254 queued_start_session_requests_.pop_front(); | 274 queued_start_session_requests_.pop_front(); |
| 255 DoStartSession(request->presentation_url(), | 275 DoStartSession(make_scoped_ptr(request.release())); |
| 256 request->presentation_id(), | |
| 257 request->PassCallback()); | |
| 258 } | 276 } |
| 259 | 277 |
| 260 int PresentationServiceImpl::RegisterNewSessionCallback( | 278 int PresentationServiceImpl::GetNextRequestSessionId() { |
| 261 const NewSessionMojoCallback& callback) { | 279 return ++next_request_session_id_; |
| 262 ++next_request_session_id_; | |
| 263 pending_session_cbs_[next_request_session_id_].reset( | |
| 264 new NewSessionMojoCallback(callback)); | |
| 265 return next_request_session_id_; | |
| 266 } | 280 } |
| 267 | 281 |
| 268 void PresentationServiceImpl::FlushNewSessionCallbacks() { | 282 int PresentationServiceImpl::RegisterJoinSessionCallback( |
| 269 for (auto& pending_entry : pending_session_cbs_) { | 283 const NewSessionMojoCallback& callback) { |
| 270 InvokeNewSessionMojoCallbackWithError(*pending_entry.second); | 284 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
| 271 } | 285 return kInvalidRequestSessionId; |
| 272 pending_session_cbs_.clear(); | 286 |
| 287 int request_id = GetNextRequestSessionId(); |
| 288 pending_join_session_cbs_[request_id].reset( |
| 289 new NewSessionMojoCallbackWrapper(callback)); |
| 290 return request_id; |
| 273 } | 291 } |
| 274 | 292 |
| 275 void PresentationServiceImpl::DoStartSession( | 293 void PresentationServiceImpl::DoStartSession( |
| 276 const std::string& presentation_url, | 294 scoped_ptr<StartSessionRequest> request) { |
| 277 const std::string& presentation_id, | 295 DCHECK_EQ(kInvalidRequestSessionId, start_session_request_id_); |
| 278 const NewSessionMojoCallback& callback) { | 296 DCHECK(!pending_start_session_cb_.get()); |
| 279 int request_session_id = RegisterNewSessionCallback(callback); | 297 |
| 280 is_start_session_pending_ = true; | 298 int request_session_id = GetNextRequestSessionId(); |
| 299 start_session_request_id_ = request_session_id; |
| 300 pending_start_session_cb_ = request->PassCallback(); |
| 301 |
| 281 delegate_->StartSession( | 302 delegate_->StartSession( |
| 282 render_process_id_, | 303 render_process_id_, |
| 283 render_frame_id_, | 304 render_frame_id_, |
| 284 presentation_url, | 305 request->presentation_url(), |
| 285 presentation_id, | 306 request->presentation_id(), |
| 286 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 307 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, |
| 287 weak_factory_.GetWeakPtr(), true, request_session_id), | 308 weak_factory_.GetWeakPtr(), request_session_id), |
| 288 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 309 base::Bind(&PresentationServiceImpl::OnStartSessionError, |
| 289 weak_factory_.GetWeakPtr(), true, request_session_id)); | 310 weak_factory_.GetWeakPtr(), request_session_id)); |
| 290 } | 311 } |
| 291 | 312 |
| 292 void PresentationServiceImpl::OnStartOrJoinSessionSucceeded( | 313 void PresentationServiceImpl::OnStartSessionSucceeded( |
| 293 bool is_start_session, | |
| 294 int request_session_id, | 314 int request_session_id, |
| 295 const PresentationSessionInfo& session_info) { | 315 const PresentationSessionInfo& session_info) { |
| 296 RunAndEraseNewSessionMojoCallback( | 316 if (request_session_id == start_session_request_id_) { |
| 317 CHECK(pending_start_session_cb_.get()); |
| 318 pending_start_session_cb_->Run( |
| 319 presentation::PresentationSessionInfo::From(session_info), |
| 320 presentation::PresentationErrorPtr()); |
| 321 pending_start_session_cb_.reset(); |
| 322 start_session_request_id_ = kInvalidRequestSessionId; |
| 323 HandleQueuedStartSessionRequests(); |
| 324 } |
| 325 } |
| 326 |
| 327 void PresentationServiceImpl::OnStartSessionError( |
| 328 int request_session_id, |
| 329 const PresentationError& error) { |
| 330 if (request_session_id == start_session_request_id_) { |
| 331 CHECK(pending_start_session_cb_.get()); |
| 332 pending_start_session_cb_->Run( |
| 333 presentation::PresentationSessionInfoPtr(), |
| 334 presentation::PresentationError::From(error)); |
| 335 pending_start_session_cb_.reset(); |
| 336 start_session_request_id_ = kInvalidRequestSessionId; |
| 337 HandleQueuedStartSessionRequests(); |
| 338 } |
| 339 } |
| 340 |
| 341 void PresentationServiceImpl::OnJoinSessionSucceeded( |
| 342 int request_session_id, |
| 343 const PresentationSessionInfo& session_info) { |
| 344 RunAndEraseJoinSessionMojoCallback( |
| 297 request_session_id, | 345 request_session_id, |
| 298 presentation::PresentationSessionInfo::From(session_info), | 346 presentation::PresentationSessionInfo::From(session_info), |
| 299 presentation::PresentationErrorPtr()); | 347 presentation::PresentationErrorPtr()); |
| 300 if (is_start_session) | |
| 301 HandleQueuedStartSessionRequests(); | |
| 302 } | 348 } |
| 303 | 349 |
| 304 void PresentationServiceImpl::OnStartOrJoinSessionError( | 350 void PresentationServiceImpl::OnJoinSessionError( |
| 305 bool is_start_session, | |
| 306 int request_session_id, | 351 int request_session_id, |
| 307 const PresentationError& error) { | 352 const PresentationError& error) { |
| 308 RunAndEraseNewSessionMojoCallback( | 353 RunAndEraseJoinSessionMojoCallback( |
| 309 request_session_id, | 354 request_session_id, |
| 310 presentation::PresentationSessionInfoPtr(), | 355 presentation::PresentationSessionInfoPtr(), |
| 311 presentation::PresentationError::From(error)); | 356 presentation::PresentationError::From(error)); |
| 312 if (is_start_session) | |
| 313 HandleQueuedStartSessionRequests(); | |
| 314 } | 357 } |
| 315 | 358 |
| 316 void PresentationServiceImpl::RunAndEraseNewSessionMojoCallback( | 359 void PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( |
| 317 int request_session_id, | 360 int request_session_id, |
| 318 presentation::PresentationSessionInfoPtr session, | 361 presentation::PresentationSessionInfoPtr session, |
| 319 presentation::PresentationErrorPtr error) { | 362 presentation::PresentationErrorPtr error) { |
| 320 auto it = pending_session_cbs_.find(request_session_id); | 363 auto it = pending_join_session_cbs_.find(request_session_id); |
| 321 if (it == pending_session_cbs_.end()) | 364 if (it == pending_join_session_cbs_.end()) |
| 322 return; | 365 return; |
| 323 | 366 |
| 324 DCHECK(it->second.get()); | 367 DCHECK(it->second.get()); |
| 325 it->second->Run(session.Pass(), error.Pass()); | 368 it->second->Run(session.Pass(), error.Pass()); |
| 326 pending_session_cbs_.erase(it); | 369 pending_join_session_cbs_.erase(it); |
| 327 } | 370 } |
| 328 | 371 |
| 329 void PresentationServiceImpl::SetDefaultPresentationURL( | 372 void PresentationServiceImpl::SetDefaultPresentationURL( |
| 330 const mojo::String& default_presentation_url, | 373 const mojo::String& default_presentation_url, |
| 331 const mojo::String& default_presentation_id) { | 374 const mojo::String& default_presentation_id) { |
| 332 DVLOG(2) << "SetDefaultPresentationURL"; | 375 DVLOG(2) << "SetDefaultPresentationURL"; |
| 333 if (!delegate_) | 376 if (!delegate_) |
| 334 return; | 377 return; |
| 335 | 378 |
| 336 const std::string& old_default_url = default_presentation_url_; | 379 const std::string& old_default_url = default_presentation_url_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 delete this; | 525 delete this; |
| 483 } | 526 } |
| 484 | 527 |
| 485 void PresentationServiceImpl::Reset() { | 528 void PresentationServiceImpl::Reset() { |
| 486 DVLOG(2) << "PresentationServiceImpl::Reset"; | 529 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 487 if (delegate_) | 530 if (delegate_) |
| 488 delegate_->Reset(render_process_id_, render_frame_id_); | 531 delegate_->Reset(render_process_id_, render_frame_id_); |
| 489 | 532 |
| 490 default_presentation_url_.clear(); | 533 default_presentation_url_.clear(); |
| 491 default_presentation_id_.clear(); | 534 default_presentation_id_.clear(); |
| 535 |
| 492 screen_availability_listener_.reset(); | 536 screen_availability_listener_.reset(); |
| 537 |
| 493 queued_start_session_requests_.clear(); | 538 queued_start_session_requests_.clear(); |
| 494 FlushNewSessionCallbacks(); | 539 start_session_request_id_ = kInvalidRequestSessionId; |
| 540 pending_start_session_cb_.reset(); |
| 541 |
| 542 pending_join_session_cbs_.clear(); |
| 543 |
| 495 default_session_start_context_.reset(); | 544 default_session_start_context_.reset(); |
| 545 |
| 496 if (on_session_messages_callback_.get()) { | 546 if (on_session_messages_callback_.get()) { |
| 497 on_session_messages_callback_->Run( | 547 on_session_messages_callback_->Run( |
| 498 mojo::Array<presentation::SessionMessagePtr>()); | 548 mojo::Array<presentation::SessionMessagePtr>()); |
| 499 on_session_messages_callback_.reset(); | 549 on_session_messages_callback_.reset(); |
| 500 } | 550 } |
| 551 |
| 501 if (send_message_callback_) { | 552 if (send_message_callback_) { |
| 502 // Run the callback with false, indicating the renderer to stop sending | 553 // Run the callback with false, indicating the renderer to stop sending |
| 503 // the requests and invalidate all pending requests. | 554 // the requests and invalidate all pending requests. |
| 504 send_message_callback_->Run(false); | 555 send_message_callback_->Run(false); |
| 505 send_message_callback_.reset(); | 556 send_message_callback_.reset(); |
| 506 } | 557 } |
| 507 } | 558 } |
| 508 | 559 |
| 509 // static | |
| 510 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | |
| 511 const NewSessionMojoCallback& callback) { | |
| 512 callback.Run( | |
| 513 presentation::PresentationSessionInfoPtr(), | |
| 514 presentation::PresentationError::From( | |
| 515 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | |
| 516 } | |
| 517 | |
| 518 void PresentationServiceImpl::OnDelegateDestroyed() { | 560 void PresentationServiceImpl::OnDelegateDestroyed() { |
| 519 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 561 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
| 520 delegate_ = nullptr; | 562 delegate_ = nullptr; |
| 521 Reset(); | 563 Reset(); |
| 522 } | 564 } |
| 523 | 565 |
| 524 void PresentationServiceImpl::OnDefaultPresentationStarted( | 566 void PresentationServiceImpl::OnDefaultPresentationStarted( |
| 525 const PresentationSessionInfo& session) { | 567 const PresentationSessionInfo& session) { |
| 526 if (default_session_start_context_.get()) | 568 if (default_session_start_context_.get()) |
| 527 default_session_start_context_->set_session(session); | 569 default_session_start_context_->set_session(session); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 544 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl | 586 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl |
| 545 ::GetPresentationUrl() const { | 587 ::GetPresentationUrl() const { |
| 546 return presentation_url_; | 588 return presentation_url_; |
| 547 } | 589 } |
| 548 | 590 |
| 549 void PresentationServiceImpl::ScreenAvailabilityListenerImpl | 591 void PresentationServiceImpl::ScreenAvailabilityListenerImpl |
| 550 ::OnScreenAvailabilityChanged(bool available) { | 592 ::OnScreenAvailabilityChanged(bool available) { |
| 551 service_->client_->OnScreenAvailabilityUpdated(available); | 593 service_->client_->OnScreenAvailabilityUpdated(available); |
| 552 } | 594 } |
| 553 | 595 |
| 596 PresentationServiceImpl::NewSessionMojoCallbackWrapper |
| 597 ::NewSessionMojoCallbackWrapper(const NewSessionMojoCallback& callback) |
| 598 : callback_(callback) { |
| 599 } |
| 600 |
| 601 PresentationServiceImpl::NewSessionMojoCallbackWrapper |
| 602 ::~NewSessionMojoCallbackWrapper() { |
| 603 if (!callback_.is_null()) |
| 604 InvokeNewSessionMojoCallbackWithError(callback_); |
| 605 } |
| 606 |
| 607 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
| 608 presentation::PresentationSessionInfoPtr session, |
| 609 presentation::PresentationErrorPtr error) { |
| 610 DCHECK(!callback_.is_null()); |
| 611 callback_.Run(session.Pass(), error.Pass()); |
| 612 callback_.reset(); |
| 613 } |
| 614 |
| 554 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( | 615 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( |
| 555 const std::string& presentation_url, | 616 const std::string& presentation_url, |
| 556 const std::string& presentation_id, | 617 const std::string& presentation_id, |
| 557 const NewSessionMojoCallback& callback) | 618 const NewSessionMojoCallback& callback) |
| 558 : presentation_url_(presentation_url), | 619 : presentation_url_(presentation_url), |
| 559 presentation_id_(presentation_id), | 620 presentation_id_(presentation_id), |
| 560 callback_(callback) { | 621 callback_wrapper_(new NewSessionMojoCallbackWrapper(callback)) { |
| 561 } | 622 } |
| 562 | 623 |
| 563 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { | 624 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { |
| 564 // Ensure that a pending callback is not dropped. | |
| 565 if (!callback_.is_null()) | |
| 566 InvokeNewSessionMojoCallbackWithError(callback_); | |
| 567 } | 625 } |
| 568 | 626 |
| 569 PresentationServiceImpl::NewSessionMojoCallback | 627 scoped_ptr<PresentationServiceImpl::NewSessionMojoCallbackWrapper> |
| 570 PresentationServiceImpl::StartSessionRequest::PassCallback() { | 628 PresentationServiceImpl::StartSessionRequest::PassCallback() { |
| 571 NewSessionMojoCallback callback = callback_; | 629 return callback_wrapper_.Pass(); |
| 572 callback_.reset(); | |
| 573 return callback; | |
| 574 } | 630 } |
| 575 | 631 |
| 576 PresentationServiceImpl::DefaultSessionStartContext | 632 PresentationServiceImpl::DefaultSessionStartContext |
| 577 ::DefaultSessionStartContext() { | 633 ::DefaultSessionStartContext() { |
| 578 } | 634 } |
| 579 | 635 |
| 580 PresentationServiceImpl::DefaultSessionStartContext | 636 PresentationServiceImpl::DefaultSessionStartContext |
| 581 ::~DefaultSessionStartContext() { | 637 ::~DefaultSessionStartContext() { |
| 582 Reset(); | 638 Reset(); |
| 583 } | 639 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 609 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 665 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| 610 ScopedVector<DefaultSessionMojoCallback> callbacks; | 666 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 611 callbacks.swap(callbacks_); | 667 callbacks.swap(callbacks_); |
| 612 for (const auto& callback : callbacks) | 668 for (const auto& callback : callbacks) |
| 613 callback->Run(presentation::PresentationSessionInfoPtr()); | 669 callback->Run(presentation::PresentationSessionInfoPtr()); |
| 614 session_.reset(); | 670 session_.reset(); |
| 615 } | 671 } |
| 616 | 672 |
| 617 } // namespace content | 673 } // namespace content |
| 618 | 674 |
| OLD | NEW |