| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 void SpeculationsPumpSession::addedElementTokens(size_t count) | 80 void SpeculationsPumpSession::addedElementTokens(size_t count) |
| 81 { | 81 { |
| 82 m_processedElementTokens += count; | 82 m_processedElementTokens += count; |
| 83 } | 83 } |
| 84 | 84 |
| 85 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser) | 85 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser) |
| 86 : m_parser(parser) | 86 : m_parser(parser) |
| 87 , m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()->loa
dingTaskRunner()) | 87 , m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()->loa
dingTaskRunner()) |
| 88 , m_cancellableContinueParse(WTF::bind(&HTMLParserScheduler::continueParsing
, this)) | 88 , m_cancellableContinueParse(CancellableTaskFactory::create(this, &HTMLParse
rScheduler::continueParsing)) |
| 89 , m_isSuspendedWithActiveTimer(false) | 89 , m_isSuspendedWithActiveTimer(false) |
| 90 { | 90 { |
| 91 } | 91 } |
| 92 | 92 |
| 93 HTMLParserScheduler::~HTMLParserScheduler() | 93 HTMLParserScheduler::~HTMLParserScheduler() |
| 94 { | 94 { |
| 95 } | 95 } |
| 96 | 96 |
| 97 void HTMLParserScheduler::scheduleForResume() | 97 void HTMLParserScheduler::scheduleForResume() |
| 98 { | 98 { |
| 99 ASSERT(!m_isSuspendedWithActiveTimer); | 99 ASSERT(!m_isSuspendedWithActiveTimer); |
| 100 m_loadingTaskRunner->postTask(FROM_HERE, m_cancellableContinueParse.cancelAn
dCreate()); | 100 m_loadingTaskRunner->postTask(FROM_HERE, m_cancellableContinueParse->cancelA
ndCreate()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void HTMLParserScheduler::suspend() | 103 void HTMLParserScheduler::suspend() |
| 104 { | 104 { |
| 105 ASSERT(!m_isSuspendedWithActiveTimer); | 105 ASSERT(!m_isSuspendedWithActiveTimer); |
| 106 if (!m_cancellableContinueParse.isPending()) | 106 if (!m_cancellableContinueParse->isPending()) |
| 107 return; | 107 return; |
| 108 m_isSuspendedWithActiveTimer = true; | 108 m_isSuspendedWithActiveTimer = true; |
| 109 m_cancellableContinueParse.cancel(); | 109 m_cancellableContinueParse->cancel(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void HTMLParserScheduler::resume() | 112 void HTMLParserScheduler::resume() |
| 113 { | 113 { |
| 114 ASSERT(!m_cancellableContinueParse.isPending()); | 114 ASSERT(!m_cancellableContinueParse->isPending()); |
| 115 if (!m_isSuspendedWithActiveTimer) | 115 if (!m_isSuspendedWithActiveTimer) |
| 116 return; | 116 return; |
| 117 m_isSuspendedWithActiveTimer = false; | 117 m_isSuspendedWithActiveTimer = false; |
| 118 | 118 |
| 119 m_loadingTaskRunner->postTask(FROM_HERE, m_cancellableContinueParse.cancelAn
dCreate()); | 119 m_loadingTaskRunner->postTask(FROM_HERE, m_cancellableContinueParse->cancelA
ndCreate()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void HTMLParserScheduler::detach() | 122 void HTMLParserScheduler::detach() |
| 123 { | 123 { |
| 124 m_cancellableContinueParse.cancel(); | 124 m_cancellableContinueParse->cancel(); |
| 125 m_isSuspendedWithActiveTimer = false; | 125 m_isSuspendedWithActiveTimer = false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& sess
ion, bool startingScript) const | 128 inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& sess
ion, bool startingScript) const |
| 129 { | 129 { |
| 130 if (Platform::current()->currentThread()->scheduler()->shouldYieldForHighPri
orityWork()) | 130 if (Platform::current()->currentThread()->scheduler()->shouldYieldForHighPri
orityWork()) |
| 131 return true; | 131 return true; |
| 132 | 132 |
| 133 const double parserTimeLimit = 0.5; | 133 const double parserTimeLimit = 0.5; |
| 134 if (session.elapsedTime() > parserTimeLimit) | 134 if (session.elapsedTime() > parserTimeLimit) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 if (shouldYield(session, startingScript)) { | 154 if (shouldYield(session, startingScript)) { |
| 155 scheduleForResume(); | 155 scheduleForResume(); |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 void HTMLParserScheduler::forceResumeAfterYield() | 162 void HTMLParserScheduler::forceResumeAfterYield() |
| 163 { | 163 { |
| 164 ASSERT(!m_cancellableContinueParse.isPending()); | 164 ASSERT(!m_cancellableContinueParse->isPending()); |
| 165 m_isSuspendedWithActiveTimer = true; | 165 m_isSuspendedWithActiveTimer = true; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void HTMLParserScheduler::continueParsing() | 168 void HTMLParserScheduler::continueParsing() |
| 169 { | 169 { |
| 170 m_parser->resumeParsingAfterYield(); | 170 m_parser->resumeParsingAfterYield(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 } | 173 } |
| OLD | NEW |