| 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 "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 Loading... |
| 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. |
| 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; |
| 134 }; | 150 }; |
| 135 | 151 |
| 136 } // namespace blink | 152 } // namespace blink |
| 137 | 153 |
| 138 #endif // ScriptStreamer_h | 154 #endif // ScriptStreamer_h |
| OLD | NEW |