Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: Source/bindings/core/v8/ScriptStreamer.h

Issue 700543002: Script streaming: detect encoding later. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review (haraken@) (more) Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptStreamer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "wtf/RefCounted.h" 10 #include "wtf/RefCounted.h"
(...skipping 26 matching lines...) Expand all
37 // false. Internally, this constructs a ScriptStreamer and attaches it to 37 // false. Internally, this constructs a ScriptStreamer and attaches it to
38 // the PendingScript. Use ScriptStreamer::addClient to get notified when the 38 // the PendingScript. Use ScriptStreamer::addClient to get notified when the
39 // streaming finishes. 39 // streaming finishes.
40 static void startStreaming(PendingScript&, Settings*, ScriptState*, PendingS cript::Type); 40 static void startStreaming(PendingScript&, Settings*, ScriptState*, PendingS cript::Type);
41 41
42 bool isFinished() const 42 bool isFinished() const
43 { 43 {
44 return m_loadingFinished && (m_parsingFinished || m_streamingSuppressed) ; 44 return m_loadingFinished && (m_parsingFinished || m_streamingSuppressed) ;
45 } 45 }
46 46
47 v8::ScriptCompiler::StreamedSource* source() { return &m_source; } 47 v8::ScriptCompiler::StreamedSource* source() { return m_source.get(); }
48 ScriptResource* resource() const { return m_resource; } 48 ScriptResource* resource() const { return m_resource; }
49 49
50 // Called when the script is not needed any more (e.g., loading was 50 // Called when the script is not needed any more (e.g., loading was
51 // cancelled). After calling cancel, PendingScript can drop its reference to 51 // cancelled). After calling cancel, PendingScript can drop its reference to
52 // ScriptStreamer, and ScriptStreamer takes care of eventually deleting 52 // ScriptStreamer, and ScriptStreamer takes care of eventually deleting
53 // itself (after the V8 side has finished too). 53 // itself (after the V8 side has finished too).
54 void cancel(); 54 void cancel();
55 55
56 // When the streaming is suppressed, the data is not given to V8, but 56 // When the streaming is suppressed, the data is not given to V8, but
57 // ScriptStreamer still watches the resource load and notifies the upper 57 // ScriptStreamer still watches the resource load and notifies the upper
58 // layers when loading is finished. It is used in situations when we have 58 // layers when loading is finished. It is used in situations when we have
59 // started streaming but then we detect we don't want to stream (e.g., when 59 // started streaming but then we detect we don't want to stream (e.g., when
60 // we have the code cache for the script) and we still want to parse and 60 // we have the code cache for the script) and we still want to parse and
61 // execute it when it has finished loading. 61 // execute it when it has finished loading.
62 void suppressStreaming(); 62 void suppressStreaming();
63 bool streamingSuppressed() const { return m_streamingSuppressed; } 63 bool streamingSuppressed() const { return m_streamingSuppressed; }
64 64
65 unsigned cachedDataType() const { return m_cachedDataType; } 65 unsigned cachedDataType() const;
66 66
67 void addClient(ScriptResourceClient* client) 67 void addClient(ScriptResourceClient* client)
68 { 68 {
69 ASSERT(!m_client); 69 ASSERT(!m_client);
70 m_client = client; 70 m_client = client;
71 notifyFinishedToClient(); 71 notifyFinishedToClient();
72 } 72 }
73 73
74 void removeClient(ScriptResourceClient* client) 74 void removeClient(ScriptResourceClient* client)
75 { 75 {
(...skipping 14 matching lines...) Expand all
90 kSmallScriptThreshold = threshold; 90 kSmallScriptThreshold = threshold;
91 } 91 }
92 92
93 static size_t smallScriptThreshold() { return kSmallScriptThreshold; } 93 static size_t smallScriptThreshold() { return kSmallScriptThreshold; }
94 94
95 private: 95 private:
96 // Scripts whose first data chunk is smaller than this constant won't be 96 // Scripts whose first data chunk is smaller than this constant won't be
97 // streamed. Non-const for testing. 97 // streamed. Non-const for testing.
98 static size_t kSmallScriptThreshold; 98 static size_t kSmallScriptThreshold;
99 99
100 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding , PendingScript::Type, ScriptStreamingMode); 100 ScriptStreamer(ScriptResource*, PendingScript::Type, ScriptStreamingMode, Sc riptState*, v8::ScriptCompiler::CompileOptions);
101 101
102 void streamingComplete(); 102 void streamingComplete();
103 void notifyFinishedToClient(); 103 void notifyFinishedToClient();
104 104
105 bool shouldBlockMainThread() const 105 bool shouldBlockMainThread() const
106 { 106 {
107 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl ocking && m_scriptType == PendingScript::ParsingBlocking; 107 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl ocking && m_scriptType == PendingScript::ParsingBlocking;
108 } 108 }
109 109
110 static const char* startedStreamingHistogramName(PendingScript::Type); 110 static const char* startedStreamingHistogramName(PendingScript::Type);
111 111
112 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type); 112 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type);
113 113
114 // This pointer is weak. If PendingScript and its Resource are deleted 114 // This pointer is weak. If PendingScript and its Resource are deleted
115 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its 115 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its
116 // deletion by calling cancel(). 116 // deletion by calling cancel().
117 ScriptResource* m_resource; 117 ScriptResource* m_resource;
118 // Whether ScriptStreamer is detached from the Resource. In those cases, the 118 // Whether ScriptStreamer is detached from the Resource. In those cases, the
119 // script data is not needed any more, and the client won't get notified 119 // script data is not needed any more, and the client won't get notified
120 // when the loading and streaming are done. 120 // when the loading and streaming are done.
121 bool m_detached; 121 bool m_detached;
122 122
123 SourceStream* m_stream; 123 SourceStream* m_stream;
124 v8::ScriptCompiler::StreamedSource m_source; 124 OwnPtr<v8::ScriptCompiler::StreamedSource> m_source;
125 ScriptResourceClient* m_client; 125 ScriptResourceClient* m_client;
126 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task;
127 bool m_loadingFinished; // Whether loading from the network is done. 126 bool m_loadingFinished; // Whether loading from the network is done.
128 // Whether the V8 side processing is done. Will be used by the main thread 127 // Whether the V8 side processing is done. Will be used by the main thread
129 // and the streamer thread; guarded by m_mutex. 128 // and the streamer thread; guarded by m_mutex.
130 bool m_parsingFinished; 129 bool m_parsingFinished;
131 // Whether we have received enough data to start the streaming. 130 // Whether we have received enough data to start the streaming.
132 bool m_haveEnoughDataForStreaming; 131 bool m_haveEnoughDataForStreaming;
133 132
134 // Whether the script source code should be retrieved from the Resource 133 // Whether the script source code should be retrieved from the Resource
135 // instead of the ScriptStreamer; guarded by m_mutex. 134 // instead of the ScriptStreamer; guarded by m_mutex.
136 bool m_streamingSuppressed; 135 bool m_streamingSuppressed;
137 136
138 // What kind of cached data V8 produces during streaming. 137 // What kind of cached data V8 produces during streaming.
139 unsigned m_cachedDataType; 138 v8::ScriptCompiler::CompileOptions m_compileOptions;
139
140 RefPtr<ScriptState> m_scriptState;
140 141
141 // For recording metrics for different types of scripts separately. 142 // For recording metrics for different types of scripts separately.
142 PendingScript::Type m_scriptType; 143 PendingScript::Type m_scriptType;
143 144
144 // Streaming mode defines whether the main thread should block and wait for 145 // Streaming mode defines whether the main thread should block and wait for
145 // the parsing to complete after the load has finished. See 146 // the parsing to complete after the load has finished. See
146 // ScriptStreamer::notifyFinished for more information. 147 // ScriptStreamer::notifyFinished for more information.
147 ScriptStreamingMode m_scriptStreamingMode; 148 ScriptStreamingMode m_scriptStreamingMode;
148 Mutex m_mutex; 149 Mutex m_mutex;
149 ThreadCondition m_parsingFinishedCondition; 150 ThreadCondition m_parsingFinishedCondition;
150 // Whether the main thread is currently waiting on the parser thread in 151 // Whether the main thread is currently waiting on the parser thread in
151 // notifyFinished(). This also defines which thread should do the cleanup of 152 // notifyFinished(). This also defines which thread should do the cleanup of
152 // the parsing task: if the main thread is waiting, the main thread should 153 // the parsing task: if the main thread is waiting, the main thread should
153 // do it, otherwise the parser thread should do it. Guarded by m_mutex. 154 // do it, otherwise the parser thread should do it. Guarded by m_mutex.
154 bool m_mainThreadWaitingForParserThread; 155 bool m_mainThreadWaitingForParserThread;
155 }; 156 };
156 157
157 } // namespace blink 158 } // namespace blink
158 159
159 #endif // ScriptStreamer_h 160 #endif // ScriptStreamer_h
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptStreamer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698