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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLParserScheduler.cpp

Issue 2554813002: Make HTMLParserScheduler inherit from ActiveDOMObject
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLParserScheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 SpeculationsPumpSession::~SpeculationsPumpSession() {} 49 SpeculationsPumpSession::~SpeculationsPumpSession() {}
50 50
51 inline double SpeculationsPumpSession::elapsedTime() const { 51 inline double SpeculationsPumpSession::elapsedTime() const {
52 return currentTime() - m_startTime; 52 return currentTime() - m_startTime;
53 } 53 }
54 54
55 void SpeculationsPumpSession::addedElementTokens(size_t count) { 55 void SpeculationsPumpSession::addedElementTokens(size_t count) {
56 m_processedElementTokens += count; 56 m_processedElementTokens += count;
57 } 57 }
58 58
59 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser, 59 HTMLParserScheduler* HTMLParserScheduler::create(
60 Document& document,
61 HTMLDocumentParser* parser,
62 WebTaskRunner* loadingTaskRunner) {
63 return new HTMLParserScheduler(document, parser, loadingTaskRunner);
64 }
65
66 HTMLParserScheduler::HTMLParserScheduler(Document& document,
67 HTMLDocumentParser* parser,
60 WebTaskRunner* loadingTaskRunner) 68 WebTaskRunner* loadingTaskRunner)
61 : m_parser(parser), 69 : ActiveDOMObject(&document),
70 m_parser(parser),
62 m_loadingTaskRunner(loadingTaskRunner->clone()), 71 m_loadingTaskRunner(loadingTaskRunner->clone()),
63 m_isSuspendedWithActiveTimer(false) {} 72 m_isSuspendedWithActiveTimer(false) {}
64 73
65 HTMLParserScheduler::~HTMLParserScheduler() {} 74 HTMLParserScheduler::~HTMLParserScheduler() {}
66 75
67 DEFINE_TRACE(HTMLParserScheduler) { 76 DEFINE_TRACE(HTMLParserScheduler) {
68 visitor->trace(m_parser); 77 visitor->trace(m_parser);
78 ActiveDOMObject::trace(visitor);
69 } 79 }
70 80
71 bool HTMLParserScheduler::isScheduledForResume() const { 81 bool HTMLParserScheduler::isScheduledForResume() const {
72 return m_isSuspendedWithActiveTimer || 82 return m_isSuspendedWithActiveTimer ||
73 m_cancellableContinueParseTaskHandle.isActive(); 83 m_cancellableContinueParseTaskHandle.isActive();
74 } 84 }
75 85
76 void HTMLParserScheduler::scheduleForResume() { 86 void HTMLParserScheduler::scheduleForResume() {
87 if (getExecutionContext()->activeDOMObjectsAreSuspended()) {
88 DCHECK(!m_cancellableContinueParseTaskHandle.isActive());
89 m_isSuspendedWithActiveTimer = true;
90 return;
91 }
77 DCHECK(!m_isSuspendedWithActiveTimer); 92 DCHECK(!m_isSuspendedWithActiveTimer);
78 m_cancellableContinueParseTaskHandle = 93 m_cancellableContinueParseTaskHandle =
79 m_loadingTaskRunner->postCancellableTask( 94 m_loadingTaskRunner->postCancellableTask(
80 BLINK_FROM_HERE, WTF::bind(&HTMLParserScheduler::continueParsing, 95 BLINK_FROM_HERE, WTF::bind(&HTMLParserScheduler::continueParsing,
81 wrapWeakPersistent(this))); 96 wrapWeakPersistent(this)));
82 } 97 }
83 98
84 void HTMLParserScheduler::suspend() { 99 void HTMLParserScheduler::suspend() {
85 DCHECK(!m_isSuspendedWithActiveTimer); 100 DCHECK(!m_isSuspendedWithActiveTimer);
86 if (!m_cancellableContinueParseTaskHandle.isActive()) 101 if (!m_cancellableContinueParseTaskHandle.isActive())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session, 148 bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session,
134 bool startingScript) { 149 bool startingScript) {
135 if (shouldYield(session, startingScript)) { 150 if (shouldYield(session, startingScript)) {
136 scheduleForResume(); 151 scheduleForResume();
137 return true; 152 return true;
138 } 153 }
139 154
140 return false; 155 return false;
141 } 156 }
142 157
143 void HTMLParserScheduler::forceResumeAfterYield() {
144 DCHECK(!m_cancellableContinueParseTaskHandle.isActive());
145 m_isSuspendedWithActiveTimer = true;
146 }
147
148 void HTMLParserScheduler::continueParsing() { 158 void HTMLParserScheduler::continueParsing() {
149 m_parser->resumeParsingAfterYield(); 159 m_parser->resumeParsingAfterYield();
150 } 160 }
151 161
152 } // namespace blink 162 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLParserScheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698