Commit 6e1e31ed authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Use a counter for DocumentLoader::BlockParser().

Replace usage of a bool by a counter to control whether or not the
parser is allowed to read new data or not.

Since WebDocumentLoader::BlockParser() is public, they may be several
components trying to pause the parser at the same time. Using a counter
make it possible to wait for all of them to call
WebDocumentLoader::ResumeParser().

This is a follow up for:
https://chromium-review.googlesource.com/982059

Bug: 822650
Change-Id: Id6d42f911f4b6e69ca942d8bf19acd296327d419
Reviewed-on: https://chromium-review.googlesource.com/992033Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548028}
parent e1756825
......@@ -473,7 +473,7 @@ void DocumentLoader::FinishedLoading(TimeTicks finish_time) {
application_cache_host_->FinishedLoadingMainResource();
if (parser_) {
if (is_parser_blocked_) {
if (parser_blocked_count_) {
finished_loading_ = true;
} else {
parser_->Finish();
......@@ -727,7 +727,7 @@ void DocumentLoader::CommitData(const char* bytes, size_t length) {
if (length)
data_received_ = true;
if (is_parser_blocked_) {
if (parser_blocked_count_) {
if (!committed_data_buffer_)
committed_data_buffer_ = SharedBuffer::Create();
committed_data_buffer_->Append(bytes, length);
......@@ -1152,13 +1152,15 @@ void DocumentLoader::ReplaceDocumentWhileExecutingJavaScriptURL(
}
void DocumentLoader::BlockParser() {
DCHECK(!is_parser_blocked_);
is_parser_blocked_ = true;
parser_blocked_count_++;
}
void DocumentLoader::ResumeParser() {
DCHECK(is_parser_blocked_);
is_parser_blocked_ = false;
parser_blocked_count_--;
DCHECK_GE(parser_blocked_count_, 0);
if (parser_blocked_count_ != 0)
return;
if (committed_data_buffer_ && !committed_data_buffer_->IsEmpty()) {
// Don't recursively process data.
......
......@@ -244,7 +244,9 @@ class CORE_EXPORT DocumentLoader
return devtools_navigation_token_;
}
// Can be used to block the parser.
// Can be used to temporarily suspend feeding the parser with new data. The
// parser will be allowed to read new data when ResumeParser() is called the
// same number of time than BlockParser().
void BlockParser();
void ResumeParser();
......@@ -387,7 +389,7 @@ class CORE_EXPORT DocumentLoader
State state_;
// Used to block the parser.
bool is_parser_blocked_ = false;
int parser_blocked_count_ = 0;
bool finished_loading_ = false;
scoped_refptr<SharedBuffer> committed_data_buffer_;
......
......@@ -148,8 +148,9 @@ class BLINK_EXPORT WebDocumentLoader {
virtual bool GetIsAdSubframe() const = 0;
// Used to pause or resume the parser. The document loader is still allowed to
// fetch new data.
// Can be used to temporarily suspend feeding the parser with new data. The
// parser will be allowed to read new data when ResumeParser() is called the
// same number of time than BlockParser().
virtual void BlockParser() = 0;
virtual void ResumeParser() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment