| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(HTMLDocumentParser* parser, |
| 60 WebTaskRunner* loadingTaskRunner) | 60 WebTaskRunner* loadingTaskRunner) |
| 61 : m_parser(parser), | 61 : m_parser(parser), |
| 62 m_loadingTaskRunner(loadingTaskRunner->clone()), | 62 m_loadingTaskRunner(loadingTaskRunner->clone()), |
| 63 m_cancellableContinueParse(CancellableTaskFactory::create( | |
| 64 this, | |
| 65 &HTMLParserScheduler::continueParsing)), | |
| 66 m_isSuspendedWithActiveTimer(false) {} | 63 m_isSuspendedWithActiveTimer(false) {} |
| 67 | 64 |
| 68 HTMLParserScheduler::~HTMLParserScheduler() {} | 65 HTMLParserScheduler::~HTMLParserScheduler() {} |
| 69 | 66 |
| 70 DEFINE_TRACE(HTMLParserScheduler) { | 67 DEFINE_TRACE(HTMLParserScheduler) { |
| 71 visitor->trace(m_parser); | 68 visitor->trace(m_parser); |
| 72 } | 69 } |
| 73 | 70 |
| 71 bool HTMLParserScheduler::isScheduledForResume() const { |
| 72 return m_isSuspendedWithActiveTimer || |
| 73 m_cancellableContinueParseTaskHandle.isActive(); |
| 74 } |
| 75 |
| 74 void HTMLParserScheduler::scheduleForResume() { | 76 void HTMLParserScheduler::scheduleForResume() { |
| 75 ASSERT(!m_isSuspendedWithActiveTimer); | 77 DCHECK(!m_isSuspendedWithActiveTimer); |
| 76 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, | 78 m_cancellableContinueParseTaskHandle = |
| 77 m_cancellableContinueParse->cancelAndCreate()); | 79 m_loadingTaskRunner->postCancellableTask( |
| 80 BLINK_FROM_HERE, WTF::bind(&HTMLParserScheduler::continueParsing, |
| 81 wrapWeakPersistent(this))); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void HTMLParserScheduler::suspend() { | 84 void HTMLParserScheduler::suspend() { |
| 81 ASSERT(!m_isSuspendedWithActiveTimer); | 85 DCHECK(!m_isSuspendedWithActiveTimer); |
| 82 if (!m_cancellableContinueParse->isPending()) | 86 if (!m_cancellableContinueParseTaskHandle.isActive()) |
| 83 return; | 87 return; |
| 84 m_isSuspendedWithActiveTimer = true; | 88 m_isSuspendedWithActiveTimer = true; |
| 85 m_cancellableContinueParse->cancel(); | 89 m_cancellableContinueParseTaskHandle.cancel(); |
| 86 } | 90 } |
| 87 | 91 |
| 88 void HTMLParserScheduler::resume() { | 92 void HTMLParserScheduler::resume() { |
| 89 ASSERT(!m_cancellableContinueParse->isPending()); | 93 DCHECK(!m_cancellableContinueParseTaskHandle.isActive()); |
| 90 if (!m_isSuspendedWithActiveTimer) | 94 if (!m_isSuspendedWithActiveTimer) |
| 91 return; | 95 return; |
| 92 m_isSuspendedWithActiveTimer = false; | 96 m_isSuspendedWithActiveTimer = false; |
| 93 | 97 scheduleForResume(); |
| 94 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, | |
| 95 m_cancellableContinueParse->cancelAndCreate()); | |
| 96 } | 98 } |
| 97 | 99 |
| 98 void HTMLParserScheduler::detach() { | 100 void HTMLParserScheduler::detach() { |
| 99 m_cancellableContinueParse->cancel(); | 101 m_cancellableContinueParseTaskHandle.cancel(); |
| 100 m_isSuspendedWithActiveTimer = false; | 102 m_isSuspendedWithActiveTimer = false; |
| 101 } | 103 } |
| 102 | 104 |
| 103 inline bool HTMLParserScheduler::shouldYield( | 105 inline bool HTMLParserScheduler::shouldYield( |
| 104 const SpeculationsPumpSession& session, | 106 const SpeculationsPumpSession& session, |
| 105 bool startingScript) const { | 107 bool startingScript) const { |
| 106 if (Platform::current() | 108 if (Platform::current() |
| 107 ->currentThread() | 109 ->currentThread() |
| 108 ->scheduler() | 110 ->scheduler() |
| 109 ->shouldYieldForHighPriorityWork()) | 111 ->shouldYieldForHighPriorityWork()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 132 bool startingScript) { | 134 bool startingScript) { |
| 133 if (shouldYield(session, startingScript)) { | 135 if (shouldYield(session, startingScript)) { |
| 134 scheduleForResume(); | 136 scheduleForResume(); |
| 135 return true; | 137 return true; |
| 136 } | 138 } |
| 137 | 139 |
| 138 return false; | 140 return false; |
| 139 } | 141 } |
| 140 | 142 |
| 141 void HTMLParserScheduler::forceResumeAfterYield() { | 143 void HTMLParserScheduler::forceResumeAfterYield() { |
| 142 ASSERT(!m_cancellableContinueParse->isPending()); | 144 DCHECK(!m_cancellableContinueParseTaskHandle.isActive()); |
| 143 m_isSuspendedWithActiveTimer = true; | 145 m_isSuspendedWithActiveTimer = true; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void HTMLParserScheduler::continueParsing() { | 148 void HTMLParserScheduler::continueParsing() { |
| 147 m_parser->resumeParsingAfterYield(); | 149 m_parser->resumeParsingAfterYield(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |