[go: nahoru, domu]

[/net] default member initializers

This change was partially automated with the following command:

<PATH_TO_LLVM_SRC>/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py \
    -p . \
    -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \
    -clang-apply-replacements-binary \
        <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \
    -checks='-*,modernize-use-default-member-init' \
    -header-filter='.*' \
    -fix 'net/*.cc' 'net/*.h'

See docs/clang_tidy.md for more details about run-clang-tidy.py.

This command modifies files outside net/ directory, so these are
manually reverted and some whitespace and some errors are manually
corrected after running clang-tidy.

This should cause no functional changes

Change-Id: I9ef778f3fbc4d95e3ea3d4e05d14297208fe4672
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3689324
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1011323}
diff --git a/net/base/priority_queue.h b/net/base/priority_queue.h
index b634a58..73cb6d7 100644
--- a/net/base/priority_queue.h
+++ b/net/base/priority_queue.h
@@ -132,8 +132,7 @@
   };
 
   // Creates a new queue for |num_priorities|.
-  explicit PriorityQueue(Priority num_priorities)
-      : lists_(num_priorities), size_(0) {
+  explicit PriorityQueue(Priority num_priorities) : lists_(num_priorities) {
 #if !defined(NDEBUG)
     next_id_ = 0;
 #endif
@@ -373,7 +372,7 @@
 #endif
 
   ListVector lists_;
-  size_t size_;
+  size_t size_ = 0;
 
   THREAD_CHECKER(thread_checker_);
 };
diff --git a/net/http/bidirectional_stream_request_info.cc b/net/http/bidirectional_stream_request_info.cc
index 18d9ba7b..2b8cabf 100644
--- a/net/http/bidirectional_stream_request_info.cc
+++ b/net/http/bidirectional_stream_request_info.cc
@@ -6,11 +6,7 @@
 
 namespace net {
 
-BidirectionalStreamRequestInfo::BidirectionalStreamRequestInfo()
-    : allow_early_data_override(false),
-      priority(LOW),
-      end_stream_on_headers(false),
-      detect_broken_connection(false) {}
+BidirectionalStreamRequestInfo::BidirectionalStreamRequestInfo() = default;
 
 BidirectionalStreamRequestInfo::~BidirectionalStreamRequestInfo() = default;
 
diff --git a/net/http/bidirectional_stream_request_info.h b/net/http/bidirectional_stream_request_info.h
index 2ed8a22..51c75ec 100644
--- a/net/http/bidirectional_stream_request_info.h
+++ b/net/http/bidirectional_stream_request_info.h
@@ -29,10 +29,10 @@
 
   // Whether to allow early data to be used with this request, overriding the
   // early data based on the |method| semantics.
-  bool allow_early_data_override;
+  bool allow_early_data_override = false;
 
   // Request priority.
-  RequestPriority priority;
+  RequestPriority priority = LOW;
 
   // Socket tag to apply to sockets used to process this request.
   SocketTag socket_tag;
@@ -41,11 +41,11 @@
   HttpRequestHeaders extra_headers;
 
   // Whether END_STREAM should be set on the request HEADER frame.
-  bool end_stream_on_headers;
+  bool end_stream_on_headers = false;
 
   // Whether the implementor of the BidirectionalStream should monitor
   // the status of the connection for the lifetime of this stream.
-  bool detect_broken_connection;
+  bool detect_broken_connection = false;
 
   // Suggests the period the broken connection detector should use to check
   // the status of the connection.
diff --git a/net/http/broken_alternative_services.cc b/net/http/broken_alternative_services.cc
index 9bde04d..8652775 100644
--- a/net/http/broken_alternative_services.cc
+++ b/net/http/broken_alternative_services.cc
@@ -82,8 +82,7 @@
       clock_(clock),
       recently_broken_alternative_services_(
           max_recently_broken_alternative_service_entries),
-      initial_delay_(kDefaultBrokenAlternativeProtocolDelay),
-      exponential_backoff_on_initial_delay_(true) {
+      initial_delay_(kDefaultBrokenAlternativeProtocolDelay) {
   DCHECK(delegate_);
   DCHECK(clock_);
 }
diff --git a/net/http/broken_alternative_services.h b/net/http/broken_alternative_services.h
index 56c8dfd..72a36cbd 100644
--- a/net/http/broken_alternative_services.h
+++ b/net/http/broken_alternative_services.h
@@ -229,7 +229,7 @@
   // initial_delay_for_broken_alternative_service * (1 << broken_count).
   // Otherwise, the delay would be initial_delay_for_broken_alternative_service,
   // 5min, 10min.. and so on.
-  bool exponential_backoff_on_initial_delay_;
+  bool exponential_backoff_on_initial_delay_ = true;
 
   base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_{this};
 };
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
index 5a6d8a7..790d31a 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -55,18 +55,7 @@
 };
 
 MockDiskEntry::MockDiskEntry(const std::string& key)
-    : key_(key),
-      in_memory_data_(0),
-      max_file_size_(std::numeric_limits<int>::max()),
-      doomed_(false),
-      sparse_(false),
-      fail_requests_(0),
-      fail_sparse_requests_(false),
-      busy_(false),
-      delayed_(false),
-      cancel_(false),
-      defer_op_(DEFER_NONE),
-      resume_return_code_(0) {
+    : key_(key), max_file_size_(std::numeric_limits<int>::max()) {
   test_mode_ = GetTestModeForEntry(key);
 }
 
@@ -393,19 +382,7 @@
 //-----------------------------------------------------------------------------
 
 MockDiskCache::MockDiskCache()
-    : Backend(DISK_CACHE),
-      open_count_(0),
-      create_count_(0),
-      doomed_count_(0),
-      max_file_size_(std::numeric_limits<int>::max()),
-      fail_requests_(false),
-      soft_failures_(0),
-      soft_failures_one_instance_(0),
-      double_create_check_(true),
-      fail_sparse_requests_(false),
-      support_in_memory_entry_data_(true),
-      force_fail_callback_later_(false),
-      defer_op_(MockDiskEntry::DEFER_NONE) {}
+    : Backend(DISK_CACHE), max_file_size_(std::numeric_limits<int>::max()) {}
 
 MockDiskCache::~MockDiskCache() {
   ReleaseAll();
@@ -844,8 +821,7 @@
 
 //-----------------------------------------------------------------------------
 
-MockBlockingBackendFactory::MockBlockingBackendFactory()
-    : backend_(nullptr), block_(true), fail_(false) {}
+MockBlockingBackendFactory::MockBlockingBackendFactory() = default;
 
 MockBlockingBackendFactory::~MockBlockingBackendFactory() = default;
 
diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h
index f0bef5b..9068a3d 100644
--- a/net/http/mock_http_cache.h
+++ b/net/http/mock_http_cache.h
@@ -137,21 +137,21 @@
 
   std::string key_;
   std::vector<char> data_[kNumCacheEntryDataIndices];
-  uint8_t in_memory_data_;
+  uint8_t in_memory_data_ = 0;
   int test_mode_;
   int max_file_size_;
-  bool doomed_;
-  bool sparse_;
-  int fail_requests_;
-  bool fail_sparse_requests_;
-  bool busy_;
-  bool delayed_;
-  bool cancel_;
+  bool doomed_ = false;
+  bool sparse_ = false;
+  int fail_requests_ = 0;
+  bool fail_sparse_requests_ = false;
+  bool busy_ = false;
+  bool delayed_ = false;
+  bool cancel_ = false;
 
   // Used for pause and restart.
-  DeferOp defer_op_;
+  DeferOp defer_op_ = DEFER_NONE;
   CompletionOnceCallback resume_callback_;
-  int resume_return_code_;
+  int resume_return_code_ = 0;
 
   static bool ignore_callbacks_;
 };
@@ -261,20 +261,20 @@
 
   EntryMap entries_;
   std::vector<std::string> external_cache_hits_;
-  int open_count_;
-  int create_count_;
-  int doomed_count_;
+  int open_count_ = 0;
+  int create_count_ = 0;
+  int doomed_count_ = 0;
   int max_file_size_;
-  bool fail_requests_;
-  int soft_failures_;
-  int soft_failures_one_instance_;
-  bool double_create_check_;
-  bool fail_sparse_requests_;
-  bool support_in_memory_entry_data_;
-  bool force_fail_callback_later_;
+  bool fail_requests_ = false;
+  int soft_failures_ = 0;
+  int soft_failures_one_instance_ = 0;
+  bool double_create_check_ = true;
+  bool fail_sparse_requests_ = false;
+  bool support_in_memory_entry_data_ = true;
+  bool force_fail_callback_later_ = false;
 
   // Used for pause and restart.
-  MockDiskEntry::DeferOp defer_op_;
+  MockDiskEntry::DeferOp defer_op_ = MockDiskEntry::DEFER_NONE;
   base::OnceClosure resume_callback_;
 };
 
@@ -385,10 +385,10 @@
  private:
   int Result() { return fail_ ? ERR_FAILED : OK; }
 
-  raw_ptr<std::unique_ptr<disk_cache::Backend>> backend_;
+  raw_ptr<std::unique_ptr<disk_cache::Backend>> backend_ = nullptr;
   CompletionOnceCallback callback_;
-  bool block_;
-  bool fail_;
+  bool block_ = true;
+  bool fail_ = false;
 };
 
 }  // namespace net
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 1c7a8c4..7c60c51 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -31,18 +31,7 @@
 
 }  // namespace
 
