Skip to content

Commit

Permalink
Replace std::deque and std::queue in //net
Browse files Browse the repository at this point in the history
Replace uses of std::deque with base::circular_deque, and std::queue
with base::queue. Uses in shared QUIC code are unchanged. We are
standardizing on the base implementations to avoid the memory
issues and widely varied implementations of the STL deque. Once most
uses have been replaced, we will add a presubmit check to disallow the
std:: variants.

Three instances of deque were left where circular_deque is not
appropriate (they required pointer stability across resizes).

An implementation of EstimateMemoryUsage is provided for circular_deque
which net required.

BufferedSlice (quic_stream_send_buffer.h) was converted to be move-only
(from being neither movable nor copyable) to support its membership in
a circular_deque.

When a typedef needed required changing, the typedef (and any adjacent
one) was converted to "using" statements.

The WebSocketChannel::PendingReceivedFrame declaration was moved to
the .cc file since the limitations around its declaration in the
header no longer exist (as explained in the removed comment).

One include had to be added to a file in Chrome that was depending on
net to being in <deque>.

Bug: 757232
Change-Id: I8c265044ec2815deae457b299f30bf08938d0b87
Reviewed-on: https://chromium-review.googlesource.com/659317
Commit-Queue: Brett Wilson <brettw@chromium.org>
Reviewed-by: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501105}
  • Loading branch information
Brett Wilson authored and Commit Bot committed Sep 12, 2017
1 parent 54a27d8 commit c6a0c82
Show file tree
Hide file tree
Showing 51 changed files with 160 additions and 164 deletions.
12 changes: 12 additions & 0 deletions base/trace_event/memory_usage_estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#include <vector>

#include "base/base_export.h"
#include "base/containers/circular_deque.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/containers/linked_list.h"
#include "base/containers/queue.h"
#include "base/strings/string16.h"

// Composable memory usage estimators.
Expand Down Expand Up @@ -152,6 +154,9 @@ size_t EstimateMemoryUsage(const std::priority_queue<T, C>& queue);
template <class T, class C>
size_t EstimateMemoryUsage(const std::stack<T, C>& stack);

template <class T>
size_t EstimateMemoryUsage(const base::circular_deque<T>& deque);

template <class T, class C>
size_t EstimateMemoryUsage(const base::flat_set<T, C>& set);

Expand Down Expand Up @@ -550,6 +555,13 @@ size_t EstimateMemoryUsage(const std::stack<T, C>& stack) {
return EstimateMemoryUsage(internal::GetUnderlyingContainer(stack));
}

// base::circular_deque

template <class T>
size_t EstimateMemoryUsage(const base::circular_deque<T>& deque) {
return sizeof(T) * deque.capacity() + EstimateIterableMemoryUsage(deque);
}

// Flat containers

template <class T, class C>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <queue>

#import "chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.h"

