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