-PartialData::PartialData()
-    : current_range_start_(0),
-      current_range_end_(0),
-      cached_start_(0),
-      cached_min_len_(0),
-      resource_size_(0),
-      range_requested_(false),
-      range_present_(false),
-      final_range_(false),
-      sparse_entry_(true),
-      truncated_(false),
-      initial_validation_(false) {}
+PartialData::PartialData() = default;
 
 PartialData::~PartialData() = default;
 
diff --git a/net/http/partial_data.h b/net/http/partial_data.h
index 16510de5..4f6fe440 100644
--- a/net/http/partial_data.h
+++ b/net/http/partial_data.h
@@ -136,8 +136,8 @@
   void GetAvailableRangeCompleted(const disk_cache::RangeResult& result);
 
   // The portion we're trying to get, either from cache or network.
-  int64_t current_range_start_;
-  int64_t current_range_end_;
+  int64_t current_range_start_ = 0;
+  int64_t current_range_end_ = 0;
 
   // Next portion available in the cache --- this may be what's currently being
   // read, or the next thing that will be read if the current network portion
@@ -146,20 +146,20 @@
   // |cached_start_| represents the beginning of the range, while
   // |cached_min_len_| the data not yet read (possibly overestimated). It may
   // also have an error code latched into it.
-  int64_t cached_start_;
-  int cached_min_len_;
+  int64_t cached_start_ = 0;
+  int cached_min_len_ = 0;
 
   // The size of the whole file.