CookiesTreeControllerBridge::CookiesTreeControllerBridge(
Expand Down
7 changes: 4 additions & 3 deletions net/cookies/cookie_monster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2001,14 +2001,15 @@ void CookieMonster::DoCookieCallbackForURL(base::OnceClosure callback,
// Checks if the domain key has been loaded.
std::string key(cookie_util::GetEffectiveDomain(url.scheme(), url.host()));
if (keys_loaded_.find(key) == keys_loaded_.end()) {
std::map<std::string, std::deque<base::OnceClosure>>::iterator it =
tasks_pending_for_key_.find(key);
std::map<std::string, base::circular_deque<base::OnceClosure>>::iterator
it = tasks_pending_for_key_.find(key);
if (it == tasks_pending_for_key_.end()) {
store_->LoadCookiesForKey(
key, base::Bind(&CookieMonster::OnKeyLoaded,
weak_ptr_factory_.GetWeakPtr(), key));
it = tasks_pending_for_key_
.insert(std::make_pair(key, std::deque<base::OnceClosure>()))
.insert(std::make_pair(
key, base::circular_deque<base::OnceClosure>()))
.first;
}
it->second.push_back(std::move(callback));
Expand Down
8 changes: 4 additions & 4 deletions net/cookies/cookie_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#include <stddef.h>
#include <stdint.h>

#include <deque>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/callback_forward.h"
#include "base/containers/circular_deque.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -685,11 +684,12 @@ class NET_EXPORT CookieMonster : public CookieStore {
// Map of domain keys to their associated task queues. These tasks are blocked
// until all cookies for the associated domain key eTLD+1 are loaded from the
// backend store.
std::map<std::string, std::deque<base::OnceClosure>> tasks_pending_for_key_;
std::map<std::string, base::circular_deque<base::OnceClosure>>
tasks_pending_for_key_;

// Queues tasks that are blocked until all cookies are loaded from the backend
// store.
std::deque<base::OnceClosure> tasks_pending_;
base::circular_deque<base::OnceClosure> tasks_pending_;

// Once a global cookie task has been seen, all per-key tasks must be put in
// |tasks_pending_| instead of |tasks_pending_for_key_| to ensure a reasonable
Expand Down
3 changes: 2 additions & 1 deletion net/cookies/cookie_monster_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "base/bind.h"
#include "base/containers/queue.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -1015,7 +1016,7 @@ class DeferredCookieTaskTest : public CookieMonsterTest {
CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_;
// Stores the callback passed from the CookieMonster to the
// PersistentCookieStore::LoadCookiesForKey
std::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
base::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
loaded_for_key_callbacks_;
// base::RunLoop used to wait for PersistentCookieStore::Load to be called.
base::RunLoop load_run_loop_;
Expand Down
4 changes: 2 additions & 2 deletions net/disk_cache/simple/simple_entry_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <stdint.h>

#include <memory>
#include <queue>
#include <string>

#include "base/containers/queue.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
Expand Down Expand Up @@ -389,7 +389,7 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
// would leak the SimpleSynchronousEntry.
SimpleSynchronousEntry* synchronous_entry_;

std::queue<SimpleEntryOperation> pending_operations_;
base::queue<SimpleEntryOperation> pending_operations_;

net::NetLogWithSource net_log_;

Expand Down
4 changes: 2 additions & 2 deletions net/dns/dns_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include "net/dns/dns_transaction.h"

#include <deque>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/big_endian.h"
#include "base/bind.h"
#include "base/containers/circular_deque.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
Expand Down Expand Up @@ -950,7 +950,7 @@ class DnsTransactionImpl : public DnsTransaction,
NetLogWithSource net_log_;

// Search list of fully-qualified DNS names to query next (in DNS format).
std::deque<std::string> qnames_;
base::circular_deque<std::string> qnames_;
size_t qnames_initial_size_;

// List of attempts for the current name.
Expand Down
3 changes: 2 additions & 1 deletion net/dns/dns_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <utility>

#include "base/bind.h"
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
Expand Down Expand Up @@ -476,7 +477,7 @@ class DnsTransactionTest : public testing::Test {

std::vector<std::unique_ptr<DnsSocketData>> socket_data_;

std::deque<int> transaction_ids_;
base::circular_deque<int> transaction_ids_;
std::unique_ptr<TestSocketFactory> socket_factory_;
scoped_refptr<DnsSession> session_;
std::unique_ptr<DnsTransactionFactory> transaction_factory_;
Expand Down
3 changes: 2 additions & 1 deletion net/dns/host_resolver_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/compiler_specific.h"
#include "base/containers/circular_deque.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
#include "base/macros.h"
Expand Down Expand Up @@ -1885,7 +1886,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
std::unique_ptr<DnsTask> dns_task_;

// All Requests waiting for the result of this Job. Some can be canceled.
std::deque<RequestImpl*> requests_;
base::circular_deque<RequestImpl*> requests_;

// A handle used in |HostResolverImpl::dispatcher_|.
PrioritizedDispatcher::Handle handle_;
Expand Down
1 change: 0 additions & 1 deletion net/dns/mdns_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "net/dns/mdns_client_impl.h"

#include <algorithm>
#include <queue>
#include <utility>

#include "base/bind.h"
Expand Down
4 changes: 2 additions & 2 deletions net/dns/mdns_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

#include <map>
#include <memory>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#include "base/cancelable_callback.h"
#include "base/containers/queue.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/observer_list.h"
Expand Down Expand Up @@ -88,7 +88,7 @@ class NET_EXPORT_PRIVATE MDnsConnection {
DnsResponse response_;
IPEndPoint multicast_addr_;
bool send_in_progress_;
std::queue<std::pair<scoped_refptr<IOBuffer>, unsigned> > send_queue_;
base::queue<std::pair<scoped_refptr<IOBuffer>, unsigned>> send_queue_;

DISALLOW_COPY_AND_ASSIGN(SocketHandler);
};
Expand Down
1 change: 0 additions & 1 deletion net/dns/mdns_client_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

#include <memory>
#include <queue>
#include <vector>

#include "base/location.h"
Expand Down
4 changes: 2 additions & 2 deletions net/filter/mock_source_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef NET_FILTER_MOCK_SOURCE_STREAM_H_
#define NET_FILTER_MOCK_SOURCE_STREAM_H_

#include <queue>
#include <string>

#include "base/containers/queue.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "net/base/completion_callback.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ class MockSourceStream : public SourceStream {
};

bool read_one_byte_at_a_time_;
std::queue<QueuedResult> results_;
base::queue<QueuedResult> results_;
bool awaiting_completion_;
scoped_refptr<IOBuffer> dest_buffer_;
CompletionCallback callback_;
Expand Down
6 changes: 3 additions & 3 deletions net/ftp/ftp_ctrl_response_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_
#define NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_

#include <queue>
#include <string>
#include <vector>

#include "base/containers/queue.h"
#include "base/macros.h"
#include "net/base/net_export.h"
#include "net/log/net_log_with_source.h"
Expand Down Expand Up @@ -76,7 +76,7 @@ class NET_EXPORT_PRIVATE FtpCtrlResponseBuffer {
// We keep not-yet-parsed data in a string buffer.
std::string buffer_;

std::queue<ParsedLine> lines_;
base::queue<ParsedLine> lines_;

// True if we are in the middle of parsing a multi-line response.
bool multiline_;
Expand All @@ -90,7 +90,7 @@ class NET_EXPORT_PRIVATE FtpCtrlResponseBuffer {
FtpCtrlResponse response_buf_;

// As we read full responses (possibly multiline), we add them to the queue.
std::queue<FtpCtrlResponse> responses_;
base::queue<FtpCtrlResponse> responses_;

NetLogWithSource net_log_;

Expand Down
5 changes: 2 additions & 3 deletions net/ftp/ftp_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include "net/ftp/ftp_network_transaction.h"

#include <deque>

#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -217,7 +216,7 @@ class FtpSocketDataProvider : public SocketDataProvider {

private:
// List of reads to be consumed.
std::deque<MockRead> reads_;
base::circular_deque<MockRead> reads_;

// Max number of bytes we will read at a time. 0 means no limit.
int short_read_limit_;
Expand Down
1 change: 0 additions & 1 deletion net/http/http_server_properties_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stddef.h>
#include <stdint.h>

#include <deque>
#include <map>
#include <set>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions net/http2/hpack/decoder/hpack_decoder_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include <stddef.h>

#include <deque>
#include <vector>

#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "net/http2/hpack/hpack_string.h"
#include "net/http2/http2_constants.h"
Expand Down Expand Up @@ -128,7 +128,7 @@ class HTTP2_EXPORT_PRIVATE HpackDecoderDynamicTable {
// Removes the oldest dynamic table entry.
void RemoveLastEntry();

std::deque<HpackDecoderTableEntry> table_;
base::circular_deque<HpackDecoderTableEntry> table_;

// The last received DynamicTableSizeUpdate value, initialized to
// SETTINGS_HEADER_TABLE_SIZE.
Expand Down
4 changes: 2 additions & 2 deletions net/log/file_net_log_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include <algorithm>
#include <memory>
#include <queue>
#include <string>
#include <utility>

#include "base/bind.h"
#include "base/containers/queue.h"
#include "base/files/file_util.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
Expand Down Expand Up @@ -100,7 +100,7 @@ void AppendToFileThenDelete(const base::FilePath& source_path,
namespace net {

// Used to store events to be written to file.
using EventQueue = std::queue<std::unique_ptr<std::string>>;
using EventQueue = base::queue<std::unique_ptr<std::string>>;

// WriteQueue receives events from FileNetLogObserver on the main thread and
// holds them in a queue until they are drained from the queue and written to
Expand Down
4 changes: 2 additions & 2 deletions net/nqe/observation_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include <stdint.h>

#include <deque>
#include <map>
#include <memory>
#include <set>
#include <vector>

#include "base/containers/circular_deque.h"
#include "base/optional.h"
#include "base/time/tick_clock.h"
#include "net/base/net_export.h"
Expand Down Expand Up @@ -115,7 +115,7 @@ class NET_EXPORT_PRIVATE ObservationBuffer {

// Holds observations sorted by time, with the oldest observation at the
// front of the queue.
std::deque<Observation> observations_;
base::circular_deque<Observation> observations_;

// The factor by which the weight of an observation reduces every second.
// For example, if an observation is 6 seconds old, its weight would be:
Expand Down
4 changes: 2 additions & 2 deletions net/nqe/throughput_analyzer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdint.h>

#include <deque>
#include <map>
#include <memory>
#include <string>
Expand All @@ -15,6 +14,7 @@

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/containers/circular_deque.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
Expand Down Expand Up @@ -109,7 +109,7 @@ TEST(ThroughputAnalyzerTest, MaximumRequests) {
throughput_analyzer.AddIPAddressResolution(&context);

ASSERT_FALSE(throughput_analyzer.disable_throughput_measurements());
std::deque<std::unique_ptr<URLRequest>> requests;
base::circular_deque<std::unique_ptr<URLRequest>> requests;

// Start more requests than the maximum number of requests that can be held
// in the memory.
Expand Down
Loading

0 comments on commit c6a0c82

Please sign in to comment.