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

Unified Diff: net/base/net_log_logger.cc

Issue 574433002: Make the net logging code more compact. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Net logger, addressed nit. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_log_logger.h ('k') | net/cert/cert_status_flags_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_log_logger.cc
diff --git a/net/base/net_log_logger.cc b/net/base/net_log_logger.cc
index f6ac5dd7188c0c8e49f0eb105baa666c92264dec..b69a70be317c5efff0bdf177ebb2a2976a1ebe4b 100644
--- a/net/base/net_log_logger.cc
+++ b/net/base/net_log_logger.cc
@@ -17,6 +17,39 @@
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_utils.h"
+namespace {
+
+struct StringToConstant {
+ const char* name;
+ const int constant;
+};
+
+const StringToConstant kCertStatusFlags[] = {
+#define CERT_STATUS_FLAG(label, value) { #label, value },
+#include "net/cert/cert_status_flags_list.h"
+#undef CERT_STATUS_FLAG
+};
+
+const StringToConstant kLoadFlags[] = {
+#define LOAD_FLAG(label, value) { #label, value },
+#include "net/base/load_flags_list.h"
+#undef LOAD_FLAG
+};
+
+const StringToConstant kLoadStateTable[] = {
+#define LOAD_STATE(label) { # label, net::LOAD_STATE_ ## label },
+#include "net/base/load_states_list.h"
+#undef LOAD_STATE
+};
+
+const short kNetErrors[] = {
+#define NET_ERROR(label, value) value,
+#include "net/base/net_error_list.h"
+#undef NET_ERROR
+};
+
+} // namespace
+
namespace net {
// This should be incremented when significant changes are made that will
@@ -82,9 +115,8 @@ base::DictionaryValue* NetLogLogger::GetConstants() {
{
base::DictionaryValue* dict = new base::DictionaryValue();
-#define CERT_STATUS_FLAG(label, value) dict->SetInteger(#label, value);
-#include "net/cert/cert_status_flags_list.h"
-#undef CERT_STATUS_FLAG
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCertStatusFlags); i++)
+ dict->SetInteger(kCertStatusFlags[i].name, kCertStatusFlags[i].constant);
constants_dict->Set("certStatusFlag", dict);
}
@@ -94,10 +126,8 @@ base::DictionaryValue* NetLogLogger::GetConstants() {
{
base::DictionaryValue* dict = new base::DictionaryValue();
-#define LOAD_FLAG(label, value) \
- dict->SetInteger(# label, static_cast<int>(value));
-#include "net/base/load_flags_list.h"
-#undef LOAD_FLAG
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLoadFlags); i++)
+ dict->SetInteger(kLoadFlags[i].name, kLoadFlags[i].constant);
constants_dict->Set("loadFlag", dict);
}
@@ -107,10 +137,8 @@ base::DictionaryValue* NetLogLogger::GetConstants() {
{
base::DictionaryValue* dict = new base::DictionaryValue();
-#define LOAD_STATE(label) \
- dict->SetInteger(# label, net::LOAD_STATE_ ## label);
-#include "net/base/load_states_list.h"
-#undef LOAD_STATE
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLoadStateTable); i++)
+ dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant);
constants_dict->Set("loadState", dict);
}
@@ -120,10 +148,8 @@ base::DictionaryValue* NetLogLogger::GetConstants() {
{
base::DictionaryValue* dict = new base::DictionaryValue();
-#define NET_ERROR(label, value) \
- dict->SetInteger(ErrorToShortString(value), static_cast<int>(value));
-#include "net/base/net_error_list.h"
-#undef NET_ERROR
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNetErrors); i++)
+ dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]);
constants_dict->Set("netError", dict);
}
« no previous file with comments | « net/base/net_log_logger.h ('k') | net/cert/cert_status_flags_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698