Use lambdas instead of base::BindRepeating() for materializing NetLog parameters.
This improves code size, performance, and readability.
For example a caller that was previously:
net_log_.BeginEvent(CERT_VERIFIER_JOB,
base::BindRepeating(&NetLogX509CertificateParams,
base::Unretained(certificate)));
Now becomes:
net_log_.BeginEvent(CERT_VERIFIER_JOB, [&] {
return NetLogX509CertificateParams(certificate);
});
The parameter callback can alternately take a NetLogCapture mode for cases where the parameters depends on the logging level.
Bug: 472687
TBR: [email protected]
Change-Id: I44267035ffab2b786ae638055c6de700c18e71d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1592493
Commit-Queue: Eric Roman <[email protected]>
Reviewed-by: David Benjamin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#677203}
diff --git a/net/log/net_log_entry.cc b/net/log/net_log_entry.cc
index 16be908..bc0e582 100644
--- a/net/log/net_log_entry.cc
+++ b/net/log/net_log_entry.cc
@@ -4,61 +4,43 @@
#include "net/log/net_log_entry.h"
-#include <utility>
-
-#include "base/callback.h"
-#include "base/values.h"
#include "net/log/net_log.h"
namespace net {
-base::Value NetLogEntry::ToValue() const {
- base::DictionaryValue entry_dict;
-
- entry_dict.SetString("time", NetLog::TickCountToString(data_->time));
-
- // Set the entry source.
- base::DictionaryValue source_dict;
- source_dict.SetInteger("id", data_->source.id);
- source_dict.SetInteger("type", static_cast<int>(data_->source.type));
- entry_dict.SetKey("source", std::move(source_dict));
-
- // Set the event info.
- entry_dict.SetInteger("type", static_cast<int>(data_->type));
- entry_dict.SetInteger("phase", static_cast<int>(data_->phase));
-
- // Set the event-specific parameters.
- base::Value params = ParametersToValue();
- if (!params.is_none())
- entry_dict.SetKey("params", std::move(params));
-
- return std::move(entry_dict);
-}
-
-base::Value NetLogEntry::ParametersToValue() const {
- if (data_->parameters_callback)
- return data_->parameters_callback->Run(capture_mode_);
- return base::Value();
-}
-
-NetLogEntryData::NetLogEntryData(
- NetLogEventType type,
- NetLogSource source,
- NetLogEventPhase phase,
- base::TimeTicks time,
- const NetLogParametersCallback* parameters_callback)
+NetLogEntry::NetLogEntry(NetLogEventType type,
+ NetLogSource source,
+ NetLogEventPhase phase,
+ base::TimeTicks time,
+ base::Value params)
: type(type),
source(source),
phase(phase),
time(time),
- parameters_callback(parameters_callback) {}
-
-NetLogEntryData::~NetLogEntryData() = default;
-
-NetLogEntry::NetLogEntry(const NetLogEntryData* data,
- NetLogCaptureMode capture_mode)
- : data_(data), capture_mode_(capture_mode) {}
+ params(std::move(params)) {}
NetLogEntry::~NetLogEntry() = default;
+base::Value NetLogEntry::ToValue() const {
+ base::DictionaryValue entry_dict;
+
+ entry_dict.SetString("time", NetLog::TickCountToString(time));
+
+ // Set the entry source.
+ base::DictionaryValue source_dict;
+ source_dict.SetInteger("id", source.id);
+ source_dict.SetInteger("type", static_cast<int>(source.type));
+ entry_dict.SetKey("source", std::move(source_dict));
+
+ // Set the event info.
+ entry_dict.SetInteger("type", static_cast<int>(type));
+ entry_dict.SetInteger("phase", static_cast<int>(phase));
+
+ // Set the event-specific parameters.
+ if (!params.is_none())
+ entry_dict.SetKey("params", params.Clone());
+
+ return std::move(entry_dict);
+}
+
} // namespace net