-  int64_t resource_size_;
+  int64_t resource_size_ = 0;
   HttpByteRange byte_range_;  // The range requested by the user.
   // The clean set of extra headers (no ranges).
   HttpRequestHeaders extra_headers_;
-  bool range_requested_;  // ###
-  bool range_present_;  // True if next range entry is already stored.
-  bool final_range_;
-  bool sparse_entry_;
-  bool truncated_;  // We have an incomplete 200 stored.
-  bool initial_validation_;  // Only used for truncated entries.
+  bool range_requested_ = false;  // ###
+  bool range_present_ = false;    // True if next range entry is already stored.
+  bool final_range_ = false;
+  bool sparse_entry_ = true;
+  bool truncated_ = false;           // We have an incomplete 200 stored.
+  bool initial_validation_ = false;  // Only used for truncated entries.
   CompletionOnceCallback callback_;
   base::WeakPtrFactory<PartialData> weak_factory_{this};
 };
diff --git a/net/http/transport_security_state.cc b/net/http/transport_security_state.cc
index f920d29..f5217b3 100644
--- a/net/http/transport_security_state.cc
+++ b/net/http/transport_security_state.cc
@@ -1388,9 +1388,7 @@
       hashed_host, network_isolation_key)] = state;
 }
 
-TransportSecurityState::STSState::STSState()
-    : upgrade_mode(MODE_DEFAULT), include_subdomains(false) {
-}
+TransportSecurityState::STSState::STSState() = default;
 
 TransportSecurityState::STSState::~STSState() = default;
 
@@ -1406,14 +1404,13 @@
 
 TransportSecurityState::STSStateIterator::~STSStateIterator() = default;
 
-TransportSecurityState::PKPState::PKPState() : include_subdomains(false) {
-}
+TransportSecurityState::PKPState::PKPState() = default;
 
 TransportSecurityState::PKPState::PKPState(const PKPState& other) = default;
 
 TransportSecurityState::PKPState::~PKPState() = default;
 
-TransportSecurityState::ExpectCTState::ExpectCTState() : enforce(false) {}
+TransportSecurityState::ExpectCTState::ExpectCTState() = default;
 
 TransportSecurityState::ExpectCTState::~ExpectCTState() = default;
 
diff --git a/net/http/transport_security_state.h b/net/http/transport_security_state.h
index 17e8bac..0e003911 100644
--- a/net/http/transport_security_state.h
+++ b/net/http/transport_security_state.h
@@ -125,10 +125,10 @@
     // expires.
     base::Time expiry;
 
-    UpgradeMode upgrade_mode;
+    UpgradeMode upgrade_mode = MODE_DEFAULT;
 
     // Are subdomains subject to this policy state?
-    bool include_subdomains;
+    bool include_subdomains = false;
 
     // The domain which matched during a search for this STSState entry.
     // Updated by |GetDynamicSTSState| and |GetStaticDomainState|.
