Chromium Code Reviews| Index: content/renderer/presentation/presentation_dispatcher.cc |
| diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc |
| index 6691be68207d752afcfe8c499db8a2098a000cab..08ec8cf23359a2f20059d93275a3cf59d1427b54 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -83,7 +83,8 @@ PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| controller_(nullptr), |
| binding_(this), |
| listening_state_(ListeningState::Inactive), |
| - last_known_availability_(false) { |
| + last_known_availability_(false), |
| + listening_for_messages_(false) { |
| } |
| PresentationDispatcher::~PresentationDispatcher() { |
| @@ -337,6 +338,8 @@ void PresentationDispatcher::DidCommitProvisionalLoad( |
| // Remove all pending send message requests. |
| MessageRequestQueue empty; |
| std::swap(message_request_queue_, empty); |
| + |
| + listening_for_messages_ = false; |
| } |
| void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
| @@ -388,9 +391,12 @@ void PresentationDispatcher::OnSessionCreated( |
| DCHECK(!session_info.is_null()); |
| callback->onSuccess(new PresentationSessionClient(session_info.Pass())); |
| - presentation_service_->ListenForSessionMessages( |
| - base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
| - base::Unretained(this))); |
| + if (!listening_for_messages_) { |
| + listening_for_messages_ = true; |
| + presentation_service_->ListenForSessionMessages( |
| + base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
| + base::Unretained(this))); |
| + } |
| } |
| void PresentationDispatcher::OnSessionStateChange( |
| @@ -411,9 +417,13 @@ void PresentationDispatcher::OnSessionStateChange( |
| void PresentationDispatcher::OnSessionMessagesReceived( |
| mojo::Array<presentation::SessionMessagePtr> messages) { |
| + DCHECK(listening_for_messages_); |
|
imcheng (use chromium acct)
2015/07/07 22:24:38
Is it possible for DidCommitProvisionalLoad() to b
haibinlu
2015/07/07 22:37:24
good point. updated.
|
| + |
| // When messages is null, there is an error at presentation service side. |
| - if (!controller_ || messages.is_null()) |
| + if (!controller_ || messages.is_null()) { |
|
imcheng (use chromium acct)
2015/07/07 22:24:39
So, we don't use an empty list for |messages| to d
haibinlu
2015/07/07 22:37:24
right. no empty list. presentation_service_impl co
|
| + listening_for_messages_ = false; |
| return; |
| + } |
| for (size_t i = 0; i < messages.size(); ++i) { |
| if (messages[i]->type == |