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" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 293 |
| 294 // Remove listener for old default presentation URL. | 294 // Remove listener for old default presentation URL. |
| 295 delegate_->RemoveScreenAvailabilityListener( | 295 delegate_->RemoveScreenAvailabilityListener( |
| 296 render_frame_host_->GetProcess()->GetID(), | 296 render_frame_host_->GetProcess()->GetID(), |
| 297 render_frame_host_->GetRoutingID(), | 297 render_frame_host_->GetRoutingID(), |
| 298 old_it->second.get()); | 298 old_it->second.get()); |
| 299 availability_contexts_.erase(old_it); | 299 availability_contexts_.erase(old_it); |
| 300 DoSetDefaultPresentationUrl(new_default_url, default_presentation_id); | 300 DoSetDefaultPresentationUrl(new_default_url, default_presentation_id); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void PresentationServiceImpl::SendStringMessage( | |
| 304 const mojo::String& presentation_url, | |
| 305 const mojo::String& presentation_id, | |
| 306 const mojo::String& message, | |
| 307 const SendMessageMojoCallback& callback) { | |
| 308 if (!delegate_) { | |
| 309 callback.Run(); | |
| 310 return; | |
| 311 } | |
| 312 // Save the callback and run it after request completion by delegate_. | |
| 313 send_message_cb_ptr_.reset(new SendMessageMojoCallback(callback)); | |
|
imcheng
2015/04/14 21:29:13
Given that incoming SendStringMessage requests are
USE s.singapati at gmail.com
2015/04/15 16:09:08
Acknowledged. Yes, I also had almost same question
USE s.singapati at gmail.com
2015/04/16 11:14:15
Also, if callback is invoked immediately after cal
| |
| 314 delegate_->SendStringMessage( | |
| 315 render_frame_host_->GetProcess()->GetID(), | |
| 316 render_frame_host_->GetRoutingID(), | |
| 317 presentation_url, | |
| 318 presentation_id, | |
| 319 message, | |
| 320 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, | |
| 321 weak_factory_.GetWeakPtr())); | |
| 322 } | |
| 323 | |
| 324 void PresentationServiceImpl::OnSendMessageCallback() { | |
| 325 DCHECK(send_message_cb_ptr_); | |
| 326 send_message_cb_ptr_->Run(); | |
| 327 send_message_cb_ptr_.reset(); | |
| 328 } | |
| 329 | |
| 303 void PresentationServiceImpl::CloseSession( | 330 void PresentationServiceImpl::CloseSession( |
| 304 const mojo::String& presentation_url, | 331 const mojo::String& presentation_url, |
| 305 const mojo::String& presentation_id) { | 332 const mojo::String& presentation_id) { |
| 306 NOTIMPLEMENTED(); | 333 NOTIMPLEMENTED(); |
| 307 } | 334 } |
| 308 | 335 |
| 309 void PresentationServiceImpl::ListenForSessionStateChange( | 336 void PresentationServiceImpl::ListenForSessionStateChange( |
| 310 const SessionStateCallback& callback) { | 337 const SessionStateCallback& callback) { |
| 311 NOTIMPLEMENTED(); | 338 NOTIMPLEMENTED(); |
| 312 } | 339 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } | 393 } |
| 367 availability_contexts_.clear(); | 394 availability_contexts_.clear(); |
| 368 for (auto& request_ptr : queued_start_session_requests_) { | 395 for (auto& request_ptr : queued_start_session_requests_) { |
| 369 InvokeNewSessionMojoCallbackWithError(request_ptr->callback); | 396 InvokeNewSessionMojoCallbackWithError(request_ptr->callback); |
| 370 } | 397 } |
| 371 queued_start_session_requests_.clear(); | 398 queued_start_session_requests_.clear(); |
| 372 for (auto& pending_entry : pending_session_cbs_) { | 399 for (auto& pending_entry : pending_session_cbs_) { |
| 373 InvokeNewSessionMojoCallbackWithError(*pending_entry.second); | 400 InvokeNewSessionMojoCallbackWithError(*pending_entry.second); |
| 374 } | 401 } |
| 375 pending_session_cbs_.clear(); | 402 pending_session_cbs_.clear(); |
| 403 | |
| 404 if (send_message_cb_ptr_) { | |
| 405 // Running the callback might result in the PresentationDispatcher sending | |
| 406 // the next message. So, just reset the callback since the frame is being | |
| 407 // closed anyways. | |
| 408 send_message_cb_ptr_.reset(); | |
|
imcheng
2015/04/14 21:29:13
It cannot simply be reset since it will DCHECK per
USE s.singapati at gmail.com
2015/04/15 16:09:08
Acknowledged.
- Then it must run the callback for
| |
| 409 } | |
| 376 } | 410 } |
| 377 | 411 |
| 378 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | 412 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( |
| 379 const NewSessionMojoCallback& callback) { | 413 const NewSessionMojoCallback& callback) { |
| 380 callback.Run( | 414 callback.Run( |
| 381 presentation::PresentationSessionInfoPtr(), | 415 presentation::PresentationSessionInfoPtr(), |
| 382 presentation::PresentationError::From( | 416 presentation::PresentationError::From( |
| 383 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | 417 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
| 384 } | 418 } |
| 385 | 419 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 : presentation_url(presentation_url), | 489 : presentation_url(presentation_url), |
| 456 presentation_id(presentation_id), | 490 presentation_id(presentation_id), |
| 457 callback(callback) { | 491 callback(callback) { |
| 458 } | 492 } |
| 459 | 493 |
| 460 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { | 494 PresentationServiceImpl::StartSessionRequest::~StartSessionRequest() { |
| 461 } | 495 } |
| 462 | 496 |
| 463 } // namespace content | 497 } // namespace content |
| 464 | 498 |
| OLD | NEW |