@@ -191,7 +191,7 @@
     HashValueVector bad_spki_hashes;
 
     // Are subdomains subject to this policy state?
-    bool include_subdomains;
+    bool include_subdomains = false;
 
     // The domain which matched during a search for this DomainState entry.
     // Updated by |GetDynamicPKPState| and |GetStaticDomainState|.
@@ -239,7 +239,7 @@
     // True if connections should be closed if they do not comply with the CT
     // policy. If false, noncompliant connections will be allowed but reports
     // will be sent about the violation.
-    bool enforce;
+    bool enforce = false;
     // The absolute time (UTC) when the Expect-CT state was last observed.
     base::Time last_observed;
     // The absolute time (UTC) when the Expect-CT state expires.
diff --git a/net/http/transport_security_state_unittest.cc b/net/http/transport_security_state_unittest.cc
index 27a596c..72ea47e 100644
--- a/net/http/transport_security_state_unittest.cc
+++ b/net/http/transport_security_state_unittest.cc
@@ -164,7 +164,7 @@
 class MockFailingCertificateReportSender
     : public TransportSecurityState::ReportSenderInterface {
  public:
-  MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {}
+  MockFailingCertificateReportSender() = default;
   ~MockFailingCertificateReportSender() override = default;
 
   int net_error() { return net_error_; }
@@ -182,14 +182,14 @@
   }
 
  private:
-  const int net_error_;
+  const int net_error_ = ERR_CONNECTION_FAILED;
 };
 
 // A mock ExpectCTReporter that remembers the latest violation that was
 // reported and the number of violations reported.
 class MockExpectCTReporter : public TransportSecurityState::ExpectCTReporter {
  public:
-  MockExpectCTReporter() : num_failures_(0) {}
+  MockExpectCTReporter() = default;
   ~MockExpectCTReporter() override = default;
 
   void OnExpectCTFailed(
@@ -233,7 +233,7 @@
   HostPortPair host_port_pair_;
   GURL report_uri_;
   base::Time expiration_;
-  uint32_t num_failures_;
+  uint32_t num_failures_ = 0;
   raw_ptr<const X509Certificate> served_certificate_chain_;
   raw_ptr<const X509Certificate> validated_certificate_chain_;
   SignedCertificateTimestampAndStatusList signed_certificate_timestamps_;
diff --git a/net/proxy_resolution/proxy_list_unittest.cc b/net/proxy_resolution/proxy_list_unittest.cc
index c198469..2a0132e 100644
--- a/net/proxy_resolution/proxy_list_unittest.cc
+++ b/net/proxy_resolution/proxy_list_unittest.cc
@@ -173,7 +173,6 @@
 }
 
 TEST(ProxyListTest, UpdateRetryInfoOnFallback) {
-  ProxyRetryInfo proxy_retry_info;
   // Retrying should put the first proxy on the retry list.
   {
     ProxyList list;
diff --git a/net/proxy_resolution/proxy_retry_info.h b/net/proxy_resolution/proxy_retry_info.h
index 23d5d75..2f85527 100644
--- a/net/proxy_resolution/proxy_retry_info.h
+++ b/net/proxy_resolution/proxy_retry_info.h
@@ -13,7 +13,7 @@
 
 // Contains the information about when to retry a proxy server.
 struct ProxyRetryInfo {
-  ProxyRetryInfo() : try_while_bad(true), net_error(0) {}
+  ProxyRetryInfo() = default;
 
   // We should not retry until this time.
   base::TimeTicks bad_until;
@@ -23,12 +23,12 @@
   base::TimeDelta current_delay;
 
   // True if this proxy should be considered even if still bad.
-  bool try_while_bad;
+  bool try_while_bad = true;
 
   // The network error received when this proxy failed, or |OK| if the proxy
   // was added to the retry list for a non-network related reason. (e.g. local
   // policy).
-  int net_error;
+  int net_error = 0;
 };
 
 // Map of proxy servers with the associated RetryInfo structures.
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 68e0ea9..147b03a 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -610,7 +610,7 @@
 template <typename T>
 class SocketDataProviderArray {
  public:
-  SocketDataProviderArray() : next_index_(0) {}
+  SocketDataProviderArray() = default;
 
   T* GetNext() {
     DCHECK_LT(next_index_, data_providers_.size());
@@ -639,7 +639,7 @@
  private:
   // Index of the next |data_providers_| element to use. Not an iterator
   // because those are invalidated on vector reallocation.
-  size_t next_index_;
+  size_t next_index_ = 0;
 
   // SocketDataProviders to be returned.
   std::vector<T*> data_providers_;