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

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

Issue 651163002: 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: more versatile options 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 "core/dom/PendingScript.h" 8 #include "core/dom/PendingScript.h"
9 #include "wtf/RefCounted.h" 9 #include "wtf/RefCounted.h"
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ASSERT(m_client == client); 75 ASSERT(m_client == client);
76 m_client = 0; 76 m_client = 0;
77 } 77 }
78 78
79 // Called by PendingScript when data arrives from the network. 79 // Called by PendingScript when data arrives from the network.
80 void notifyAppendData(ScriptResource*); 80 void notifyAppendData(ScriptResource*);
81 void notifyFinished(Resource*); 81 void notifyFinished(Resource*);
82 82
83 // Called by ScriptStreamingTask when it has streamed all data to V8 and V8 83 // Called by ScriptStreamingTask when it has streamed all data to V8 and V8
84 // has processed it. 84 // has processed it.
85 void streamingComplete(); 85 void streamingCompleteOnBackgroundThread();
86 86
87 static void setSmallScriptThresholdForTesting(size_t threshold) 87 static void setSmallScriptThresholdForTesting(size_t threshold)
88 { 88 {
89 kSmallScriptThreshold = threshold; 89 kSmallScriptThreshold = threshold;
90 } 90 }
91 91
92 static size_t smallScriptThreshold() { return kSmallScriptThreshold; } 92 static size_t smallScriptThreshold() { return kSmallScriptThreshold; }
93 93
94 private: 94 private:
95 // Scripts whose first data chunk is smaller than this constant won't be 95 // Scripts whose first data chunk is smaller than this constant won't be
96 // streamed. Non-const for testing. 96 // streamed. Non-const for testing.
97 static size_t kSmallScriptThreshold; 97 static size_t kSmallScriptThreshold;
98 98
99 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding , PendingScript::Type); 99 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding , PendingScript::Type, bool blockMainThreadAfterLoading);
jochen (gone - plz use gerrit) 2014/10/23 09:40:59 nit. enum instead of bool maybe?
marja 2014/10/23 14:11:45 Done: Passing the mode here (as discussed).
100 100
101 void streamingComplete();
101 void notifyFinishedToClient(); 102 void notifyFinishedToClient();
102 103
104 bool shouldBlockMainThread() const
105 {
106 return m_blockMainThreadAfterLoading && m_scriptType == PendingScript::P arsingBlocking;
107 }
108
103 static const char* startedStreamingHistogramName(PendingScript::Type); 109 static const char* startedStreamingHistogramName(PendingScript::Type);
104 110
105 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type); 111 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, PendingScript::Type);
106 112
107 // This pointer is weak. If PendingScript and its Resource are deleted 113 // This pointer is weak. If PendingScript and its Resource are deleted
108 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its 114 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its
109 // deletion by calling cancel(). 115 // deletion by calling cancel().
110 ScriptResource* m_resource; 116 ScriptResource* m_resource;
111 // Whether ScriptStreamer is detached from the Resource. In those cases, the 117 // 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 118 // script data is not needed any more, and the client won't get notified
113 // when the loading and streaming are done. 119 // when the loading and streaming are done.
114 bool m_detached; 120 bool m_detached;
115 121
116 SourceStream* m_stream; 122 SourceStream* m_stream;
117 v8::ScriptCompiler::StreamedSource m_source; 123 v8::ScriptCompiler::StreamedSource m_source;
118 ScriptResourceClient* m_client; 124 ScriptResourceClient* m_client;
119 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; 125 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task;
120 bool m_loadingFinished; // Whether loading from the network is done. 126 bool m_loadingFinished; // Whether loading from the network is done.
121 bool m_parsingFinished; // Whether the V8 side processing is done. 127 // Whether the V8 side processing is done. Will be used by the main thread
128 // and the streamer thread; guarded by m_mutex.
129 bool m_parsingFinished;
122 // Whether we have received enough data to start the streaming. 130 // Whether we have received enough data to start the streaming.
123 bool m_haveEnoughDataForStreaming; 131 bool m_haveEnoughDataForStreaming;
124 132
125 // Whether the script source code should be retrieved from the Resource 133 // Whether the script source code should be retrieved from the Resource
126 // instead of the ScriptStreamer. 134 // instead of the ScriptStreamer.
127 bool m_streamingSuppressed; 135 bool m_streamingSuppressed;
128 136
129 // What kind of cached data V8 produces during streaming. 137 // What kind of cached data V8 produces during streaming.
130 unsigned m_cachedDataType; 138 unsigned m_cachedDataType;
131 139
132 // For recording metrics for different types of scripts separately. 140 // For recording metrics for different types of scripts separately.
133 PendingScript::Type m_scriptType; 141 PendingScript::Type m_scriptType;
142
143 // Whether the main thread should block and wait for the parsing to complete
144 // after the load has finished. See ScriptStreamer::notifyFinished for more
145 // information.
146 bool m_blockMainThreadAfterLoading;
147 Mutex m_mutex;
148 ThreadCondition m_parsingFinishedCondition;
134 }; 149 };
135 150
136 } // namespace blink 151 } // namespace blink
137 152
138 #endif // ScriptStreamer_h 153 #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