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 "core/dom/PendingScript.h" | 9 #include "core/dom/PendingScript.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 static PassRefPtrWillBeRawPtr<ScriptStreamer> create(ScriptResource* resourc
e, PendingScript::Type scriptType, ScriptState* scriptState, v8::ScriptCompiler:
:CompileOptions compileOptions, WebTaskRunner* loadingTaskRunner) | 36 static PassRefPtrWillBeRawPtr<ScriptStreamer> create(ScriptResource* resourc
e, PendingScript::Type scriptType, ScriptState* scriptState, v8::ScriptCompiler:
:CompileOptions compileOptions, WebTaskRunner* loadingTaskRunner) |
37 { | 37 { |
38 return adoptRefWillBeNoop(new ScriptStreamer(resource, scriptType, scrip
tState, compileOptions, loadingTaskRunner)); | 38 return adoptRefWillBeNoop(new ScriptStreamer(resource, scriptType, scrip
tState, compileOptions, loadingTaskRunner)); |
39 } | 39 } |
40 | 40 |
41 ~ScriptStreamer(); | 41 ~ScriptStreamer(); |
42 DECLARE_TRACE(); | 42 DECLARE_TRACE(); |
43 | 43 |
44 // Launches a task (on a background thread) which will stream the given | 44 // Launches a task (on a background thread) which will stream the given |
45 // PendingScript into V8 as it loads. | 45 // PendingScript into V8 as it loads. |
46 static void startStreaming(PendingScript&, PendingScript::Type, Settings*, S
criptState*, WebTaskRunner*); | 46 static void startStreaming(PendingScript*, PendingScript::Type, Settings*, S
criptState*, WebTaskRunner*); |
47 | 47 |
48 // Returns false if we cannot stream the given encoding. | 48 // Returns false if we cannot stream the given encoding. |
49 static bool convertEncoding(const char* encodingName, v8::ScriptCompiler::St
reamedSource::Encoding*); | 49 static bool convertEncoding(const char* encodingName, v8::ScriptCompiler::St
reamedSource::Encoding*); |
50 | 50 |
51 bool isFinished() const; | 51 bool isFinished() const; |
52 | 52 |
53 v8::ScriptCompiler::StreamedSource* source() { return m_source.get(); } | 53 v8::ScriptCompiler::StreamedSource* source() { return m_source.get(); } |
54 ScriptResource* resource() const { return m_resource; } | 54 ScriptResource* resource() const { return m_resource; } |
55 | 55 |
56 // Called when the script is not needed any more (e.g., loading was | 56 // Called when the script is not needed any more (e.g., loading was |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 private: | 106 private: |
107 // Scripts whose first data chunk is smaller than this constant won't be | 107 // Scripts whose first data chunk is smaller than this constant won't be |
108 // streamed. Non-const for testing. | 108 // streamed. Non-const for testing. |
109 static size_t kSmallScriptThreshold; | 109 static size_t kSmallScriptThreshold; |
110 | 110 |
111 ScriptStreamer(ScriptResource*, PendingScript::Type, ScriptState*, v8::Scrip
tCompiler::CompileOptions, WebTaskRunner*); | 111 ScriptStreamer(ScriptResource*, PendingScript::Type, ScriptState*, v8::Scrip
tCompiler::CompileOptions, WebTaskRunner*); |
112 | 112 |
113 void streamingComplete(); | 113 void streamingComplete(); |
114 void notifyFinishedToClient(); | 114 void notifyFinishedToClient(); |
115 | 115 |
116 static bool startStreamingInternal(PendingScript&, PendingScript::Type, Sett
ings*, ScriptState*, WebTaskRunner*); | 116 static bool startStreamingInternal(PendingScript*, PendingScript::Type, Sett
ings*, ScriptState*, WebTaskRunner*); |
117 | 117 |
118 // This pointer is weak. If PendingScript and its Resource are deleted | 118 // This pointer is weak. If PendingScript and its Resource are deleted |
119 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 119 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its |
120 // deletion by calling cancel(). | 120 // deletion by calling cancel(). |
121 RawPtrWillBeMember<ScriptResource> m_resource; | 121 RawPtrWillBeMember<ScriptResource> m_resource; |
122 // Whether ScriptStreamer is detached from the Resource. In those cases, the | 122 // Whether ScriptStreamer is detached from the Resource. In those cases, the |
123 // script data is not needed any more, and the client won't get notified | 123 // script data is not needed any more, and the client won't get notified |
124 // when the loading and streaming are done. | 124 // when the loading and streaming are done. |
125 bool m_detached; | 125 bool m_detached; |
126 | 126 |
(...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 |