Chromium Code Reviews| 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 // wrapWeakPersistent(this) is safe because a posted task is canceled when the |
| 77 m_cancellableContinueParse->cancelAndCreate()); | 79 // task handle is destroyed on the dtor of this HTMLParserScheduler. |
|
tzik
2016/11/17 06:20:15
ditto
nhiroki
2016/11/17 08:10:16
Done.
| |
| 80 m_cancellableContinueParseTaskHandle = | |
| 81 m_loadingTaskRunner->postCancellableTask( | |
| 82 BLINK_FROM_HERE, WTF::bind(&HTMLParserScheduler::continueParsing, | |
| 83 wrapWeakPersistent(this))); | |
| 78 } | 84 } |
| 79 | 85 |
| 80 void HTMLParserScheduler::suspend() { | 86 void HTMLParserScheduler::suspend() { |
| 81 ASSERT(!m_isSuspendedWithActiveTimer); | 87 DCHECK(!m_isSuspendedWithActiveTimer); |
| 82 if (!m_cancellableContinueParse->isPending()) | 88 if (!m_cancellableContinueParseTaskHandle.isActive()) |
| 83 return; | 89 return; |
| 84 m_isSuspendedWithActiveTimer = true; | 90 m_isSuspendedWithActiveTimer = true; |
| 85 m_cancellableContinueParse->cancel(); | 91 m_cancellableContinueParseTaskHandle.cancel(); |
| 86 } | 92 } |
| 87 | 93 |
| 88 void HTMLParserScheduler::resume() { | 94 void HTMLParserScheduler::resume() { |
| 89 ASSERT(!m_cancellableContinueParse->isPending()); | 95 DCHECK(!m_cancellableContinueParseTaskHandle.isActive()); |
| 90 if (!m_isSuspendedWithActiveTimer) | 96 if (!m_isSuspendedWithActiveTimer) |
| 91 return; | 97 return; |
| 92 m_isSuspendedWithActiveTimer = false; | 98 m_isSuspendedWithActiveTimer = false; |
| 93 | 99 scheduleForResume(); |
| 94 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, | |
| 95 m_cancellableContinueParse->cancelAndCreate()); | |
| 96 } | 100 } |
| 97 | 101 |
| 98 void HTMLParserScheduler::detach() { | 102 void HTMLParserScheduler::detach() { |
| 99 m_cancellableContinueParse->cancel(); | 103 m_cancellableContinueParseTaskHandle.cancel(); |
| 100 m_isSuspendedWithActiveTimer = false; | 104 m_isSuspendedWithActiveTimer = false; |
| 101 } | 105 } |
| 102 | 106 |
| 103 inline bool HTMLParserScheduler::shouldYield( | 107 inline bool HTMLParserScheduler::shouldYield( |
| 104 const SpeculationsPumpSession& session, | 108 const SpeculationsPumpSession& session, |
| 105 bool startingScript) const { | 109 bool startingScript) const { |
| 106 if (Platform::current() | 110 if (Platform::current() |
| 107 ->currentThread() | 111 ->currentThread() |
| 108 ->scheduler() | 112 ->scheduler() |
| 109 ->shouldYieldForHighPriorityWork()) | 113 ->shouldYieldForHighPriorityWork()) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 132 bool startingScript) { | 136 bool startingScript) { |
| 133 if (shouldYield(session, startingScript)) { | 137 if (shouldYield(session, startingScript)) { |
| 134 scheduleForResume(); | 138 scheduleForResume(); |
| 135 return true; | 139 return true; |
| 136 } | 140 } |
| 137 | 141 |
| 138 return false; | 142 return false; |
| 139 } | 143 } |
| 140 | 144 |
| 141 void HTMLParserScheduler::forceResumeAfterYield() { | 145 void HTMLParserScheduler::forceResumeAfterYield() { |
| 142 ASSERT(!m_cancellableContinueParse->isPending()); | 146 DCHECK(!m_cancellableContinueParseTaskHandle.isActive()); |
| 143 m_isSuspendedWithActiveTimer = true; | 147 m_isSuspendedWithActiveTimer = true; |
| 144 } | 148 } |
| 145 | 149 |
| 146 void HTMLParserScheduler::continueParsing() { | 150 void HTMLParserScheduler::continueParsing() { |
| 147 m_parser->resumeParsingAfterYield(); | 151 m_parser->resumeParsingAfterYield(); |
| 148 } | 152 } |
| 149 | 153 |
| 150 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |