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

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

Issue 674133002: Reland: Script streaming: Add an option to make the main thread block (wait for parsing) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code review (haraken@) Created 6 years, 2 months 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 "core/dom/PendingScript.h" 9 #include "core/dom/PendingScript.h"
9 #include "wtf/RefCounted.h" 10 #include "wtf/RefCounted.h"
10 11
11 #include <v8.h> 12 #include <v8.h>
12 13
13 namespace blink { 14 namespace blink {
14 15
15 class PendingScript; 16 class PendingScript;
16 class Resource; 17 class Resource;
17 class ScriptResource; 18 class ScriptResource;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ASSERT(m_client == client); 76 ASSERT(m_client == client);
76 m_client = 0; 77 m_client = 0;
77 } 78 }
78 79
79 // Called by PendingScript when data arrives from the network. 80 // Called by PendingScript when data arrives from the network.
80 void notifyAppendData(ScriptResource*); 81 void notifyAppendData(ScriptResource*);
81 void notifyFinished(Resource*); 82 void notifyFinished(Resource*);
82 83
83 // Called by ScriptStreamingTask when it has streamed all data to V8 and V8 84 // Called by ScriptStreamingTask when it has streamed all data to V8 and V8
84 // has processed it. 85 // has processed it.
85 void streamingComplete(); 86 void streamingCompleteOnBackgroundThread();
86 87
87 static void setSmallScriptThresholdForTesting(size_t threshold) 88 static void setSmallScriptThresholdForTesting(size_t threshold)
88 { 89 {
89 kSmallScriptThreshold = threshold; 90 kSmallScriptThreshold = threshold;
90 } 91 }
91 92
92 static size_t smallScriptThreshold() { return kSmallScriptThreshold; } 93 static size_t smallScriptThreshold() { return kSmallScriptThreshold; }
93 94
94 private: 95 private:
95 // 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
96 // streamed. Non-const for testing. 97 // streamed. Non-const for testing.
97 static size_t kSmallScriptThreshold; 98 static size_t kSmallScriptThreshold;
98 99
99 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding , PendingScript::Type); 100 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding , PendingScript::Type, ScriptStreamingMode);
100 101
102 void streamingComplete();
101 void notifyFinishedToClient(); 103 void notifyFinishedToClient();
102 104
105 bool shouldBlockMainThread() const
106 {
107 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl ocking && m_scriptType == PendingScript::ParsingBlocking;
108 }
109
103 static const char* startedStreamingHistogramName(PendingScript::Type); 110 static const char* startedStreamingHistogramName(PendingScript::Type);
104 111
105 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type); 112 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type);
106 113
107 // This pointer is weak. If PendingScript and its Resource are deleted 114 // This pointer is weak. If PendingScript and its Resource are deleted
108 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its 115 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its
109 // deletion by calling cancel(). 116 // deletion by calling cancel().
110 ScriptResource* m_resource; 117 ScriptResource* m_resource;
111 // Whether ScriptStreamer is detached from the Resource. In those cases, the 118 // Whether ScriptStreamer is detached from the Resource. In those cases, the
112 // 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
113 // when the loading and streaming are done. 120 // when the loading and streaming are done.
114 bool m_detached; 121 bool m_detached;
115 122
116 SourceStream* m_stream; 123 SourceStream* m_stream;
117 v8::ScriptCompiler::StreamedSource m_source; 124 v8::ScriptCompiler::StreamedSource m_source;
118 ScriptResourceClient* m_client; 125 ScriptResourceClient* m_client;
119 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; 126 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task;
120 bool m_loadingFinished; // Whether loading from the network is done. 127 bool m_loadingFinished; // Whether loading from the network is done.
121 bool m_parsingFinished; // Whether the V8 side processing is done. 128 // Whether the V8 side processing is done. Will be used by the main thread
129 // and the streamer thread; guarded by m_mutex.
130 bool m_parsingFinished;
122 // Whether we have received enough data to start the streaming. 131 // Whether we have received enough data to start the streaming.
123 bool m_haveEnoughDataForStreaming; 132 bool m_haveEnoughDataForStreaming;
124 133
125 // Whether the script source code should be retrieved from the Resource 134 // Whether the script source code should be retrieved from the Resource
126 // instead of the ScriptStreamer. 135 // instead of the ScriptStreamer; guarded by m_mutex.
127 bool m_streamingSuppressed; 136 bool m_streamingSuppressed;
128 137
129 // What kind of cached data V8 produces during streaming. 138 // What kind of cached data V8 produces during streaming.
130 unsigned m_cachedDataType; 139 unsigned m_cachedDataType;
131 140
132 // For recording metrics for different types of scripts separately. 141 // For recording metrics for different types of scripts separately.
133 PendingScript::Type m_scriptType; 142 PendingScript::Type m_scriptType;
143
144 // Streaming mode defines whether the main thread should block and wait for
145 // the parsing to complete after the load has finished. See
146 // ScriptStreamer::notifyFinished for more information.
147 ScriptStreamingMode m_scriptStreamingMode;
148 Mutex m_mutex;
149 ThreadCondition m_parsingFinishedCondition;
150 // 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 // 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 bool m_mainThreadWaitingForParserThread;
134 }; 155 };
135 156
136 } // namespace blink 157 } // namespace blink
137 158
138 #endif // ScriptStreamer_h 159 #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