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 ScriptStreamerImpl_h | 5 #ifndef ScriptStreamerImpl_h |
6 #define ScriptStreamerImpl_h | 6 #define ScriptStreamerImpl_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "bindings/core/v8/ScriptStreamer.h" | 10 #include "bindings/core/v8/ScriptStreamer.h" |
11 #include "core/CoreExport.h" | 11 #include "core/CoreExport.h" |
| 12 #include "platform/WebTaskRunner.h" |
12 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
13 #include "platform/wtf/Noncopyable.h" | 14 #include "platform/wtf/Noncopyable.h" |
14 #include "platform/wtf/text/WTFString.h" | 15 #include "platform/wtf/text/WTFString.h" |
15 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class PendingScript; | 20 class ClassicPendingScript; |
20 class Resource; | 21 class Resource; |
21 class ScriptResource; | 22 class ScriptResource; |
22 class ScriptState; | 23 class ScriptState; |
23 class Settings; | 24 class Settings; |
24 class SourceStream; | 25 class SourceStream; |
25 class WebTaskRunner; | |
26 | 26 |
27 class CORE_EXPORT ScriptStreamerImpl final : public ScriptStreamer { | 27 class CORE_EXPORT ScriptStreamerImpl final : public ScriptStreamer { |
28 WTF_MAKE_NONCOPYABLE(ScriptStreamerImpl); | 28 WTF_MAKE_NONCOPYABLE(ScriptStreamerImpl); |
29 | 29 |
30 public: | 30 public: |
31 ~ScriptStreamerImpl(); | 31 ~ScriptStreamerImpl(); |
32 DECLARE_TRACE(); | 32 DECLARE_TRACE(); |
33 | 33 |
34 // Launches a task (on a background thread) which will stream the given | 34 // Launches a task (on a background thread) which will stream the given |
35 // PendingScript into V8 as it loads. | 35 // ClassicPendingScript into V8 as it loads. |
36 static void StartStreaming(PendingScript*, | 36 static void StartStreaming(ClassicPendingScript*, |
37 Type, | 37 Type, |
38 Settings*, | 38 Settings*, |
39 ScriptState*, | 39 ScriptState*, |
40 RefPtr<WebTaskRunner>); | 40 RefPtr<WebTaskRunner>); |
41 | 41 |
42 // Returns false if we cannot stream the given encoding. | 42 // Returns false if we cannot stream the given encoding. |
43 static bool ConvertEncoding(const char* encoding_name, | 43 static bool ConvertEncoding(const char* encoding_name, |
44 v8::ScriptCompiler::StreamedSource::Encoding*); | 44 v8::ScriptCompiler::StreamedSource::Encoding*); |
45 | 45 |
46 v8::ScriptCompiler::StreamedSource* Source() override { | 46 v8::ScriptCompiler::StreamedSource* Source() override { |
(...skipping 15 matching lines...) Expand all Loading... |
62 static void SetSmallScriptThresholdForTesting(size_t threshold) { | 62 static void SetSmallScriptThresholdForTesting(size_t threshold) { |
63 small_script_threshold_ = threshold; | 63 small_script_threshold_ = threshold; |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 // Scripts whose first data chunk is smaller than this constant won't be | 67 // Scripts whose first data chunk is smaller than this constant won't be |
68 // streamed. Non-const for testing. | 68 // streamed. Non-const for testing. |
69 static size_t small_script_threshold_; | 69 static size_t small_script_threshold_; |
70 | 70 |
71 static ScriptStreamerImpl* Create( | 71 static ScriptStreamerImpl* Create( |
72 PendingScript* script, | 72 ClassicPendingScript* script, |
73 Type script_type, | 73 Type script_type, |
74 ScriptState* script_state, | 74 ScriptState* script_state, |
75 v8::ScriptCompiler::CompileOptions compile_options, | 75 v8::ScriptCompiler::CompileOptions compile_options, |
76 RefPtr<WebTaskRunner> loading_task_runner) { | 76 RefPtr<WebTaskRunner> loading_task_runner) { |
77 return new ScriptStreamerImpl(script, script_type, script_state, | 77 return new ScriptStreamerImpl(script, script_type, script_state, |
78 compile_options, | 78 compile_options, |
79 std::move(loading_task_runner)); | 79 std::move(loading_task_runner)); |
80 } | 80 } |
81 ScriptStreamerImpl(PendingScript*, | 81 ScriptStreamerImpl(ClassicPendingScript*, |
82 Type, | 82 Type, |
83 ScriptState*, | 83 ScriptState*, |
84 v8::ScriptCompiler::CompileOptions, | 84 v8::ScriptCompiler::CompileOptions, |
85 RefPtr<WebTaskRunner>); | 85 RefPtr<WebTaskRunner>); |
86 | 86 |
87 void StreamingComplete(); | 87 void StreamingComplete(); |
88 void NotifyFinishedToClient(); | 88 void NotifyFinishedToClient(); |
89 | 89 |
90 bool IsFinished() const override; | 90 bool IsFinished() const override; |
91 bool StreamingSuppressed() const override { return streaming_suppressed_; } | 91 bool StreamingSuppressed() const override { return streaming_suppressed_; } |
92 void NotifyAppendData(ScriptResource*) override; | 92 void NotifyAppendData(ScriptResource*) override; |
93 void NotifyFinished(Resource*) override; | 93 void NotifyFinished(Resource*) override; |
94 void Cancel() override; | 94 void Cancel() override; |
95 | 95 |
96 static bool StartStreamingInternal(PendingScript*, | 96 static bool StartStreamingInternal(ClassicPendingScript*, |
97 Type, | 97 Type, |
98 Settings*, | 98 Settings*, |
99 ScriptState*, | 99 ScriptState*, |
100 RefPtr<WebTaskRunner>); | 100 RefPtr<WebTaskRunner>); |
101 | 101 |
102 Member<PendingScript> pending_script_; | 102 Member<ClassicPendingScript> pending_script_; |
103 // This pointer is weak. If PendingScript and its Resource are deleted | 103 // This pointer is weak. If ClassicPendingScript and its Resource are deleted |
104 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 104 // before ScriptStreamer, ClassicPendingScript will notify ScriptStreamer of |
105 // deletion by calling cancel(). | 105 // its deletion by calling cancel(). |
106 Member<ScriptResource> resource_; | 106 Member<ScriptResource> resource_; |
107 // Whether ScriptStreamer is detached from the Resource. In those cases, the | 107 // Whether ScriptStreamer is detached from the Resource. In those cases, the |
108 // script data is not needed any more, and the client won't get notified | 108 // script data is not needed any more, and the client won't get notified |
109 // when the loading and streaming are done. | 109 // when the loading and streaming are done. |
110 bool detached_; | 110 bool detached_; |
111 | 111 |
112 SourceStream* stream_; | 112 SourceStream* stream_; |
113 std::unique_ptr<v8::ScriptCompiler::StreamedSource> source_; | 113 std::unique_ptr<v8::ScriptCompiler::StreamedSource> source_; |
114 bool loading_finished_; // Whether loading from the network is done. | 114 bool loading_finished_; // Whether loading from the network is done. |
115 bool parsing_finished_; // Whether the V8 side processing is done. | 115 bool parsing_finished_; // Whether the V8 side processing is done. |
(...skipping 20 matching lines...) Expand all Loading... |
136 | 136 |
137 // Encoding of the streamed script. Saved for sanity checking purposes. | 137 // Encoding of the streamed script. Saved for sanity checking purposes. |
138 v8::ScriptCompiler::StreamedSource::Encoding encoding_; | 138 v8::ScriptCompiler::StreamedSource::Encoding encoding_; |
139 | 139 |
140 RefPtr<WebTaskRunner> loading_task_runner_; | 140 RefPtr<WebTaskRunner> loading_task_runner_; |
141 }; | 141 }; |
142 | 142 |
143 } // namespace blink | 143 } // namespace blink |
144 | 144 |
145 #endif // ScriptStreamer_h | 145 #endif // ScriptStreamer_h |
OLD | NEW |