Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "net/base/net_log_logger.h" | 5 #include "net/base/net_log_logger.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "net/base/address_family.h" | 14 #include "net/base/address_family.h" |
| 15 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/quic_utils.h" | 18 #include "net/quic/quic_utils.h" |
| 19 | 19 |
| 20 namespace { | |
| 21 | |
| 22 struct StringToConstant { | |
| 23 const char* name; | |
| 24 const int constant; | |
| 25 }; | |
| 26 | |
| 27 const StringToConstant kCertStatusFlags[] = { | |
| 28 #define CERT_STATUS_FLAG(label, value) { #label, value }, | |
| 29 #include "net/cert/cert_status_flags_list.h" | |
| 30 #undef CERT_STATUS_FLAG | |
| 31 }; | |
| 32 | |
| 33 const StringToConstant kLoadFlags[] = { | |
| 34 #define LOAD_FLAG(label, value) { #label, value }, | |
| 35 #include "net/base/load_flags_list.h" | |
| 36 #undef LOAD_FLAG | |
| 37 }; | |
| 38 | |
| 39 const StringToConstant kLoadStateTable[] = { | |
| 40 #define LOAD_STATE(label) { # label, net::LOAD_STATE_ ## label }, | |
| 41 #include "net/base/load_states_list.h" | |
| 42 #undef LOAD_STATE | |
| 43 }; | |
| 44 | |
| 45 const short kNetErrors[] = { | |
| 46 #define NET_ERROR(label, value) value, | |
| 47 #include "net/base/net_error_list.h" | |
| 48 #undef NET_ERROR | |
| 49 }; | |
| 50 | |
| 51 } | |
|
mmenke
2014/09/16 14:24:29
nit:
} // namespace
| |
| 52 | |
| 20 namespace net { | 53 namespace net { |
| 21 | 54 |
| 22 // This should be incremented when significant changes are made that will | 55 // This should be incremented when significant changes are made that will |
| 23 // invalidate the old loading code. | 56 // invalidate the old loading code. |
| 24 static const int kLogFormatVersion = 1; | 57 static const int kLogFormatVersion = 1; |
| 25 | 58 |
| 26 NetLogLogger::NetLogLogger(FILE* file, const base::Value& constants) | 59 NetLogLogger::NetLogLogger(FILE* file, const base::Value& constants) |
| 27 : file_(file), log_level_(NetLog::LOG_ALL_BUT_BYTES), added_events_(false) { | 60 : file_(file), log_level_(NetLog::LOG_ALL_BUT_BYTES), added_events_(false) { |
| 28 DCHECK(file); | 61 DCHECK(file); |
| 29 | 62 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 108 |
| 76 // Add a dictionary with information on the relationship between event type | 109 // Add a dictionary with information on the relationship between event type |
| 77 // enums and their symbolic names. | 110 // enums and their symbolic names. |
| 78 constants_dict->Set("logEventTypes", net::NetLog::GetEventTypesAsValue()); | 111 constants_dict->Set("logEventTypes", net::NetLog::GetEventTypesAsValue()); |
| 79 | 112 |
| 80 // Add a dictionary with information about the relationship between CertStatus | 113 // Add a dictionary with information about the relationship between CertStatus |
| 81 // flags and their symbolic names. | 114 // flags and their symbolic names. |
| 82 { | 115 { |
| 83 base::DictionaryValue* dict = new base::DictionaryValue(); | 116 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 84 | 117 |
| 85 #define CERT_STATUS_FLAG(label, value) dict->SetInteger(#label, value); | 118 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCertStatusFlags); i++) |
| 86 #include "net/cert/cert_status_flags_list.h" | 119 dict->SetInteger(kCertStatusFlags[i].name, kCertStatusFlags[i].constant); |
| 87 #undef CERT_STATUS_FLAG | |
| 88 | 120 |
| 89 constants_dict->Set("certStatusFlag", dict); | 121 constants_dict->Set("certStatusFlag", dict); |
| 90 } | 122 } |
| 91 | 123 |
| 92 // Add a dictionary with information about the relationship between load flag | 124 // Add a dictionary with information about the relationship between load flag |
| 93 // enums and their symbolic names. | 125 // enums and their symbolic names. |
| 94 { | 126 { |
| 95 base::DictionaryValue* dict = new base::DictionaryValue(); | 127 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 96 | 128 |
| 97 #define LOAD_FLAG(label, value) \ | 129 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLoadFlags); i++) |
| 98 dict->SetInteger(# label, static_cast<int>(value)); | 130 dict->SetInteger(kLoadFlags[i].name, kLoadFlags[i].constant); |
| 99 #include "net/base/load_flags_list.h" | |
| 100 #undef LOAD_FLAG | |
| 101 | 131 |
| 102 constants_dict->Set("loadFlag", dict); | 132 constants_dict->Set("loadFlag", dict); |
| 103 } | 133 } |
| 104 | 134 |
| 105 // Add a dictionary with information about the relationship between load state | 135 // Add a dictionary with information about the relationship between load state |
| 106 // enums and their symbolic names. | 136 // enums and their symbolic names. |
| 107 { | 137 { |
| 108 base::DictionaryValue* dict = new base::DictionaryValue(); | 138 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 109 | 139 |
| 110 #define LOAD_STATE(label) \ | 140 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLoadStateTable); i++) |
| 111 dict->SetInteger(# label, net::LOAD_STATE_ ## label); | 141 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant); |
| 112 #include "net/base/load_states_list.h" | |
| 113 #undef LOAD_STATE | |
| 114 | 142 |
| 115 constants_dict->Set("loadState", dict); | 143 constants_dict->Set("loadState", dict); |
| 116 } | 144 } |
| 117 | 145 |
| 118 // Add information on the relationship between net error codes and their | 146 // Add information on the relationship between net error codes and their |
| 119 // symbolic names. | 147 // symbolic names. |
| 120 { | 148 { |
| 121 base::DictionaryValue* dict = new base::DictionaryValue(); | 149 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 122 | 150 |
| 123 #define NET_ERROR(label, value) \ | 151 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNetErrors); i++) |
| 124 dict->SetInteger(ErrorToShortString(value), static_cast<int>(value)); | 152 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]); |
| 125 #include "net/base/net_error_list.h" | |
| 126 #undef NET_ERROR | |
| 127 | 153 |
| 128 constants_dict->Set("netError", dict); | 154 constants_dict->Set("netError", dict); |
| 129 } | 155 } |
| 130 | 156 |
| 131 // Add information on the relationship between QUIC error codes and their | 157 // Add information on the relationship between QUIC error codes and their |
| 132 // symbolic names. | 158 // symbolic names. |
| 133 { | 159 { |
| 134 base::DictionaryValue* dict = new base::DictionaryValue(); | 160 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 135 | 161 |
| 136 for (net::QuicErrorCode error = net::QUIC_NO_ERROR; | 162 for (net::QuicErrorCode error = net::QUIC_NO_ERROR; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 } | 253 } |
| 228 | 254 |
| 229 // "clientInfo" key is required for some NetLogLogger log readers. | 255 // "clientInfo" key is required for some NetLogLogger log readers. |
| 230 // Provide a default empty value for compatibility. | 256 // Provide a default empty value for compatibility. |
| 231 constants_dict->Set("clientInfo", new base::DictionaryValue()); | 257 constants_dict->Set("clientInfo", new base::DictionaryValue()); |
| 232 | 258 |
| 233 return constants_dict; | 259 return constants_dict; |
| 234 } | 260 } |
| 235 | 261 |
| 236 } // namespace net | 262 } // namespace net |
| OLD | NEW |