| 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/OwnPtr.h" | |
| 11 #include "wtf/PassOwnPtr.h" | |
| 12 #include "wtf/ThreadingPrimitives.h" | |
| 13 #include "wtf/Vector.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 // ParsedChunkQueue is used to transfer parsed HTML token chunks | |
| 18 // from BackgroundHTMLParser thread to Blink main thread without | |
| 19 // spamming task queue. | |
| 20 // ParsedChunkQueue is accessed from both BackgroundHTMLParser | |
| 21 // thread (producer) and Blink main thread (consumer). | |
| 22 // Access to the backend queue vector is protected by a mutex. | |
| 23 // If enqueue is done against empty queue, BackgroundHTMLParser | |
| 24 // thread kicks a consumer task on Blink main thread. | |
| 25 class ParsedChunkQueue { | |
| 26 public: | |
| 27 static PassOwnPtr<ParsedChunkQueue> create() | |
| 28 { | |
| 29 return adoptPtr(new ParsedChunkQueue); | |
| 30 } | |
| 31 | |
| 32 bool enqueue(PassOwnPtr<HTMLDocumentParser::ParsedChunk>); | |
| 33 void clear(); | |
| 34 | |
| 35 void takeAll(Vector<OwnPtr<HTMLDocumentParser::ParsedChunk>>&); | |
| 36 | |
| 37 private: | |
| 38 ParsedChunkQueue(); | |
| 39 | |
| 40 Mutex m_mutex; | |
| 41 Vector<OwnPtr<HTMLDocumentParser::ParsedChunk>> m_pendingChunks; | |
| 42 }; | |
| 43 | |
| 44 } // namespace blink | |
| 45 | |
| 46 #endif | |
| OLD | NEW |