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 18 matching lines...) Expand all Loading... |
29 #include "core/html/parser/NestingLevelIncrementer.h" | 29 #include "core/html/parser/NestingLevelIncrementer.h" |
30 #include "platform/scheduler/CancellableTaskFactory.h" | 30 #include "platform/scheduler/CancellableTaskFactory.h" |
31 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
32 #include "wtf/PassOwnPtr.h" | 32 #include "wtf/PassOwnPtr.h" |
33 #include "wtf/RefPtr.h" | 33 #include "wtf/RefPtr.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 class Document; | 37 class Document; |
38 class HTMLDocumentParser; | 38 class HTMLDocumentParser; |
| 39 class WebTaskRunner; |
39 | 40 |
40 class ActiveParserSession : public NestingLevelIncrementer { | 41 class ActiveParserSession : public NestingLevelIncrementer { |
41 STACK_ALLOCATED(); | 42 STACK_ALLOCATED(); |
42 public: | 43 public: |
43 ActiveParserSession(unsigned& nestingLevel, Document*); | 44 ActiveParserSession(unsigned& nestingLevel, Document*); |
44 ~ActiveParserSession(); | 45 ~ActiveParserSession(); |
45 | 46 |
46 private: | 47 private: |
47 RefPtrWillBeMember<Document> m_document; | 48 RefPtrWillBeMember<Document> m_document; |
48 }; | 49 }; |
(...skipping 16 matching lines...) Expand all Loading... |
65 size_t processedElementTokens() const { return m_processedElementTokens; } | 66 size_t processedElementTokens() const { return m_processedElementTokens; } |
66 | 67 |
67 private: | 68 private: |
68 double m_startTime; | 69 double m_startTime; |
69 size_t m_processedElementTokens; | 70 size_t m_processedElementTokens; |
70 }; | 71 }; |
71 | 72 |
72 class HTMLParserScheduler { | 73 class HTMLParserScheduler { |
73 WTF_MAKE_NONCOPYABLE(HTMLParserScheduler); WTF_MAKE_FAST_ALLOCATED(HTMLParse
rScheduler); | 74 WTF_MAKE_NONCOPYABLE(HTMLParserScheduler); WTF_MAKE_FAST_ALLOCATED(HTMLParse
rScheduler); |
74 public: | 75 public: |
75 static PassOwnPtr<HTMLParserScheduler> create(HTMLDocumentParser* parser) | 76 static PassOwnPtr<HTMLParserScheduler> create(HTMLDocumentParser* parser, We
bTaskRunner* loadingTaskRunner) |
76 { | 77 { |
77 return adoptPtr(new HTMLParserScheduler(parser)); | 78 return adoptPtr(new HTMLParserScheduler(parser, loadingTaskRunner)); |
78 } | 79 } |
79 ~HTMLParserScheduler(); | 80 ~HTMLParserScheduler(); |
80 | 81 |
81 bool isScheduledForResume() const { return m_isSuspendedWithActiveTimer || m
_cancellableContinueParse->isPending(); } | 82 bool isScheduledForResume() const { return m_isSuspendedWithActiveTimer || m
_cancellableContinueParse->isPending(); } |
82 | 83 |
83 void scheduleForResume(); | 84 void scheduleForResume(); |
84 bool yieldIfNeeded(const SpeculationsPumpSession&, bool startingScript); | 85 bool yieldIfNeeded(const SpeculationsPumpSession&, bool startingScript); |
85 | 86 |
86 /** | 87 /** |
87 * Can only be called if this scheduler is suspended. If this is called, | 88 * Can only be called if this scheduler is suspended. If this is called, |
88 * then after the scheduler is resumed by calling resume(), this call | 89 * then after the scheduler is resumed by calling resume(), this call |
89 * ensures that HTMLDocumentParser::resumeAfterYield will be called. Used to | 90 * ensures that HTMLDocumentParser::resumeAfterYield will be called. Used to |
90 * signal this scheduler that the background html parser sent chunks to | 91 * signal this scheduler that the background html parser sent chunks to |
91 * HTMLDocumentParser while it was suspended. | 92 * HTMLDocumentParser while it was suspended. |
92 */ | 93 */ |
93 void forceResumeAfterYield(); | 94 void forceResumeAfterYield(); |
94 | 95 |
95 void suspend(); | 96 void suspend(); |
96 void resume(); | 97 void resume(); |
97 | 98 |
98 void detach(); // Clear active tasks if any. | 99 void detach(); // Clear active tasks if any. |
99 | 100 |
100 private: | 101 private: |
101 explicit HTMLParserScheduler(HTMLDocumentParser*); | 102 HTMLParserScheduler(HTMLDocumentParser*, WebTaskRunner*); |
102 | 103 |
103 bool shouldYield(const SpeculationsPumpSession&, bool startingScript) const; | 104 bool shouldYield(const SpeculationsPumpSession&, bool startingScript) const; |
104 void continueParsing(); | 105 void continueParsing(); |
105 | 106 |
106 HTMLDocumentParser* m_parser; | 107 HTMLDocumentParser* m_parser; |
107 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED | 108 OwnPtr<WebTaskRunner> m_loadingTaskRunner; |
108 | 109 |
109 OwnPtr<CancellableTaskFactory> m_cancellableContinueParse; | 110 OwnPtr<CancellableTaskFactory> m_cancellableContinueParse; |
110 bool m_isSuspendedWithActiveTimer; | 111 bool m_isSuspendedWithActiveTimer; |
111 }; | 112 }; |
112 | 113 |
113 } | 114 } |
114 | 115 |
115 #endif | 116 #endif |
OLD | NEW |