Chromium Code Reviews| 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 if (start_session_request_id_ != kInvalidRequestSessionId) { |
| 217 queued_start_session_requests_.push_back(make_linked_ptr( | 226 if (queued_start_session_requests_.size() >= kMaxNumQueuedSessionRequests) { |
| 218 new StartSessionRequest(presentation_url, presentation_id, callback))); | 227 InvokeNewSessionMojoCallbackWithError(callback); |
| 228 } else { | |
|
whywhat
2015/05/13 11:11:32
nit: consider returning after InvokeNewSessionMojo
imcheng (use chromium acct)
2015/05/13 17:07:45
Done.
| |
| 229 queued_start_session_requests_.push_back( | |
| 230 make_linked_ptr(new StartSessionRequest( | |
| 231 presentation_url, presentation_id, callback))); | |
| 232 } | |
| 219 return; | 233 return; |
| 220 } | 234 } |
| 221 | 235 |
| 222 DoStartSession(presentation_url, presentation_id, callback); | 236 DoStartSession(make_scoped_ptr(new StartSessionRequest( |
| 237 presentation_url, presentation_id, callback))); | |
| 223 } | 238 } |
| 224 | 239 |
| 225 void PresentationServiceImpl::JoinSession( | 240 void PresentationServiceImpl::JoinSession( |
| 226 const mojo::String& presentation_url, | 241 const mojo::String& presentation_url, |
| 227 const mojo::String& presentation_id, | 242 const mojo::String& presentation_id, |
| 228 const NewSessionMojoCallback& callback) { | 243 const NewSessionMojoCallback& callback) { |
| 229 DVLOG(2) << "JoinSession"; | 244 DVLOG(2) << "JoinSession"; |
| 230 if (!delegate_) { | 245 if (!delegate_) { |
| 231 InvokeNewSessionMojoCallbackWithError(callback); | 246 InvokeNewSessionMojoCallbackWithError(callback); |
| 232 return; | 247 return; |
| 233 } | 248 } |
| 234 | 249 |
| 235 int request_session_id = RegisterNewSessionCallback(callback); | 250 int request_session_id = RegisterJoinSessionCallback(callback); |
| 251 if (request_session_id == kInvalidRequestSessionId) { | |
| 252 InvokeNewSessionMojoCallbackWithError(callback); | |
| 253 return; | |
| 254 } | |
| 236 delegate_->JoinSession( | 255 delegate_->JoinSession( |
| 237 render_process_id_, | 256 render_process_id_, |
| 238 render_frame_id_, | 257 render_frame_id_, |
| 239 presentation_url, | 258 presentation_url, |
| 240 presentation_id, | 259 presentation_id, |
| 241 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 260 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, |
| 242 weak_factory_.GetWeakPtr(), false, request_session_id), | 261 weak_factory_.GetWeakPtr(), request_session_id), |
| 243 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 262 base::Bind(&PresentationServiceImpl::OnJoinSessionError, |
| 244 weak_factory_.GetWeakPtr(), false, request_session_id)); | 263 weak_factory_.GetWeakPtr(), request_session_id)); |
| 245 } | 264 } |
| 246 | 265 |
| 247 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { | 266 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { |
| 248 if (queued_start_session_requests_.empty()) { | 267 if (queued_start_session_requests_.empty()) |
| 249 is_start_session_pending_ = false; | |
| 250 return; | 268 return; |
| 251 } | 269 |
| 252 linked_ptr<StartSessionRequest> request = | 270 linked_ptr<StartSessionRequest> request = |
| 253 queued_start_session_requests_.front(); | 271 queued_start_session_requests_.front(); |
| 254 queued_start_session_requests_.pop_front(); | 272 queued_start_session_requests_.pop_front(); |
| 255 DoStartSession(request->presentation_url(), | 273 DoStartSession(make_scoped_ptr(request.release())); |
| 256 request->presentation_id(), | |
| 257 request->PassCallback()); | |
| 258 } | 274 } |
| 259 | 275 |
| 260 int PresentationServiceImpl::RegisterNewSessionCallback( | 276 int PresentationServiceImpl::GetNextRequestSessionId() { |
| 261 const NewSessionMojoCallback& callback) { | 277 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 } | 278 } |
| 267 | 279 |
| 268 void PresentationServiceImpl::FlushNewSessionCallbacks() { | 280 int PresentationServiceImpl::RegisterJoinSessionCallback( |
| 269 for (auto& pending_entry : pending_session_cbs_) { | 281 const NewSessionMojoCallback& callback) { |
| 270 InvokeNewSessionMojoCallbackWithError(*pending_entry.second); | 282 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) |
| 271 } | 283 return kInvalidRequestSessionId; |
| 272 pending_session_cbs_.clear(); | 284 |
| 285 int request_id = GetNextRequestSessionId(); | |
| 286 pending_join_session_cbs_[request_id].reset( | |
| 287 new NewSessionMojoCallbackWrapper(callback)); | |
| 288 return request_id; | |
| 273 } | 289 } |
| 274 | 290 |
| 275 void PresentationServiceImpl::DoStartSession( | 291 void PresentationServiceImpl::DoStartSession( |
| 276 const std::string& presentation_url, | 292 scoped_ptr<StartSessionRequest> request) { |
| 277 const std::string& presentation_id, | 293 DCHECK_EQ(kInvalidRequestSessionId, start_session_request_id_); |
| 278 const NewSessionMojoCallback& callback) { | 294 DCHECK(!pending_start_session_cb_.get()); |
| 279 int request_session_id = RegisterNewSessionCallback(callback); | 295 |
| 280 is_start_session_pending_ = true; | 296 int request_session_id = GetNextRequestSessionId(); |
| 297 start_session_request_id_ = request_session_id; | |
| 298 pending_start_session_cb_ = request->PassCallback(); | |
| 299 | |
| 281 delegate_->StartSession( | 300 delegate_->StartSession( |
| 282 render_process_id_, | 301 render_process_id_, |
| 283 render_frame_id_, | 302 render_frame_id_, |
| 284 presentation_url, | 303 request->presentation_url(), |
| 285 presentation_id, | 304 request->presentation_id(), |
| 286 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 305 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, |
| 287 weak_factory_.GetWeakPtr(), true, request_session_id), | 306 weak_factory_.GetWeakPtr(), request_session_id), |
| 288 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 307 base::Bind(&PresentationServiceImpl::OnStartSessionError, |
| 289 weak_factory_.GetWeakPtr(), true, request_session_id)); | 308 weak_factory_.GetWeakPtr(), request_session_id)); |
| 290 } | 309 } |
| 291 | 310 |
| 292 void PresentationServiceImpl::OnStartOrJoinSessionSucceeded( | 311 void PresentationServiceImpl::OnStartSessionSucceeded( |
| 293 bool is_start_session, | |
| 294 int request_session_id, | 312 int request_session_id, |
| 295 const PresentationSessionInfo& session_info) { | 313 const PresentationSessionInfo& session_info) { |
| 296 RunAndEraseNewSessionMojoCallback( | 314 if (request_session_id == start_session_request_id_) { |
| 315 CHECK(pending_start_session_cb_.get()); | |
| 316 pending_start_session_cb_->Run( | |
| 317 presentation::PresentationSessionInfo::From(session_info), | |
| 318 presentation::PresentationErrorPtr()); | |
| 319 pending_start_session_cb_.reset(); | |
| 320 start_session_request_id_ = kInvalidRequestSessionId; | |
| 321 HandleQueuedStartSessionRequests(); | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 void PresentationServiceImpl::OnStartSessionError( | |
| 326 int request_session_id, | |
| 327 const PresentationError& error) { | |
| 328 if (request_session_id == start_session_request_id_) { | |
| 329 CHECK(pending_start_session_cb_.get()); | |
| 330 pending_start_session_cb_->Run( | |
| 331 presentation::PresentationSessionInfoPtr(), | |
| 332 presentation::PresentationError::From(error)); | |
| 333 pending_start_session_cb_.reset(); | |
| 334 start_session_request_id_ = kInvalidRequestSessionId; | |
| 335 HandleQueuedStartSessionRequests(); | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 void PresentationServiceImpl::OnJoinSessionSucceeded( | |
| 340 int request_session_id, | |
| 341 const PresentationSessionInfo& session_info) { | |
| 342 RunAndEraseJoinSessionMojoCallback( | |
| 297 request_session_id, | 343 request_session_id, |
| 298 presentation::PresentationSessionInfo::From(session_info), | 344 presentation::PresentationSessionInfo::From(session_info), |
| 299 presentation::PresentationErrorPtr()); | 345 presentation::PresentationErrorPtr()); |
| 300 if (is_start_session) | |
| 301 HandleQueuedStartSessionRequests(); | |
| 302 } | 346 } |
| 303 | 347 |
| 304 void PresentationServiceImpl::OnStartOrJoinSessionError( | 348 void PresentationServiceImpl::OnJoinSessionError( |
| 305 bool is_start_session, | |
| 306 int request_session_id, | 349 int request_session_id, |
| 307 const PresentationError& error) { | 350 const PresentationError& error) { |
| 308 RunAndEraseNewSessionMojoCallback( | 351 RunAndEraseJoinSessionMojoCallback( |
| 309 request_session_id, | 352 request_session_id, |
| 310 presentation::PresentationSessionInfoPtr(), | 353 presentation::PresentationSessionInfoPtr(), |
| 311 presentation::PresentationError::From(error)); | 354 presentation::PresentationError::From(error)); |
| 312 if (is_start_session) | |
| 313 HandleQueuedStartSessionRequests(); | |
| 314 } | 355 } |
| 315 | 356 |
| 316 void PresentationServiceImpl::RunAndEraseNewSessionMojoCallback( | 357 void PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( |
| 317 int request_session_id, | 358 int request_session_id, |
| 318 presentation::PresentationSessionInfoPtr session, | 359 presentation::PresentationSessionInfoPtr session, |
| 319 presentation::PresentationErrorPtr error) { | 360 presentation::PresentationErrorPtr error) { |
| 320 auto it = pending_session_cbs_.find(request_session_id); | 361 auto it = pending_join_session_cbs_.find(request_session_id); |
| 321 if (it == pending_session_cbs_.end()) | 362 if (it == pending_join_session_cbs_.end()) |
| 322 return; | 363 return; |
| 323 | 364 |
| 324 DCHECK(it->second.get()); | 365 DCHECK(it->second.get()); |
| 325 it->second->Run(session.Pass(), error.Pass()); | 366 it->second->Run(session.Pass(), error.Pass()); |
| 326 pending_session_cbs_.erase(it); | 367 pending_join_session_cbs_.erase(it); |
| 327 } | 368 } |
| 328 | 369 |
| 329 void PresentationServiceImpl::SetDefaultPresentationURL( | 370 void PresentationServiceImpl::SetDefaultPresentationURL( |
| 330 const mojo::String& default_presentation_url, | 371 const mojo::String& default_presentation_url, |
| 331 const mojo::String& default_presentation_id) { | 372 const mojo::String& default_presentation_id) { |
| 332 DVLOG(2) << "SetDefaultPresentationURL"; | 373 DVLOG(2) << "SetDefaultPresentationURL"; |
| 333 if (!delegate_) | 374 if (!delegate_) |
| 334 return; | 375 return; |
| 335 | 376 |
| 336 const std::string& old_default_url = default_presentation_url_; | 377 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; | 523 delete this; |
| 483 } | 524 } |
| 484 | 525 |
| 485 void PresentationServiceImpl::Reset() { | 526 void PresentationServiceImpl::Reset() { |
| 486 DVLOG(2) << "PresentationServiceImpl::Reset"; | 527 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 487 if (delegate_) | 528 if (delegate_) |
| 488 delegate_->Reset(render_process_id_, render_frame_id_); | 529 delegate_->Reset(render_process_id_, render_frame_id_); |
| 489 | 530 |
| 490 default_presentation_url_.clear(); | 531 default_presentation_url_.clear(); |
| 491 default_presentation_id_.clear(); | 532 default_presentation_id_.clear(); |
| 533 | |
| 492 screen_availability_listener_.reset(); | 534 screen_availability_listener_.reset(); |
| 535 | |
| 493 queued_start_session_requests_.clear(); | 536 queued_start_session_requests_.clear(); |
| 494 FlushNewSessionCallbacks(); | 537 start_session_request_id_ = kInvalidRequestSessionId; |
| 538 pending_start_session_cb_.reset(); | |
| 539 | |
| 540 pending_join_session_cbs_.clear(); | |
| 541 | |
| 495 default_session_start_context_.reset(); | 542 default_session_start_context_.reset(); |
| 543 | |
| 496 if (on_session_messages_callback_.get()) { | 544 if (on_session_messages_callback_.get()) { |
| 497 on_session_messages_callback_->Run( | 545 on_session_messages_callback_->Run( |
| 498 mojo::Array<presentation::SessionMessagePtr>()); | 546 mojo::Array<presentation::SessionMessagePtr>()); |
| 499 on_session_messages_callback_.reset(); | 547 on_session_messages_callback_.reset(); |
| 500 } | 548 } |
| 549 | |
| 501 if (send_message_callback_) { | 550 if (send_message_callback_) { |
| 502 // Run the callback with false, indicating the renderer to stop sending | 551 // Run the callback with false, indicating the renderer to stop sending |
| 503 // the requests and invalidate all pending requests. | 552 // the requests and invalidate all pending requests. |
| 504 send_message_callback_->Run(false); | 553 send_message_callback_->Run(false); |
| 505 send_message_callback_.reset(); | 554 send_message_callback_.reset(); |
| 506 } | 555 } |
| 507 } | 556 } |
| 508 | 557 |
| 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() { | 558 void PresentationServiceImpl::OnDelegateDestroyed() { |
| 519 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 559 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
| 520 delegate_ = nullptr; | 560 delegate_ = nullptr; |
| 521 Reset(); | 561 Reset(); |
| 522 } | 562 } |
| 523 | 563 |
| 524 void PresentationServiceImpl::OnDefaultPresentationStarted( | 564 void PresentationServiceImpl::OnDefaultPresentationStarted( |
| 525 const PresentationSessionInfo& session) { | 565 const PresentationSessionInfo& session) { |
| 526 if (default_session_start_context_.get()) | 566 if (default_session_start_context_.get()) |
| 527 default_session_start_context_->set_session(session); | 567 default_session_start_context_->set_session(session); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 544 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl | 584 std::string PresentationServiceImpl::ScreenAvailabilityListenerImpl |
| 545 ::GetPresentationUrl() const { | 585 ::GetPresentationUrl() const { |
| 546 return presentation_url_; | 586 return presentation_url_; |
| 547 } | 587 } |
| 548 | 588 |
| 549 void PresentationServiceImpl::ScreenAvailabilityListenerImpl | 589 void PresentationServiceImpl::ScreenAvailabilityListenerImpl |
| 550 ::OnScreenAvailabilityChanged(bool available) { | 590 ::OnScreenAvailabilityChanged(bool available) { |
| 551 service_->client_->OnScreenAvailabilityUpdated(available); | 591 service_->client_->OnScreenAvailabilityUpdated(available); |
| 552 } | 592 } |
| 553 | 593 |
| 594 PresentationServiceImpl::NewSessionMojoCallbackWrapper | |
| 595 ::NewSessionMojoCallbackWrapper(const NewSessionMojoCallback& callback) | |
| 596 : callback_(callback) { | |
| 597 } | |
| 598 | |
| 599 PresentationServiceImpl::NewSessionMojoCallbackWrapper | |
| 600 ::~NewSessionMojoCallbackWrapper() { | |
| 601 if (!callback_.is_null()) | |
| 602 InvokeNewSessionMojoCallbackWithError(callback_); | |
| 603 } | |
| 604 | |
| 605 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( | |
| 606 presentation::PresentationSessionInfoPtr session, | |
| 607 presentation::PresentationErrorPtr error) { | |
| 608 DCHECK(!callback_.is_null()); | |
| 609 callback_.Run(session.Pass(), error.Pass()); | |
| 610 callback_.reset(); | |
| 611 } | |
| 612 | |
| 554 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( | 613 PresentationServiceImpl::StartSessionRequest::StartSessionRequest( |
| 555 const std::string& presentation_url, | 614 const std::string& presentation_url, |
| 556 const std::string& presentation_id, | 615 const std::string& presentation_id, |
| 557 const NewSessionMojoCallback& callback) | 616 const NewSessionMojoCallback& callback) |
| 558 : presentation_url_(presentation_url), | 617 : presentation_url_(presentation_url), |
| 559 presentation_id_(presentation_id), | 618 presentation_id_(presentation_id), |
| 560 callback_(callback) { | 619 callback_wrapper_(new NewSessionMojoCallbackWrapper(callback)) { |
| 561 } | 620 } |
| 562 | 621 |
| 563 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { | 622 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { |
| 564 // Ensure that a pending callback is not dropped. | |
| 565 if (!callback_.is_null()) | |
| 566 InvokeNewSessionMojoCallbackWithError(callback_); | |
| 567 } | 623 } |
| 568 | 624 |
| 569 PresentationServiceImpl::NewSessionMojoCallback | 625 scoped_ptr<PresentationServiceImpl::NewSessionMojoCallbackWrapper> |
| 570 PresentationServiceImpl::StartSessionRequest::PassCallback() { | 626 PresentationServiceImpl::StartSessionRequest::PassCallback() { |
| 571 NewSessionMojoCallback callback = callback_; | 627 return callback_wrapper_.Pass(); |
| 572 callback_.reset(); | |
| 573 return callback; | |
| 574 } | 628 } |
| 575 | 629 |
| 576 PresentationServiceImpl::DefaultSessionStartContext | 630 PresentationServiceImpl::DefaultSessionStartContext |
| 577 ::DefaultSessionStartContext() { | 631 ::DefaultSessionStartContext() { |
| 578 } | 632 } |
| 579 | 633 |
| 580 PresentationServiceImpl::DefaultSessionStartContext | 634 PresentationServiceImpl::DefaultSessionStartContext |
| 581 ::~DefaultSessionStartContext() { | 635 ::~DefaultSessionStartContext() { |
| 582 Reset(); | 636 Reset(); |
| 583 } | 637 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 609 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 663 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| 610 ScopedVector<DefaultSessionMojoCallback> callbacks; | 664 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 611 callbacks.swap(callbacks_); | 665 callbacks.swap(callbacks_); |
| 612 for (const auto& callback : callbacks) | 666 for (const auto& callback : callbacks) |
| 613 callback->Run(presentation::PresentationSessionInfoPtr()); | 667 callback->Run(presentation::PresentationSessionInfoPtr()); |
| 614 session_.reset(); | 668 session_.reset(); |
| 615 } | 669 } |
| 616 | 670 |
| 617 } // namespace content | 671 } // namespace content |
| 618 | 672 |
| OLD | NEW |