Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: components/network_hints/renderer/dns_prefetch_queue.h

Issue 1918083002: Convert //components/[f-n]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: … Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
28
29 #include <stddef.h> 27 #include <stddef.h>
30 #include <stdint.h> 28 #include <stdint.h>
31 29
30 #include <memory>
31 #include <string>
32
32 #include "base/macros.h" 33 #include "base/macros.h"
33 #include "base/memory/scoped_ptr.h"
34 34
35 namespace network_hints { 35 namespace network_hints {
36 36
37 // 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
38 // component. 38 // component.
39 class DnsQueue { 39 class DnsQueue {
40 public: 40 public:
41 // BufferSize is a signed type used for indexing into a buffer. 41 // BufferSize is a signed type used for indexing into a buffer.
42 typedef int32_t BufferSize; 42 typedef int32_t BufferSize;
43 43
(...skipping 26 matching lines...) Expand all
70 return Push(source.c_str(), source.length()); 70 return Push(source.c_str(), source.length());
71 } 71 }
72 72
73 // Extract the next available string from the buffer. 73 // Extract the next available string from the buffer.
74 // If the buffer is empty, then return false. 74 // If the buffer is empty, then return false.
75 bool Pop(std::string* out_string); 75 bool Pop(std::string* out_string);
76 76
77 private: 77 private:
78 bool Validate(); // Checks that all internal data is valid. 78 bool Validate(); // Checks that all internal data is valid.
79 79
80 const scoped_ptr<char[]> buffer_; // Circular buffer, plus extra char ('\0'). 80 // Circular buffer, plus extra char ('\0').
81 const std::unique_ptr<char[]> buffer_;
81 const BufferSize buffer_size_; // Size one smaller than allocated space. 82 const BufferSize buffer_size_; // Size one smaller than allocated space.
82 const BufferSize buffer_sentinel_; // Index of extra '\0' at end of buffer_. 83 const BufferSize buffer_sentinel_; // Index of extra '\0' at end of buffer_.
83 84
84 // If writable_ == readable_, then the buffer is empty. 85 // If writable_ == readable_, then the buffer is empty.
85 BufferSize readable_; // Next readable char in buffer_. 86 BufferSize readable_; // Next readable char in buffer_.
86 BufferSize writeable_; // The next space in buffer_ to push. 87 BufferSize writeable_; // The next space in buffer_ to push.
87 88
88 // Number of queued strings 89 // Number of queued strings
89 size_t size_; 90 size_t size_;
90 91
91 DISALLOW_COPY_AND_ASSIGN(DnsQueue); 92 DISALLOW_COPY_AND_ASSIGN(DnsQueue);
92 }; // class DnsQueue 93 }; // class DnsQueue
93 94
94 } // namespace network_hints 95 } // namespace network_hints
95 96
96 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ 97 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__
OLDNEW
« no previous file with comments | « components/net_log/net_log_temp_file_unittest.cc ('k') | components/network_time/network_time_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698