| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ScriptStreamer_h | 5 #ifndef ScriptStreamer_h |
| 6 #define ScriptStreamer_h | 6 #define ScriptStreamer_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/RefCounted.h" | 10 #include "wtf/RefCounted.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class SourceStream; | 22 class SourceStream; |
| 23 class WebTaskRunner; | 23 class WebTaskRunner; |
| 24 | 24 |
| 25 // ScriptStreamer streams incomplete script data to V8 so that it can be parsed | 25 // ScriptStreamer streams incomplete script data to V8 so that it can be parsed |
| 26 // while it's loaded. PendingScript holds a reference to ScriptStreamer. At the | 26 // while it's loaded. PendingScript holds a reference to ScriptStreamer. At the |
| 27 // moment, ScriptStreamer is only used for parser blocking scripts; this means | 27 // moment, ScriptStreamer is only used for parser blocking scripts; this means |
| 28 // that the Document stays stable and no other scripts are executing while we're | 28 // that the Document stays stable and no other scripts are executing while we're |
| 29 // streaming. It is possible, though, that Document and the PendingScript are | 29 // streaming. It is possible, though, that Document and the PendingScript are |
| 30 // destroyed while the streaming is in progress, and ScriptStreamer handles it | 30 // destroyed while the streaming is in progress, and ScriptStreamer handles it |
| 31 // gracefully. | 31 // gracefully. |
| 32 class CORE_EXPORT ScriptStreamer final : public RefCountedWillBeRefCountedGarbag
eCollected<ScriptStreamer> { | 32 class CORE_EXPORT ScriptStreamer final : public RefCountedGarbageCollected<Scrip
tStreamer> { |
| 33 WTF_MAKE_NONCOPYABLE(ScriptStreamer); | 33 WTF_MAKE_NONCOPYABLE(ScriptStreamer); |
| 34 public: | 34 public: |
| 35 enum Type { | 35 enum Type { |
| 36 ParsingBlocking, | 36 ParsingBlocking, |
| 37 Deferred, | 37 Deferred, |
| 38 Async | 38 Async |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 ~ScriptStreamer(); | 41 ~ScriptStreamer(); |
| 42 DECLARE_TRACE(); | 42 DECLARE_TRACE(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 s_smallScriptThreshold = threshold; | 91 s_smallScriptThreshold = threshold; |
| 92 } | 92 } |
| 93 | 93 |
| 94 static size_t smallScriptThreshold() { return s_smallScriptThreshold; } | 94 static size_t smallScriptThreshold() { return s_smallScriptThreshold; } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 // Scripts whose first data chunk is smaller than this constant won't be | 97 // Scripts whose first data chunk is smaller than this constant won't be |
| 98 // streamed. Non-const for testing. | 98 // streamed. Non-const for testing. |
| 99 static size_t s_smallScriptThreshold; | 99 static size_t s_smallScriptThreshold; |
| 100 | 100 |
| 101 static PassRefPtrWillBeRawPtr<ScriptStreamer> create(PendingScript* script,
Type scriptType, ScriptState* scriptState, v8::ScriptCompiler::CompileOptions co
mpileOptions, WebTaskRunner* loadingTaskRunner) | 101 static RawPtr<ScriptStreamer> create(PendingScript* script, Type scriptType,
ScriptState* scriptState, v8::ScriptCompiler::CompileOptions compileOptions, We
bTaskRunner* loadingTaskRunner) |
| 102 { | 102 { |
| 103 return adoptRefWillBeNoop(new ScriptStreamer(script, scriptType, scriptS
tate, compileOptions, loadingTaskRunner)); | 103 return new ScriptStreamer(script, scriptType, scriptState, compileOption
s, loadingTaskRunner); |
| 104 } | 104 } |
| 105 ScriptStreamer(PendingScript*, Type, ScriptState*, v8::ScriptCompiler::Compi
leOptions, WebTaskRunner*); | 105 ScriptStreamer(PendingScript*, Type, ScriptState*, v8::ScriptCompiler::Compi
leOptions, WebTaskRunner*); |
| 106 | 106 |
| 107 void streamingComplete(); | 107 void streamingComplete(); |
| 108 void notifyFinishedToClient(); | 108 void notifyFinishedToClient(); |
| 109 | 109 |
| 110 static bool startStreamingInternal(PendingScript*, Type, Settings*, ScriptSt
ate*, WebTaskRunner*); | 110 static bool startStreamingInternal(PendingScript*, Type, Settings*, ScriptSt
ate*, WebTaskRunner*); |
| 111 | 111 |
| 112 RawPtrWillBeMember<PendingScript> m_pendingScript; | 112 Member<PendingScript> m_pendingScript; |
| 113 // This pointer is weak. If PendingScript and its Resource are deleted | 113 // This pointer is weak. If PendingScript and its Resource are deleted |
| 114 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 114 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its |
| 115 // deletion by calling cancel(). | 115 // deletion by calling cancel(). |
| 116 RawPtrWillBeMember<ScriptResource> m_resource; | 116 Member<ScriptResource> m_resource; |
| 117 // Whether ScriptStreamer is detached from the Resource. In those cases, the | 117 // Whether ScriptStreamer is detached from the Resource. In those cases, the |
| 118 // script data is not needed any more, and the client won't get notified | 118 // script data is not needed any more, and the client won't get notified |
| 119 // when the loading and streaming are done. | 119 // when the loading and streaming are done. |
| 120 bool m_detached; | 120 bool m_detached; |
| 121 | 121 |
| 122 SourceStream* m_stream; | 122 SourceStream* m_stream; |
| 123 OwnPtr<v8::ScriptCompiler::StreamedSource> m_source; | 123 OwnPtr<v8::ScriptCompiler::StreamedSource> m_source; |
| 124 bool m_loadingFinished; // Whether loading from the network is done. | 124 bool m_loadingFinished; // Whether loading from the network is done. |
| 125 // Whether the V8 side processing is done. Will be used by the main thread | 125 // Whether the V8 side processing is done. Will be used by the main thread |
| 126 // and the streamer thread; guarded by m_mutex. | 126 // and the streamer thread; guarded by m_mutex. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 150 | 150 |
| 151 // Encoding of the streamed script. Saved for sanity checking purposes. | 151 // Encoding of the streamed script. Saved for sanity checking purposes. |
| 152 v8::ScriptCompiler::StreamedSource::Encoding m_encoding; | 152 v8::ScriptCompiler::StreamedSource::Encoding m_encoding; |
| 153 | 153 |
| 154 OwnPtr<WebTaskRunner> m_loadingTaskRunner; | 154 OwnPtr<WebTaskRunner> m_loadingTaskRunner; |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace blink | 157 } // namespace blink |
| 158 | 158 |
| 159 #endif // ScriptStreamer_h | 159 #endif // ScriptStreamer_h |
| OLD | NEW |