| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ParsedChunkQueue_h | |
| 6 #define ParsedChunkQueue_h | |
| 7 | |
| 8 #include "core/html/parser/HTMLDocumentParser.h" | |
| 9 #include "wtf/Deque.h" | |
| 10 #include "wtf/PassRefPtr.h" | |
| 11 #include "wtf/ThreadSafeRefCounted.h" | |
| 12 #include "wtf/ThreadingPrimitives.h" | |
| 13 #include "wtf/Vector.h" | |
| 14 #include <memory> | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 // ParsedChunkQueue is used to transfer parsed HTML token chunks | |
| 19 // from BackgroundHTMLParser thread to Blink main thread without | |
| 20 // spamming task queue. | |
| 21 // ParsedChunkQueue is accessed from both BackgroundHTMLParser | |
| 22 // thread (producer) and Blink main thread (consumer). | |
| 23 // Access to the backend queue vector is protected by a mutex. | |
| 24 // If enqueue is done against empty queue, BackgroundHTMLParser | |
| 25 // thread kicks a consumer task on Blink main thread. | |
| 26 class ParsedChunkQueue : public ThreadSafeRefCounted<ParsedChunkQueue> { | |
| 27 public: | |
| 28 static PassRefPtr<ParsedChunkQueue> create() | |
| 29 { | |
| 30 return adoptRef(new ParsedChunkQueue); | |
| 31 } | |
| 32 | |
| 33 ~ParsedChunkQueue(); | |
| 34 | |
| 35 bool enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk>); | |
| 36 void clear(); | |
| 37 | |
| 38 void takeAll(Vector<std::unique_ptr<HTMLDocumentParser::ParsedChunk>>&); | |
| 39 size_t peakPendingChunkCount(); | |
| 40 size_t peakPendingTokenCount(); | |
| 41 | |
| 42 private: | |
| 43 ParsedChunkQueue(); | |
| 44 | |
| 45 std::unique_ptr<Mutex> m_mutex; | |
| 46 Vector<std::unique_ptr<HTMLDocumentParser::ParsedChunk>> m_pendingChunks; | |
| 47 size_t m_peakPendingChunkCount = 0; | |
| 48 size_t m_peakPendingTokenCount = 0; | |
| 49 size_t m_pendingTokenCount = 0; | |
| 50 }; | |
| 51 | |
| 52 } // namespace blink | |
| 53 | |
| 54 #endif | |
| OLD | NEW |