| 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 "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptStreamer.h" | 6 #include "bindings/core/v8/ScriptStreamer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptStreamerThread.h" | 8 #include "bindings/core/v8/ScriptStreamerThread.h" |
| 9 #include "bindings/core/v8/V8ScriptRunner.h" | 9 #include "bindings/core/v8/V8ScriptRunner.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 SourceStream() | 165 SourceStream() |
| 166 : v8::ScriptCompiler::ExternalSourceStream() | 166 : v8::ScriptCompiler::ExternalSourceStream() |
| 167 , m_cancelled(false) | 167 , m_cancelled(false) |
| 168 , m_finished(false) | 168 , m_finished(false) |
| 169 , m_queueLeadPosition(0) | 169 , m_queueLeadPosition(0) |
| 170 , m_queueTailPosition(0) | 170 , m_queueTailPosition(0) |
| 171 , m_bookmarkPosition(0) | 171 , m_bookmarkPosition(0) |
| 172 { | 172 { |
| 173 } | 173 } |
| 174 | 174 |
| 175 virtual ~SourceStream() { } | 175 virtual ~SourceStream() override { } |
| 176 | 176 |
| 177 // Called by V8 on a background thread. Should block until we can return | 177 // Called by V8 on a background thread. Should block until we can return |
| 178 // some data. | 178 // some data. |
| 179 virtual size_t GetMoreData(const uint8_t** src) override | 179 size_t GetMoreData(const uint8_t** src) override |
| 180 { | 180 { |
| 181 ASSERT(!isMainThread()); | 181 ASSERT(!isMainThread()); |
| 182 { | 182 { |
| 183 MutexLocker locker(m_mutex); | 183 MutexLocker locker(m_mutex); |
| 184 if (m_cancelled) | 184 if (m_cancelled) |
| 185 return 0; | 185 return 0; |
| 186 } | 186 } |
| 187 size_t length = 0; | 187 size_t length = 0; |
| 188 // This will wait until there is data. | 188 // This will wait until there is data. |
| 189 m_dataQueue.consume(src, &length); | 189 m_dataQueue.consume(src, &length); |
| 190 { | 190 { |
| 191 MutexLocker locker(m_mutex); | 191 MutexLocker locker(m_mutex); |
| 192 if (m_cancelled) | 192 if (m_cancelled) |
| 193 return 0; | 193 return 0; |
| 194 } | 194 } |
| 195 m_queueLeadPosition += length; | 195 m_queueLeadPosition += length; |
| 196 return length; | 196 return length; |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Called by V8 on background thread. | 199 // Called by V8 on background thread. |
| 200 virtual bool SetBookmark() override | 200 bool SetBookmark() override |
| 201 { | 201 { |
| 202 ASSERT(!isMainThread()); | 202 ASSERT(!isMainThread()); |
| 203 m_bookmarkPosition = m_queueLeadPosition; | 203 m_bookmarkPosition = m_queueLeadPosition; |
| 204 return m_bookmarkPosition != 0; // Don't mess with BOM. | 204 return m_bookmarkPosition != 0; // Don't mess with BOM. |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Called by V8 on background thread. | 207 // Called by V8 on background thread. |
| 208 virtual void ResetToBookmark() override | 208 void ResetToBookmark() override |
| 209 { | 209 { |
| 210 ASSERT(!isMainThread()); | 210 ASSERT(!isMainThread()); |
| 211 { | 211 { |
| 212 MutexLocker locker(m_mutex); | 212 MutexLocker locker(m_mutex); |
| 213 m_queueLeadPosition = m_bookmarkPosition; | 213 m_queueLeadPosition = m_bookmarkPosition; |
| 214 m_queueTailPosition = m_bookmarkPosition; | 214 m_queueTailPosition = m_bookmarkPosition; |
| 215 m_dataQueue.clear(); | 215 m_dataQueue.clear(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Inform main thread to re-queue the data. | 218 // Inform main thread to re-queue the data. |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 642 |
| 643 // The Resource might go out of scope if the script is no longer | 643 // The Resource might go out of scope if the script is no longer |
| 644 // needed. This makes PendingScript notify the ScriptStreamer when it is | 644 // needed. This makes PendingScript notify the ScriptStreamer when it is |
| 645 // destroyed. | 645 // destroyed. |
| 646 script.setStreamer(ScriptStreamer::create(resource, scriptType, scriptState,
compileOption)); | 646 script.setStreamer(ScriptStreamer::create(resource, scriptType, scriptState,
compileOption)); |
| 647 | 647 |
| 648 return true; | 648 return true; |
| 649 } | 649 } |
| 650 | 650 |
| 651 } // namespace blink | 651 } // namespace blink |
| OLD | NEW |