OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // DnsQueue is implemented as an almost FIFO circular buffer for text | 5 // DnsQueue is implemented as an almost FIFO circular buffer for text |
6 // strings that don't have embedded nulls ('\0'). The "almost" element is that | 6 // strings that don't have embedded nulls ('\0'). The "almost" element is that |
7 // some duplicate strings may be removed (i.e., the string won't really be | 7 // some duplicate strings may be removed (i.e., the string won't really be |
8 // pushed *if* the class happens to notice that a duplicate is already in the | 8 // pushed *if* the class happens to notice that a duplicate is already in the |
9 // queue). | 9 // queue). |
10 // The buffers internal format is null terminated character strings | 10 // The buffers internal format is null terminated character strings |
11 // (a.k.a., c_strings). | 11 // (a.k.a., c_strings). |
12 // It is written to be as fast as possible during push() operations, so | 12 // It is written to be as fast as possible during push() operations, so |
13 // that there will be minimal performance impact on a supplier thread. | 13 // that there will be minimal performance impact on a supplier thread. |
14 // The push() operation will not block, and no memory allocation is involved | 14 // The push() operation will not block, and no memory allocation is involved |
15 // (internally) during the push operations. | 15 // (internally) during the push operations. |
16 // The one caveat is that if there is insufficient space in the buffer to | 16 // The one caveat is that if there is insufficient space in the buffer to |
17 // accept additional string via a push(), then the push() will fail, and | 17 // accept additional string via a push(), then the push() will fail, and |
18 // the buffer will be unmodified. | 18 // the buffer will be unmodified. |
19 | 19 |
20 // This class was designed for use in DNS prefetch operations. During | 20 // This class was designed for use in DNS prefetch operations. During |
21 // rendering, the supplier is the renderer (typically), and the consumer | 21 // rendering, the supplier is the renderer (typically), and the consumer |
22 // is a thread that sends messages to an async DNS resolver. | 22 // is a thread that sends messages to an async DNS resolver. |
23 | 23 |
24 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ | 24 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ |
25 #define COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ | 25 #define COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ |
26 | 26 |
27 #include <string> | 27 #include <string> |
28 | 28 |
29 #include "base/basictypes.h" | 29 #include <stddef.h> |
| 30 #include <stdint.h> |
| 31 |
| 32 #include "base/macros.h" |
30 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" |
31 | 34 |
32 namespace network_hints { | 35 namespace network_hints { |
33 | 36 |
34 // A queue of DNS lookup requests for internal use within the network_hints | 37 // A queue of DNS lookup requests for internal use within the network_hints |
35 // component. | 38 // component. |
36 class DnsQueue { | 39 class DnsQueue { |
37 public: | 40 public: |
38 // BufferSize is a signed type used for indexing into a buffer. | 41 // BufferSize is a signed type used for indexing into a buffer. |
39 typedef int32 BufferSize; | 42 typedef int32_t BufferSize; |
40 | 43 |
41 enum PushResult { SUCCESSFUL_PUSH, OVERFLOW_PUSH, REDUNDANT_PUSH }; | 44 enum PushResult { SUCCESSFUL_PUSH, OVERFLOW_PUSH, REDUNDANT_PUSH }; |
42 | 45 |
43 // The size specified in the constructor creates a buffer large enough | 46 // The size specified in the constructor creates a buffer large enough |
44 // to hold at most one string of that length, or "many" | 47 // to hold at most one string of that length, or "many" |
45 // strings of considerably shorter length. Note that strings | 48 // strings of considerably shorter length. Note that strings |
46 // are padded internally with a terminal '\0" while stored, | 49 // are padded internally with a terminal '\0" while stored, |
47 // so if you are trying to be precise and get N strings of | 50 // so if you are trying to be precise and get N strings of |
48 // length K to fit, you should actually construct a buffer with | 51 // length K to fit, you should actually construct a buffer with |
49 // an internal size of N*(K+1). | 52 // an internal size of N*(K+1). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 87 |
85 // Number of queued strings | 88 // Number of queued strings |
86 size_t size_; | 89 size_t size_; |
87 | 90 |
88 DISALLOW_COPY_AND_ASSIGN(DnsQueue); | 91 DISALLOW_COPY_AND_ASSIGN(DnsQueue); |
89 }; // class DnsQueue | 92 }; // class DnsQueue |
90 | 93 |
91 } // namespace network_hints | 94 } // namespace network_hints |
92 | 95 |
93 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ | 96 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ |
OLD | NEW |