Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2293)

Unified Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 1224953002: [PresentationAPI] Ensures only one pending message callback at a time if a frame created multiple s… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/presentation/presentation_dispatcher.cc
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc
index 24d4dcb7b2a85484eaeaff1910e9873672306a49..3e318961cf73a00faf8444f8202f96b707b5287d 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() {
@@ -342,6 +343,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) {
@@ -395,6 +398,7 @@ void PresentationDispatcher::OnDefaultSessionStarted(
if (!session_info.is_null()) {
controller_->didStartDefaultSession(
new PresentationSessionClient(session_info.Pass()));
+ StartListenForMessages();
}
}
@@ -413,6 +417,14 @@ void PresentationDispatcher::OnSessionCreated(
DCHECK(!session_info.is_null());
callback->onSuccess(new PresentationSessionClient(session_info.Pass()));
+ StartListenForMessages();
+}
+
+void PresentationDispatcher::StartListenForMessages() {
+ if (listening_for_messages_)
+ return;
+
+ listening_for_messages_ = true;
presentation_service_->ListenForSessionMessages(
base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
base::Unretained(this)));
@@ -432,9 +444,14 @@ void PresentationDispatcher::OnSessionStateChanged(
void PresentationDispatcher::OnSessionMessagesReceived(
mojo::Array<presentation::SessionMessagePtr> messages) {
+ if (!listening_for_messages_)
+ return; // messages may come after the frame navigated.
+
// When messages is null, there is an error at presentation service side.
- if (!controller_ || messages.is_null())
+ if (!controller_ || messages.is_null()) {
+ listening_for_messages_ = false;
return;
+ }
for (size_t i = 0; i < messages.size(); ++i) {
if (messages[i]->type ==
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698