| 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 "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  Loading... | 
|   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 removeSmallScriptThresholdForTesting() |   87     static void removeSmallScriptThresholdForTesting() | 
|   88     { |   88     { | 
|   89         kSmallScriptThreshold = 0; |   89         kSmallScriptThreshold = 0; | 
|   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); | 
|  100  |  100  | 
 |  101     void streamingComplete(); | 
|  101     void notifyFinishedToClient(); |  102     void notifyFinishedToClient(); | 
|  102  |  103  | 
|  103     static const char* startedStreamingHistogramName(PendingScript::Type); |  104     static const char* startedStreamingHistogramName(PendingScript::Type); | 
|  104  |  105  | 
|  105     static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, 
     PendingScript::Type); |  106     static bool startStreamingInternal(PendingScript&, Settings*, ScriptState*, 
     PendingScript::Type); | 
|  106  |  107  | 
|  107     // This pointer is weak. If PendingScript and its Resource are deleted |  108     // This pointer is weak. If PendingScript and its Resource are deleted | 
|  108     // before ScriptStreamer, PendingScript will notify ScriptStreamer of its |  109     // before ScriptStreamer, PendingScript will notify ScriptStreamer of its | 
|  109     // deletion by calling cancel(). |  110     // deletion by calling cancel(). | 
|  110     ScriptResource* m_resource; |  111     ScriptResource* m_resource; | 
|  111     // Whether ScriptStreamer is detached from the Resource. In those cases, the |  112     // 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 |  113     // script data is not needed any more, and the client won't get notified | 
|  113     // when the loading and streaming are done. |  114     // when the loading and streaming are done. | 
|  114     bool m_detached; |  115     bool m_detached; | 
|  115  |  116  | 
|  116     SourceStream* m_stream; |  117     SourceStream* m_stream; | 
|  117     v8::ScriptCompiler::StreamedSource m_source; |  118     v8::ScriptCompiler::StreamedSource m_source; | 
|  118     ScriptResourceClient* m_client; |  119     ScriptResourceClient* m_client; | 
|  119     WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; |  120     WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_task; | 
|  120     bool m_loadingFinished; // Whether loading from the network is done. |  121     bool m_loadingFinished; // Whether loading from the network is done. | 
|  121     bool m_parsingFinished; // Whether the V8 side processing is done. |  122     // Whether the V8 side processing is done. Will be used by the main thread | 
 |  123     // and the streamer thread; guarded by m_mutex. | 
 |  124     bool m_parsingFinished; | 
|  122     bool m_firstDataChunkReceived; |  125     bool m_firstDataChunkReceived; | 
|  123  |  126  | 
|  124     // Whether the script source code should be retrieved from the Resource |  127     // Whether the script source code should be retrieved from the Resource | 
|  125     // instead of the ScriptStreamer. |  128     // instead of the ScriptStreamer. | 
|  126     bool m_streamingSuppressed; |  129     bool m_streamingSuppressed; | 
|  127  |  130  | 
|  128     // What kind of cached data V8 produces during streaming. |  131     // What kind of cached data V8 produces during streaming. | 
|  129     unsigned m_cachedDataType; |  132     unsigned m_cachedDataType; | 
|  130  |  133  | 
|  131     // For recording metrics for different types of scripts separately. |  134     // For recording metrics for different types of scripts separately. | 
|  132     PendingScript::Type m_scriptType; |  135     PendingScript::Type m_scriptType; | 
 |  136  | 
 |  137     // Whether the main thread should block and wait for the parsing to complete | 
 |  138     // after the load has finished. See ScriptStreamer::notifyFinished for more | 
 |  139     // information. | 
 |  140     bool m_blockMainThreadAfterLoading; | 
 |  141     Mutex m_mutex; | 
 |  142     ThreadCondition m_parsingFinishedCondition; | 
|  133 }; |  143 }; | 
|  134  |  144  | 
|  135 } // namespace blink |  145 } // namespace blink | 
|  136  |  146  | 
|  137 #endif // ScriptStreamer_h |  147 #endif // ScriptStreamer_h | 
| OLD | NEW |