| 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 #include "bindings/core/v8/ScriptStreamer.h" | 5 #include "bindings/core/v8/ScriptStreamer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptStreamerThread.h" | 7 #include "bindings/core/v8/ScriptStreamerThread.h" |
| 8 #include "bindings/core/v8/V8ScriptRunner.h" | 8 #include "bindings/core/v8/V8ScriptRunner.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 void ScriptStreamer::suppressStreaming() { | 398 void ScriptStreamer::suppressStreaming() { |
| 399 MutexLocker locker(m_mutex); | 399 MutexLocker locker(m_mutex); |
| 400 DCHECK(!m_loadingFinished); | 400 DCHECK(!m_loadingFinished); |
| 401 // It can be that the parsing task has already finished (e.g., if there was | 401 // It can be that the parsing task has already finished (e.g., if there was |
| 402 // a parse error). | 402 // a parse error). |
| 403 m_streamingSuppressed = true; | 403 m_streamingSuppressed = true; |
| 404 } | 404 } |
| 405 | 405 |
| 406 void ScriptStreamer::notifyAppendData(ScriptResource* resource) { | 406 void ScriptStreamer::notifyAppendData(ScriptResource* resource) { |
| 407 DCHECK(isMainThread()); | 407 DCHECK(isMainThread()); |
| 408 DCHECK_EQ(m_resource, resource); | 408 CHECK_EQ(m_resource, resource); |
| 409 { | 409 { |
| 410 MutexLocker locker(m_mutex); | 410 MutexLocker locker(m_mutex); |
| 411 if (m_streamingSuppressed) | 411 if (m_streamingSuppressed) |
| 412 return; | 412 return; |
| 413 } | 413 } |
| 414 if (!m_haveEnoughDataForStreaming) { | 414 if (!m_haveEnoughDataForStreaming) { |
| 415 // Even if the first data chunk is small, the script can still be big | 415 // Even if the first data chunk is small, the script can still be big |
| 416 // enough - wait until the next data chunk comes before deciding whether | 416 // enough - wait until the next data chunk comes before deciding whether |
| 417 // to start the streaming. | 417 // to start the streaming. |
| 418 DCHECK(resource->resourceBuffer()); | 418 DCHECK(resource->resourceBuffer()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 passed(std::move(scriptStreamingTask)), | 493 passed(std::move(scriptStreamingTask)), |
| 494 wrapCrossThreadPersistent(this))); | 494 wrapCrossThreadPersistent(this))); |
| 495 recordStartedStreamingHistogram(m_scriptType, 1); | 495 recordStartedStreamingHistogram(m_scriptType, 1); |
| 496 } | 496 } |
| 497 if (m_stream) | 497 if (m_stream) |
| 498 m_stream->didReceiveData(this); | 498 m_stream->didReceiveData(this); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void ScriptStreamer::notifyFinished(Resource* resource) { | 501 void ScriptStreamer::notifyFinished(Resource* resource) { |
| 502 DCHECK(isMainThread()); | 502 DCHECK(isMainThread()); |
| 503 DCHECK_EQ(m_resource, resource); | 503 CHECK_EQ(m_resource, resource); |
| 504 // A special case: empty and small scripts. We didn't receive enough data to | 504 // A special case: empty and small scripts. We didn't receive enough data to |
| 505 // start the streaming before this notification. In that case, there won't | 505 // start the streaming before this notification. In that case, there won't |
| 506 // be a "parsing complete" notification either, and we should not wait for | 506 // be a "parsing complete" notification either, and we should not wait for |
| 507 // it. | 507 // it. |
| 508 if (!m_haveEnoughDataForStreaming) { | 508 if (!m_haveEnoughDataForStreaming) { |
| 509 recordNotStreamingReasonHistogram(m_scriptType, ScriptTooSmall); | 509 recordNotStreamingReasonHistogram(m_scriptType, ScriptTooSmall); |
| 510 recordStartedStreamingHistogram(m_scriptType, 0); | 510 recordStartedStreamingHistogram(m_scriptType, 0); |
| 511 suppressStreaming(); | 511 suppressStreaming(); |
| 512 } | 512 } |
| 513 if (m_stream) | 513 if (m_stream) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // The Resource might go out of scope if the script is no longer | 620 // The Resource might go out of scope if the script is no longer |
| 621 // needed. This makes PendingScript notify the ScriptStreamer when it is | 621 // needed. This makes PendingScript notify the ScriptStreamer when it is |
| 622 // destroyed. | 622 // destroyed. |
| 623 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState, | 623 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState, |
| 624 compileOption, loadingTaskRunner)); | 624 compileOption, loadingTaskRunner)); |
| 625 | 625 |
| 626 return true; | 626 return true; |
| 627 } | 627 } |
| 628 | 628 |
| 629 } // namespace blink | 629 } // namespace blink |
| OLD | NEW |