| 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" | |
| 9 #include "core/dom/PendingScript.h" | 8 #include "core/dom/PendingScript.h" |
| 10 #include "wtf/RefCounted.h" | 9 #include "wtf/RefCounted.h" |
| 11 | 10 |
| 12 #include <v8.h> | 11 #include <v8.h> |
| 13 | 12 |
| 14 namespace blink { | 13 namespace blink { |
| 15 | 14 |
| 16 class PendingScript; | 15 class PendingScript; |
| 17 class Resource; | 16 class Resource; |
| 18 class ScriptResource; | 17 class ScriptResource; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ASSERT(m_client == client); | 75 ASSERT(m_client == client); |
| 77 m_client = 0; | 76 m_client = 0; |
| 78 } | 77 } |
| 79 | 78 |
| 80 // Called by PendingScript when data arrives from the network. | 79 // Called by PendingScript when data arrives from the network. |
| 81 void notifyAppendData(ScriptResource*); | 80 void notifyAppendData(ScriptResource*); |
| 82 void notifyFinished(Resource*); | 81 void notifyFinished(Resource*); |
| 83 | 82 |
| 84 // 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 |
| 85 // has processed it. | 84 // has processed it. |
| 86 void streamingCompleteOnBackgroundThread(); | 85 void streamingComplete(); |
| 87 | 86 |
| 88 static void setSmallScriptThresholdForTesting(size_t threshold) | 87 static void setSmallScriptThresholdForTesting(size_t threshold) |
| 89 { | 88 { |
| 90 kSmallScriptThreshold = threshold; | 89 kSmallScriptThreshold = threshold; |
| 91 } | 90 } |
| 92 | 91 |
| 93 static size_t smallScriptThreshold() { return kSmallScriptThreshold; } | 92 static size_t smallScriptThreshold() { return kSmallScriptThreshold; } |
| 94 | 93 |
| 95 private: | 94 private: |
| 96 // 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 |
| 97 // streamed. Non-const for testing. | 96 // streamed. Non-const for testing. |
| 98 static size_t kSmallScriptThreshold; | 97 static size_t kSmallScriptThreshold; |
| 99 | 98 |
| 100 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding
, PendingScript::Type, ScriptStreamingMode); | 99 ScriptStreamer(ScriptResource*, v8::ScriptCompiler::StreamedSource::Encoding
, PendingScript::Type); |
| 101 | 100 |
| 102 void streamingComplete(); | |
| 103 void notifyFinishedToClient(); | 101 void notifyFinishedToClient(); |
| 104 | 102 |
| 105 bool shouldBlockMainThread() const | |
| 106 { | |
| 107 return m_scriptStreamingMode == ScriptStreamingModeAllPlusBlockParsingBl
ocking && m_scriptType == PendingScript::ParsingBlocking; | |
| 108 } | |
| 109 | |
| 110 static const char* startedStreamingHistogramName(PendingScript::Type); | 103 static const char* startedStreamingHistogramName(PendingScript::Type); |
| 111 | 104 |
| 112 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*,
PendingScript::Type); | 105 static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*,
PendingScript::Type); |
| 113 | 106 |
| 114 // This pointer is weak. If PendingScript and its Resource are deleted | 107 // This pointer is weak. If PendingScript and its Resource are deleted |
| 115 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 108 // before ScriptStreamer, PendingScript will notify ScriptStreamer of its |
| 116 // deletion by calling cancel(). | 109 // deletion by calling cancel(). |
| 117 ScriptResource* m_resource; | 110 ScriptResource* m_resource; |
| 118 // Whether ScriptStreamer is detached from the Resource. In those cases, the | 111 // 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 | 112 // script data is not needed any more, and the client won't get notified |
| 120 // when the loading and streaming are done. | 113 // when the loading and streaming are done. |
| 121 bool m_detached; | 114 bool m_detached; |
| 122 | 115 |
| 123 SourceStream* m_stream; | 116 SourceStream* m_stream; |
| 124 v8::ScriptCompiler::StreamedSource m_source; | 117 v8::ScriptCompiler::StreamedSource m_source; |
| 125 ScriptResourceClient* m_client; | 118 ScriptResourceClient* m_client; |
| 126 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; | 119 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; |
| 127 bool m_loadingFinished; // Whether loading from the network is done. | 120 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 | 121 bool m_parsingFinished; // Whether the V8 side processing is done. |
| 129 // and the streamer thread; guarded by m_mutex. | |
| 130 bool m_parsingFinished; | |
| 131 // Whether we have received enough data to start the streaming. | 122 // Whether we have received enough data to start the streaming. |
| 132 bool m_haveEnoughDataForStreaming; | 123 bool m_haveEnoughDataForStreaming; |
| 133 | 124 |
| 134 // Whether the script source code should be retrieved from the Resource | 125 // Whether the script source code should be retrieved from the Resource |
| 135 // instead of the ScriptStreamer. | 126 // instead of the ScriptStreamer. |
| 136 bool m_streamingSuppressed; | 127 bool m_streamingSuppressed; |
| 137 | 128 |
| 138 // What kind of cached data V8 produces during streaming. | 129 // What kind of cached data V8 produces during streaming. |
| 139 unsigned m_cachedDataType; | 130 unsigned m_cachedDataType; |
| 140 | 131 |
| 141 // For recording metrics for different types of scripts separately. | 132 // For recording metrics for different types of scripts separately. |
| 142 PendingScript::Type m_scriptType; | 133 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 }; | 134 }; |
| 151 | 135 |
| 152 } // namespace blink | 136 } // namespace blink |
| 153 | 137 |
| 154 #endif // ScriptStreamer_h | 138 #endif // ScriptStreamer_h |
| OLD | NEW |