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

Side by Side Diff: net/base/net_log_util.cc

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « net/base/net_log_util.h ('k') | net/base/net_log_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/net_log_util.h"
6
7 #include <string>
8
9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
13 #include "base/values.h"
14 #include "net/base/address_family.h"
15 #include "net/base/load_states.h"
16 #include "net/base/net_errors.h"
17 #include "net/base/net_log.h"
18 #include "net/disk_cache/disk_cache.h"
19 #include "net/dns/host_cache.h"
20 #include "net/dns/host_resolver.h"
21 #include "net/http/http_cache.h"
22 #include "net/http/http_network_session.h"
23 #include "net/http/http_server_properties.h"
24 #include "net/http/http_transaction_factory.h"
25 #include "net/proxy/proxy_config.h"
26 #include "net/proxy/proxy_retry_info.h"
27 #include "net/proxy/proxy_service.h"
28 #include "net/quic/quic_protocol.h"
29 #include "net/quic/quic_utils.h"
30 #include "net/url_request/url_request_context.h"
31
32 namespace net {
33
34 namespace {
35
36 // This should be incremented when significant changes are made that will
37 // invalidate the old loading code.
38 const int kLogFormatVersion = 1;
39
40 struct StringToConstant {
41 const char* name;
42 const int constant;
43 };
44
45 const StringToConstant kCertStatusFlags[] = {
46 #define CERT_STATUS_FLAG(label, value) { #label, value },
47 #include "net/cert/cert_status_flags_list.h"
48 #undef CERT_STATUS_FLAG
49 };
50
51 const StringToConstant kLoadFlags[] = {
52 #define LOAD_FLAG(label, value) { #label, value },
53 #include "net/base/load_flags_list.h"
54 #undef LOAD_FLAG
55 };
56
57 const StringToConstant kLoadStateTable[] = {
58 #define LOAD_STATE(label) { # label, net::LOAD_STATE_ ## label },
59 #include "net/base/load_states_list.h"
60 #undef LOAD_STATE
61 };
62
63 const short kNetErrors[] = {
64 #define NET_ERROR(label, value) value,
65 #include "net/base/net_error_list.h"
66 #undef NET_ERROR
67 };
68
69 const char* NetInfoSourceToString(NetInfoSource source) {
70 switch (source) {
71 #define NET_INFO_SOURCE(label, string, value) \
72 case NET_INFO_ ## label: \
73 return string;
74 #include "net/base/net_info_source_list.h"
75 #undef NET_INFO_SOURCE
76 case NET_INFO_ALL_SOURCES:
77 return "All";
78 }
79 return "?";
80 }
81
82 // Returns the disk cache backend for |context| if there is one, or NULL.
83 // Despite the name, can return an in memory "disk cache".
84 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) {
85 if (!context->http_transaction_factory())
86 return NULL;
87
88 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache();
89 if (!http_cache)
90 return NULL;
91
92 return http_cache->GetCurrentBackend();
93 }
94
95 } // namespace
96
97 scoped_ptr<base::DictionaryValue> GetNetConstants() {
98 scoped_ptr<base::DictionaryValue> constants_dict(new base::DictionaryValue());
99
100 // Version of the file format.
101 constants_dict->SetInteger("logFormatVersion", kLogFormatVersion);
102
103 // Add a dictionary with information on the relationship between event type
104 // enums and their symbolic names.
105 constants_dict->Set("logEventTypes", net::NetLog::GetEventTypesAsValue());
106
107 // Add a dictionary with information about the relationship between CertStatus
108 // flags and their symbolic names.
109 {
110 base::DictionaryValue* dict = new base::DictionaryValue();
111
112 for (size_t i = 0; i < arraysize(kCertStatusFlags); i++)
113 dict->SetInteger(kCertStatusFlags[i].name, kCertStatusFlags[i].constant);
114
115 constants_dict->Set("certStatusFlag", dict);
116 }
117
118 // Add a dictionary with information about the relationship between load flag
119 // enums and their symbolic names.
120 {
121 base::DictionaryValue* dict = new base::DictionaryValue();
122
123 for (size_t i = 0; i < arraysize(kLoadFlags); i++)
124 dict->SetInteger(kLoadFlags[i].name, kLoadFlags[i].constant);
125
126 constants_dict->Set("loadFlag", dict);
127 }
128
129 // Add a dictionary with information about the relationship between load state
130 // enums and their symbolic names.
131 {
132 base::DictionaryValue* dict = new base::DictionaryValue();
133
134 for (size_t i = 0; i < arraysize(kLoadStateTable); i++)
135 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant);
136
137 constants_dict->Set("loadState", dict);
138 }
139
140 {
141 base::DictionaryValue* dict = new base::DictionaryValue();
142 #define NET_INFO_SOURCE(label, string, value) \
143 dict->SetInteger(string, NET_INFO_ ## label);
144 #include "net/base/net_info_source_list.h"
145 #undef NET_INFO_SOURCE
146 constants_dict->Set("netInfoSources", dict);
147 }
148
149 // Add information on the relationship between net error codes and their
150 // symbolic names.
151 {
152 base::DictionaryValue* dict = new base::DictionaryValue();
153
154 for (size_t i = 0; i < arraysize(kNetErrors); i++)
155 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]);
156
157 constants_dict->Set("netError", dict);
158 }
159
160 // Add information on the relationship between QUIC error codes and their
161 // symbolic names.
162 {
163 base::DictionaryValue* dict = new base::DictionaryValue();
164
165 for (net::QuicErrorCode error = net::QUIC_NO_ERROR;
166 error < net::QUIC_LAST_ERROR;
167 error = static_cast<net::QuicErrorCode>(error + 1)) {
168 dict->SetInteger(net::QuicUtils::ErrorToString(error),
169 static_cast<int>(error));
170 }
171
172 constants_dict->Set("quicError", dict);
173 }
174
175 // Add information on the relationship between QUIC RST_STREAM error codes
176 // and their symbolic names.
177 {
178 base::DictionaryValue* dict = new base::DictionaryValue();
179
180 for (net::QuicRstStreamErrorCode error = net::QUIC_STREAM_NO_ERROR;
181 error < net::QUIC_STREAM_LAST_ERROR;
182 error = static_cast<net::QuicRstStreamErrorCode>(error + 1)) {
183 dict->SetInteger(net::QuicUtils::StreamErrorToString(error),
184 static_cast<int>(error));
185 }
186
187 constants_dict->Set("quicRstStreamError", dict);
188 }
189
190 // Information about the relationship between event phase enums and their
191 // symbolic names.
192 {
193 base::DictionaryValue* dict = new base::DictionaryValue();
194
195 dict->SetInteger("PHASE_BEGIN", net::NetLog::PHASE_BEGIN);
196 dict->SetInteger("PHASE_END", net::NetLog::PHASE_END);
197 dict->SetInteger("PHASE_NONE", net::NetLog::PHASE_NONE);
198
199 constants_dict->Set("logEventPhase", dict);
200 }
201
202 // Information about the relationship between source type enums and
203 // their symbolic names.
204 constants_dict->Set("logSourceType", net::NetLog::GetSourceTypesAsValue());
205
206 // Information about the relationship between LogLevel enums and their
207 // symbolic names.
208 {
209 base::DictionaryValue* dict = new base::DictionaryValue();
210
211 dict->SetInteger("LOG_ALL", net::NetLog::LOG_ALL);
212 dict->SetInteger("LOG_ALL_BUT_BYTES", net::NetLog::LOG_ALL_BUT_BYTES);
213 dict->SetInteger("LOG_STRIP_PRIVATE_DATA",
214 net::NetLog::LOG_STRIP_PRIVATE_DATA);
215
216 constants_dict->Set("logLevelType", dict);
217 }
218
219 // Information about the relationship between address family enums and
220 // their symbolic names.
221 {
222 base::DictionaryValue* dict = new base::DictionaryValue();
223
224 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED",
225 net::ADDRESS_FAMILY_UNSPECIFIED);
226 dict->SetInteger("ADDRESS_FAMILY_IPV4",
227 net::ADDRESS_FAMILY_IPV4);
228 dict->SetInteger("ADDRESS_FAMILY_IPV6",
229 net::ADDRESS_FAMILY_IPV6);
230
231 constants_dict->Set("addressFamily", dict);
232 }
233
234 // Information about how the "time ticks" values we have given it relate to
235 // actual system times. (We used time ticks throughout since they are stable
236 // across system clock changes).
237 {
238 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds();
239
240 int64 cur_time_ticks_ms =
241 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
242
243 // If we add this number to a time tick value, it gives the timestamp.
244 int64 tick_to_time_ms = cur_time_ms - cur_time_ticks_ms;
245
246 // Chrome on all platforms stores times using the Windows epoch
247 // (Jan 1 1601), but the javascript wants a unix epoch.
248 // TODO(eroman): Getting the timestamp relative to the unix epoch should
249 // be part of the time library.
250 const int64 kUnixEpochMs = 11644473600000LL;
251 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs;
252
253 // Pass it as a string, since it may be too large to fit in an integer.
254 constants_dict->SetString("timeTickOffset",
255 base::Int64ToString(tick_to_unix_time_ms));
256 }
257
258 // "clientInfo" key is required for some NetLogLogger log readers.
259 // Provide a default empty value for compatibility.
260 constants_dict->Set("clientInfo", new base::DictionaryValue());
261
262 // Add a list of active field experiments.
263 {
264 base::FieldTrial::ActiveGroups active_groups;
265 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
266 base::ListValue* field_trial_groups = new base::ListValue();
267 for (base::FieldTrial::ActiveGroups::const_iterator it =
268 active_groups.begin();
269 it != active_groups.end(); ++it) {
270 field_trial_groups->AppendString(it->trial_name + ":" +
271 it->group_name);
272 }
273 constants_dict->Set("activeFieldTrialGroups", field_trial_groups);
274 }
275
276 return constants_dict.Pass();
277 }
278
279 NET_EXPORT scoped_ptr<base::DictionaryValue> GetNetInfo(
280 URLRequestContext* context, int info_sources) {
281 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue());
282
283 // TODO(mmenke): The code for most of these sources should probably be moved
284 // into the sources themselves.
285 if (info_sources & NET_INFO_PROXY_SETTINGS) {
286 net::ProxyService* proxy_service = context->proxy_service();
287
288 base::DictionaryValue* dict = new base::DictionaryValue();
289 if (proxy_service->fetched_config().is_valid())
290 dict->Set("original", proxy_service->fetched_config().ToValue());
291 if (proxy_service->config().is_valid())
292 dict->Set("effective", proxy_service->config().ToValue());
293
294 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), dict);
295 }
296
297 if (info_sources & NET_INFO_BAD_PROXIES) {
298 const net::ProxyRetryInfoMap& bad_proxies_map =
299 context->proxy_service()->proxy_retry_info();
300
301 base::ListValue* list = new base::ListValue();
302
303 for (net::ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin();
304 it != bad_proxies_map.end(); ++it) {
305 const std::string& proxy_uri = it->first;
306 const net::ProxyRetryInfo& retry_info = it->second;
307
308 base::DictionaryValue* dict = new base::DictionaryValue();
309 dict->SetString("proxy_uri", proxy_uri);
310 dict->SetString("bad_until",
311 net::NetLog::TickCountToString(retry_info.bad_until));
312
313 list->Append(dict);
314 }
315
316 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), list);
317 }
318
319 if (info_sources & NET_INFO_HOST_RESOLVER) {
320 net::HostResolver* host_resolver = context->host_resolver();
321 DCHECK(host_resolver);
322 net::HostCache* cache = host_resolver->GetHostCache();
323 if (cache) {
324 base::DictionaryValue* dict = new base::DictionaryValue();
325 base::Value* dns_config = host_resolver->GetDnsConfigAsValue();
326 if (dns_config)
327 dict->Set("dns_config", dns_config);
328
329 dict->SetInteger(
330 "default_address_family",
331 static_cast<int>(host_resolver->GetDefaultAddressFamily()));
332
333 base::DictionaryValue* cache_info_dict = new base::DictionaryValue();
334
335 cache_info_dict->SetInteger(
336 "capacity",
337 static_cast<int>(cache->max_entries()));
338
339 base::ListValue* entry_list = new base::ListValue();
340
341 net::HostCache::EntryMap::Iterator it(cache->entries());
342 for (; it.HasNext(); it.Advance()) {
343 const net::HostCache::Key& key = it.key();
344 const net::HostCache::Entry& entry = it.value();
345
346 base::DictionaryValue* entry_dict = new base::DictionaryValue();
347
348 entry_dict->SetString("hostname", key.hostname);
349 entry_dict->SetInteger("address_family",
350 static_cast<int>(key.address_family));
351 entry_dict->SetString("expiration",
352 net::NetLog::TickCountToString(it.expiration()));
353
354 if (entry.error != net::OK) {
355 entry_dict->SetInteger("error", entry.error);
356 } else {
357 // Append all of the resolved addresses.
358 base::ListValue* address_list = new base::ListValue();
359 for (size_t i = 0; i < entry.addrlist.size(); ++i) {
360 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort());
361 }
362 entry_dict->Set("addresses", address_list);
363 }
364
365 entry_list->Append(entry_dict);
366 }
367
368 cache_info_dict->Set("entries", entry_list);
369 dict->Set("cache", cache_info_dict);
370 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), dict);
371 }
372 }
373
374 net::HttpNetworkSession* http_network_session =
375 context->http_transaction_factory()->GetSession();
376
377 if (info_sources & NET_INFO_SOCKET_POOL) {
378 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL),
379 http_network_session->SocketPoolInfoToValue());
380 }
381
382 if (info_sources & NET_INFO_SPDY_SESSIONS) {
383 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS),
384 http_network_session->SpdySessionPoolInfoToValue());
385 }
386
387 if (info_sources & NET_INFO_SPDY_STATUS) {
388 base::DictionaryValue* status_dict = new base::DictionaryValue();
389
390 status_dict->SetBoolean("spdy_enabled",
391 net::HttpStreamFactory::spdy_enabled());
392 status_dict->SetBoolean(
393 "use_alternate_protocols",
394 http_network_session->params().use_alternate_protocols);
395 status_dict->SetBoolean(
396 "force_spdy_over_ssl",
397 http_network_session->params().force_spdy_over_ssl);
398 status_dict->SetBoolean(
399 "force_spdy_always",
400 http_network_session->params().force_spdy_always);
401
402 std::vector<std::string> next_protos;
403 http_network_session->GetNextProtos(&next_protos);
404 std::string next_protos_string = JoinString(next_protos, ',');
405 status_dict->SetString("next_protos", next_protos_string);
406
407 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS),
408 status_dict);
409 }
410
411 if (info_sources & NET_INFO_SPDY_ALT_PROTO_MAPPINGS) {
412 base::ListValue* dict_list = new base::ListValue();
413
414 const net::HttpServerProperties& http_server_properties =
415 *context->http_server_properties();
416
417 const net::AlternateProtocolMap& map =
418 http_server_properties.alternate_protocol_map();
419
420 for (net::AlternateProtocolMap::const_iterator it = map.begin();
421 it != map.end(); ++it) {
422 base::DictionaryValue* dict = new base::DictionaryValue();
423 dict->SetString("host_port_pair", it->first.ToString());
424 dict->SetString("alternate_protocol", it->second.ToString());
425 dict_list->Append(dict);
426 }
427
428 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_ALT_PROTO_MAPPINGS),
429 dict_list);
430 }
431
432 if (info_sources & NET_INFO_QUIC) {
433 net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC),
434 http_network_session->QuicInfoToValue());
435 }
436
437 if (info_sources & NET_INFO_HTTP_CACHE) {
438 base::DictionaryValue* info_dict = new base::DictionaryValue();
439 base::DictionaryValue* stats_dict = new base::DictionaryValue();
440
441 disk_cache::Backend* disk_cache = GetDiskCacheBackend(context);
442
443 if (disk_cache) {
444 // Extract the statistics key/value pairs from the backend.
445 base::StringPairs stats;
446 disk_cache->GetStats(&stats);
447 for (size_t i = 0; i < stats.size(); ++i) {
448 stats_dict->SetStringWithoutPathExpansion(
449 stats[i].first, stats[i].second);
450 }
451 }
452 info_dict->Set("stats", stats_dict);
453
454 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE),
455 info_dict);
456 }
457
458 return net_info_dict.Pass();
459 }
460
461 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_log_util.h ('k') | net/base/net_log_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698