Chromium Code Reviews| 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 "bindings/core/v8/ScriptStreamingMode.h" | 8 #include "bindings/core/v8/ScriptStreamingMode.h" |
| 9 #include "core/dom/PendingScript.h" | 9 #include "core/dom/PendingScript.h" |
| 10 #include "platform/heap/Handle.h" | |
| 10 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
| 11 | 12 |
| 12 #include <v8.h> | 13 #include <v8.h> |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class PendingScript; | 17 class PendingScript; |
| 17 class Resource; | 18 class Resource; |
| 18 class ScriptResource; | 19 class ScriptResource; |
| 19 class ScriptResourceClient; | 20 class ScriptResourceClient; |
| 20 class ScriptState; | 21 class ScriptState; |
| 21 class Settings; | 22 class Settings; |
| 22 class SourceStream; | 23 class SourceStream; |
| 23 | 24 |
| 24 // 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 |
| 25 // 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 |
| 26 // moment, ScriptStreamer is only used for parser blocking scripts; this means | 27 // moment, ScriptStreamer is only used for parser blocking scripts; this means |
| 27 // 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 |
| 28 // streaming. It is possible, though, that Document and the PendingScript are | 29 // streaming. It is possible, though, that Document and the PendingScript are |
| 29 // destroyed while the streaming is in progress, and ScriptStreamer handles it | 30 // destroyed while the streaming is in progress, and ScriptStreamer handles it |
| 30 // gracefully. | 31 // gracefully. |
| 31 class ScriptStreamer : public RefCounted<ScriptStreamer> { | 32 class ScriptStreamer final : public RefCountedWillBeRefCountedGarbageCollected<S criptStreamer> { |
| 32 WTF_MAKE_NONCOPYABLE(ScriptStreamer); | 33 WTF_MAKE_NONCOPYABLE(ScriptStreamer); |
| 33 public: | 34 public: |
| 35 static PassRefPtrWillBeRawPtr<ScriptStreamer> create(ScriptResource* resourc e, PendingScript::Type scriptType, ScriptStreamingMode mode, ScriptState* script State, v8::ScriptCompiler::CompileOptions compileOptions) | |
| 36 { | |
| 37 return adoptRefWillBeNoop(new ScriptStreamer(resource, scriptType, mode, scriptState, compileOptions)); | |
| 38 } | |
| 39 | |
| 40 ~ScriptStreamer(); | |
| 41 void trace(Visitor*); | |
| 42 | |
| 34 // Launches a task (on a background thread) which will stream the given | 43 // Launches a task (on a background thread) which will stream the given |
| 35 // PendingScript into V8 as it loads. It's also possible that V8 cannot | 44 // PendingScript into V8 as it loads. It's also possible that V8 cannot |
| 36 // stream the given script; in that case this function returns | 45 // stream the given script; in that case this function returns |
| 37 // false. Internally, this constructs a ScriptStreamer and attaches it to | 46 // false. Internally, this constructs a ScriptStreamer and attaches it to |
| 38 // the PendingScript. Use ScriptStreamer::addClient to get notified when the | 47 // the PendingScript. Use ScriptStreamer::addClient to get notified when the |
| 39 // streaming finishes. | 48 // streaming finishes. |
| 40 static void startStreaming(PendingScript&, Settings*, ScriptState*, PendingS cript::Type); | 49 static void startStreaming(PendingScript&, Settings*, ScriptState*, PendingS cript::Type); |
| 41 | 50 |
| 42 // Returns false if we cannot stream the given encoding. | 51 // Returns false if we cannot stream the given encoding. |
| 43 static bool convertEncoding(const char* encodingName, v8::ScriptCompiler::St reamedSource::Encoding*); | 52 static bool convertEncoding(const char* encodingName, v8::ScriptCompiler::St reamedSource::Encoding*); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl ocking && m_scriptType == PendingScript::ParsingBlocking; | 124 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl ocking && m_scriptType == PendingScript::ParsingBlocking; |
| 116 } | 125 } |
| 117 | 126 |
| 118 static const char* startedStreamingHistogramName(PendingScript::Type); | 127 static const char* startedStreamingHistogramName(PendingScript::Type); |
| 119 | 128 |
| 120 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type); | 129 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type); |
| 121 | 130 |
| 122 // This pointer is weak. If PendingScript and its Resource are deleted | 131 // This pointer is weak. If PendingScript and its Resource are deleted |
| 123 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 132 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its |
| 124 // deletion by calling cancel(). | 133 // deletion by calling cancel(). |
| 125 ScriptResource* m_resource; | 134 RawPtrWillBeMember<ScriptResource> m_resource; |
|
marja
2015/01/22 08:21:57
Why is the WillBeMember part correct? Will this re
haraken
2015/01/22 08:24:50
When an on-heap object X has a reference to anothe
| |
| 126 // Whether ScriptStreamer is detached from the Resource. In those cases, the | 135 // Whether ScriptStreamer is detached from the Resource. In those cases, the |
| 127 // script data is not needed any more, and the client won't get notified | 136 // script data is not needed any more, and the client won't get notified |
| 128 // when the loading and streaming are done. | 137 // when the loading and streaming are done. |
| 129 bool m_detached; | 138 bool m_detached; |
| 130 | 139 |
| 131 SourceStream* m_stream; | 140 SourceStream* m_stream; |
| 132 OwnPtr<v8::ScriptCompiler::StreamedSource> m_source; | 141 OwnPtr<v8::ScriptCompiler::StreamedSource> m_source; |
| 133 ScriptResourceClient* m_client; | 142 ScriptResourceClient* m_client; |
| 134 bool m_loadingFinished; // Whether loading from the network is done. | 143 bool m_loadingFinished; // Whether loading from the network is done. |
| 135 // Whether the V8 side processing is done. Will be used by the main thread | 144 // Whether the V8 side processing is done. Will be used by the main thread |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 162 // do it, otherwise the parser thread should do it. Guarded by m_mutex. | 171 // do it, otherwise the parser thread should do it. Guarded by m_mutex. |
| 163 bool m_mainThreadWaitingForParserThread; | 172 bool m_mainThreadWaitingForParserThread; |
| 164 | 173 |
| 165 // Encoding of the streamed script. Saved for sanity checking purposes. | 174 // Encoding of the streamed script. Saved for sanity checking purposes. |
| 166 v8::ScriptCompiler::StreamedSource::Encoding m_encoding; | 175 v8::ScriptCompiler::StreamedSource::Encoding m_encoding; |
| 167 }; | 176 }; |
| 168 | 177 |
| 169 } // namespace blink | 178 } // namespace blink |
| 170 | 179 |
| 171 #endif // ScriptStreamer_h | 180 #endif // ScriptStreamer_h |
| OLD | NEW |