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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 SharedBuffer* buffer = streamer->resource()->resourceBuffer(); | 281 SharedBuffer* buffer = streamer->resource()->resourceBuffer(); |
282 m_resourceBuffer = RefPtr<SharedBuffer>(buffer); | 282 m_resourceBuffer = RefPtr<SharedBuffer>(buffer); |
283 } | 283 } |
284 | 284 |
285 fetchDataFromResourceBuffer(lengthOfBOM); | 285 fetchDataFromResourceBuffer(lengthOfBOM); |
286 } | 286 } |
287 | 287 |
288 void fetchDataFromResourceBuffer(size_t lengthOfBOM) | 288 void fetchDataFromResourceBuffer(size_t lengthOfBOM) |
289 { | 289 { |
290 ASSERT(isMainThread()); | 290 ASSERT(isMainThread()); |
| 291 MutexLocker locker(m_mutex); // For m_cancelled + m_queueTailPosition. |
291 | 292 |
292 // Get as much data from the ResourceBuffer as we can. | 293 // Get as much data from the ResourceBuffer as we can. |
293 const char* data = 0; | 294 const char* data = 0; |
294 Vector<const char*> chunks; | 295 Vector<const char*> chunks; |
295 Vector<unsigned> chunkLengths; | 296 Vector<unsigned> chunkLengths; |
296 size_t dataLength = 0; | 297 size_t dataLength = 0; |
297 | 298 |
298 { | 299 if (!m_cancelled) { |
299 MutexLocker locker(m_mutex); // For m_cancelled + m_queueTailPositio
n. | 300 while (unsigned length = m_resourceBuffer->getSomeData(data, m_queue
TailPosition)) { |
300 if (!m_cancelled) { | 301 // FIXME: Here we can limit based on the total length, if it tur
ns |
301 while (unsigned length = m_resourceBuffer->getSomeData(data, m_q
ueueTailPosition)) { | 302 // out that we don't want to give all the data we have (memory |
302 // FIXME: Here we can limit based on the total length, if it
turns | 303 // vs. speed). |
303 // out that we don't want to give all the data we have (memo
ry | 304 chunks.append(data); |
304 // vs. speed). | 305 chunkLengths.append(length); |
305 chunks.append(data); | 306 dataLength += length; |
306 chunkLengths.append(length); | 307 m_queueTailPosition += length; |
307 dataLength += length; | |
308 m_queueTailPosition += length; | |
309 } | |
310 } | 308 } |
311 } | 309 } |
312 | 310 |
313 // Copy the data chunks into a new buffer, since we're going to give the | 311 // Copy the data chunks into a new buffer, since we're going to give the |
314 // data to a background thread. | 312 // data to a background thread. |
315 if (dataLength > lengthOfBOM) { | 313 if (dataLength > lengthOfBOM) { |
316 dataLength -= lengthOfBOM; | 314 dataLength -= lengthOfBOM; |
317 uint8_t* copiedData = new uint8_t[dataLength]; | 315 uint8_t* copiedData = new uint8_t[dataLength]; |
318 unsigned offset = 0; | 316 unsigned offset = 0; |
319 for (size_t i = 0; i < chunks.size(); ++i) { | 317 for (size_t i = 0; i < chunks.size(); ++i) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 640 |
643 // The Resource might go out of scope if the script is no longer | 641 // The Resource might go out of scope if the script is no longer |
644 // needed. This makes PendingScript notify the ScriptStreamer when it is | 642 // needed. This makes PendingScript notify the ScriptStreamer when it is |
645 // destroyed. | 643 // destroyed. |
646 script.setStreamer(ScriptStreamer::create(resource, scriptType, scriptState,
compileOption)); | 644 script.setStreamer(ScriptStreamer::create(resource, scriptType, scriptState,
compileOption)); |
647 | 645 |
648 return true; | 646 return true; |
649 } | 647 } |
650 | 648 |
651 } // namespace blink | 649 } // namespace blink |
OLD | NEW |