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