| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 class HTMLParserScheduler { | 62 class HTMLParserScheduler { |
| 63 WTF_MAKE_NONCOPYABLE(HTMLParserScheduler); WTF_MAKE_FAST_ALLOCATED; | 63 WTF_MAKE_NONCOPYABLE(HTMLParserScheduler); WTF_MAKE_FAST_ALLOCATED; |
| 64 public: | 64 public: |
| 65 static PassOwnPtr<HTMLParserScheduler> create(HTMLDocumentParser* parser) | 65 static PassOwnPtr<HTMLParserScheduler> create(HTMLDocumentParser* parser) |
| 66 { | 66 { |
| 67 return adoptPtr(new HTMLParserScheduler(parser)); | 67 return adoptPtr(new HTMLParserScheduler(parser)); |
| 68 } | 68 } |
| 69 ~HTMLParserScheduler(); | 69 ~HTMLParserScheduler(); |
| 70 | 70 |
| 71 // Inline as this is called after every token in the parser. | |
| 72 void checkForYieldBeforeToken(PumpSession& session) | |
| 73 { | |
| 74 if (session.processedTokens > parserChunkSize || session.didSeeScript) { | |
| 75 // currentTime() can be expensive. By delaying, we avoided calling | |
| 76 // currentTime() when constructing non-yielding PumpSessions. | |
| 77 if (!session.startTime) | |
| 78 session.startTime = currentTime(); | |
| 79 | |
| 80 session.processedTokens = 0; | |
| 81 session.didSeeScript = false; | |
| 82 | |
| 83 double elapsedTime = currentTime() - session.startTime; | |
| 84 if (elapsedTime > parserTimeLimit) | |
| 85 session.needsYield = true; | |
| 86 } | |
| 87 ++session.processedTokens; | |
| 88 } | |
| 89 | |
| 90 void scheduleForResume(); | 71 void scheduleForResume(); |
| 91 bool isScheduledForResume() const { return m_isSuspendedWithActiveTimer || m
_continueNextChunkTimer.isActive(); } | 72 bool isScheduledForResume() const { return m_isSuspendedWithActiveTimer || m
_continueNextChunkTimer.isActive(); } |
| 92 | 73 |
| 93 void suspend(); | 74 void suspend(); |
| 94 void resume(); | 75 void resume(); |
| 95 | 76 |
| 96 private: | 77 private: |
| 97 static const double parserTimeLimit; | 78 static const double parserTimeLimit; |
| 98 static const int parserChunkSize; | 79 static const int parserChunkSize; |
| 99 | 80 |
| 100 HTMLParserScheduler(HTMLDocumentParser*); | 81 HTMLParserScheduler(HTMLDocumentParser*); |
| 101 | 82 |
| 102 void continueNextChunkTimerFired(Timer<HTMLParserScheduler>*); | 83 void continueNextChunkTimerFired(Timer<HTMLParserScheduler>*); |
| 103 | 84 |
| 104 HTMLDocumentParser* m_parser; | 85 HTMLDocumentParser* m_parser; |
| 105 | 86 |
| 106 Timer<HTMLParserScheduler> m_continueNextChunkTimer; | 87 Timer<HTMLParserScheduler> m_continueNextChunkTimer; |
| 107 bool m_isSuspendedWithActiveTimer; | 88 bool m_isSuspendedWithActiveTimer; |
| 108 }; | 89 }; |
| 109 | 90 |
| 110 } | 91 } |
| 111 | 92 |
| 112 #endif | 93 #endif |
| OLD | NEW |