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

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

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_util.h" 5 #include "net/base/net_log_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 25 matching lines...) Expand all
36 // This should be incremented when significant changes are made that will 36 // This should be incremented when significant changes are made that will
37 // invalidate the old loading code. 37 // invalidate the old loading code.
38 const int kLogFormatVersion = 1; 38 const int kLogFormatVersion = 1;
39 39
40 struct StringToConstant { 40 struct StringToConstant {
41 const char* name; 41 const char* name;
42 const int constant; 42 const int constant;
43 }; 43 };
44 44
45 const StringToConstant kCertStatusFlags[] = { 45 const StringToConstant kCertStatusFlags[] = {
46 #define CERT_STATUS_FLAG(label, value) { #label, value }, 46 #define CERT_STATUS_FLAG(label, value) \
47 { #label, value } \
48 ,
47 #include "net/cert/cert_status_flags_list.h" 49 #include "net/cert/cert_status_flags_list.h"
48 #undef CERT_STATUS_FLAG 50 #undef CERT_STATUS_FLAG
49 }; 51 };
50 52
51 const StringToConstant kLoadFlags[] = { 53 const StringToConstant kLoadFlags[] = {
52 #define LOAD_FLAG(label, value) { #label, value }, 54 #define LOAD_FLAG(label, value) \
55 { #label, value } \
56 ,
mmenke 2014/12/02 19:22:29 The placement of the comma here is really weird.
53 #include "net/base/load_flags_list.h" 57 #include "net/base/load_flags_list.h"
54 #undef LOAD_FLAG 58 #undef LOAD_FLAG
55 }; 59 };
56 60
57 const StringToConstant kLoadStateTable[] = { 61 const StringToConstant kLoadStateTable[] = {
58 #define LOAD_STATE(label) { # label, net::LOAD_STATE_ ## label }, 62 #define LOAD_STATE(label) \
63 { #label, net::LOAD_STATE_##label } \
64 ,
59 #include "net/base/load_states_list.h" 65 #include "net/base/load_states_list.h"
60 #undef LOAD_STATE 66 #undef LOAD_STATE
61 }; 67 };
62 68
63 const short kNetErrors[] = { 69 const short kNetErrors[] = {
64 #define NET_ERROR(label, value) value, 70 #define NET_ERROR(label, value) value,
65 #include "net/base/net_error_list.h" 71 #include "net/base/net_error_list.h"
66 #undef NET_ERROR 72 #undef NET_ERROR
67 }; 73 };
68 74
69 const char* NetInfoSourceToString(NetInfoSource source) { 75 const char* NetInfoSourceToString(NetInfoSource source) {
70 switch (source) { 76 switch (source) {
71 #define NET_INFO_SOURCE(label, string, value) \ 77 #define NET_INFO_SOURCE(label, string, value) \
72 case NET_INFO_ ## label: \ 78 case NET_INFO_##label: \
73 return string; 79 return string;
74 #include "net/base/net_info_source_list.h" 80 #include "net/base/net_info_source_list.h"
75 #undef NET_INFO_SOURCE 81 #undef NET_INFO_SOURCE
76 case NET_INFO_ALL_SOURCES: 82 case NET_INFO_ALL_SOURCES:
77 return "All"; 83 return "All";
78 } 84 }
79 return "?"; 85 return "?";
80 } 86 }
81 87
82 // Returns the disk cache backend for |context| if there is one, or NULL. 88 // Returns the disk cache backend for |context| if there is one, or NULL.
83 // Despite the name, can return an in memory "disk cache". 89 // Despite the name, can return an in memory "disk cache".
84 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) { 90 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) {
85 if (!context->http_transaction_factory()) 91 if (!context->http_transaction_factory())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 base::DictionaryValue* dict = new base::DictionaryValue(); 138 base::DictionaryValue* dict = new base::DictionaryValue();
133 139
134 for (size_t i = 0; i < arraysize(kLoadStateTable); i++) 140 for (size_t i = 0; i < arraysize(kLoadStateTable); i++)
135 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant); 141 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant);
136 142
137 constants_dict->Set("loadState", dict); 143 constants_dict->Set("loadState", dict);
138 } 144 }
139 145
140 { 146 {
141 base::DictionaryValue* dict = new base::DictionaryValue(); 147 base::DictionaryValue* dict = new base::DictionaryValue();
142 #define NET_INFO_SOURCE(label, string, value) \ 148 #define NET_INFO_SOURCE(label, string, value) \
143 dict->SetInteger(string, NET_INFO_ ## label); 149 dict->SetInteger(string, NET_INFO_##label);
144 #include "net/base/net_info_source_list.h" 150 #include "net/base/net_info_source_list.h"
145 #undef NET_INFO_SOURCE 151 #undef NET_INFO_SOURCE
146 constants_dict->Set("netInfoSources", dict); 152 constants_dict->Set("netInfoSources", dict);
147 } 153 }
148 154
149 // Add information on the relationship between net error codes and their 155 // Add information on the relationship between net error codes and their
150 // symbolic names. 156 // symbolic names.
151 { 157 {
152 base::DictionaryValue* dict = new base::DictionaryValue(); 158 base::DictionaryValue* dict = new base::DictionaryValue();
153 159
154 for (size_t i = 0; i < arraysize(kNetErrors); i++) 160 for (size_t i = 0; i < arraysize(kNetErrors); i++)
155 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]); 161 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 constants_dict->Set("logLevelType", dict); 222 constants_dict->Set("logLevelType", dict);
217 } 223 }
218 224
219 // Information about the relationship between address family enums and 225 // Information about the relationship between address family enums and
220 // their symbolic names. 226 // their symbolic names.
221 { 227 {
222 base::DictionaryValue* dict = new base::DictionaryValue(); 228 base::DictionaryValue* dict = new base::DictionaryValue();
223 229
224 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", 230 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED",
225 net::ADDRESS_FAMILY_UNSPECIFIED); 231 net::ADDRESS_FAMILY_UNSPECIFIED);
226 dict->SetInteger("ADDRESS_FAMILY_IPV4", 232 dict->SetInteger("ADDRESS_FAMILY_IPV4", net::ADDRESS_FAMILY_IPV4);
227 net::ADDRESS_FAMILY_IPV4); 233 dict->SetInteger("ADDRESS_FAMILY_IPV6", net::ADDRESS_FAMILY_IPV6);
228 dict->SetInteger("ADDRESS_FAMILY_IPV6",
229 net::ADDRESS_FAMILY_IPV6);
230 234
231 constants_dict->Set("addressFamily", dict); 235 constants_dict->Set("addressFamily", dict);
232 } 236 }
233 237
234 // Information about how the "time ticks" values we have given it relate to 238 // 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 239 // actual system times. (We used time ticks throughout since they are stable
236 // across system clock changes). 240 // across system clock changes).
237 { 241 {
238 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds(); 242 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds();
239 243
(...skipping 20 matching lines...) Expand all
260 constants_dict->Set("clientInfo", new base::DictionaryValue()); 264 constants_dict->Set("clientInfo", new base::DictionaryValue());
261 265
262 // Add a list of active field experiments. 266 // Add a list of active field experiments.
263 { 267 {
264 base::FieldTrial::ActiveGroups active_groups; 268 base::FieldTrial::ActiveGroups active_groups;
265 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); 269 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
266 base::ListValue* field_trial_groups = new base::ListValue(); 270 base::ListValue* field_trial_groups = new base::ListValue();
267 for (base::FieldTrial::ActiveGroups::const_iterator it = 271 for (base::FieldTrial::ActiveGroups::const_iterator it =
268 active_groups.begin(); 272 active_groups.begin();
269 it != active_groups.end(); ++it) { 273 it != active_groups.end(); ++it) {
270 field_trial_groups->AppendString(it->trial_name + ":" + 274 field_trial_groups->AppendString(it->trial_name + ":" + it->group_name);
271 it->group_name);
272 } 275 }
273 constants_dict->Set("activeFieldTrialGroups", field_trial_groups); 276 constants_dict->Set("activeFieldTrialGroups", field_trial_groups);
274 } 277 }
275 278
276 return constants_dict.Pass(); 279 return constants_dict.Pass();
277 } 280 }
278 281
279 NET_EXPORT scoped_ptr<base::DictionaryValue> GetNetInfo( 282 NET_EXPORT scoped_ptr<base::DictionaryValue> GetNetInfo(
280 URLRequestContext* context, int info_sources) { 283 URLRequestContext* context,
284 int info_sources) {
281 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue()); 285 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue());
282 286
283 // TODO(mmenke): The code for most of these sources should probably be moved 287 // TODO(mmenke): The code for most of these sources should probably be moved
284 // into the sources themselves. 288 // into the sources themselves.
285 if (info_sources & NET_INFO_PROXY_SETTINGS) { 289 if (info_sources & NET_INFO_PROXY_SETTINGS) {
286 net::ProxyService* proxy_service = context->proxy_service(); 290 net::ProxyService* proxy_service = context->proxy_service();
287 291
288 base::DictionaryValue* dict = new base::DictionaryValue(); 292 base::DictionaryValue* dict = new base::DictionaryValue();
289 if (proxy_service->fetched_config().is_valid()) 293 if (proxy_service->fetched_config().is_valid())
290 dict->Set("original", proxy_service->fetched_config().ToValue()); 294 dict->Set("original", proxy_service->fetched_config().ToValue());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 base::Value* dns_config = host_resolver->GetDnsConfigAsValue(); 329 base::Value* dns_config = host_resolver->GetDnsConfigAsValue();
326 if (dns_config) 330 if (dns_config)
327 dict->Set("dns_config", dns_config); 331 dict->Set("dns_config", dns_config);
328 332
329 dict->SetInteger( 333 dict->SetInteger(
330 "default_address_family", 334 "default_address_family",
331 static_cast<int>(host_resolver->GetDefaultAddressFamily())); 335 static_cast<int>(host_resolver->GetDefaultAddressFamily()));
332 336
333 base::DictionaryValue* cache_info_dict = new base::DictionaryValue(); 337 base::DictionaryValue* cache_info_dict = new base::DictionaryValue();
334 338
335 cache_info_dict->SetInteger( 339 cache_info_dict->SetInteger("capacity",
336 "capacity", 340 static_cast<int>(cache->max_entries()));
337 static_cast<int>(cache->max_entries()));
338 341
339 base::ListValue* entry_list = new base::ListValue(); 342 base::ListValue* entry_list = new base::ListValue();
340 343
341 net::HostCache::EntryMap::Iterator it(cache->entries()); 344 net::HostCache::EntryMap::Iterator it(cache->entries());
342 for (; it.HasNext(); it.Advance()) { 345 for (; it.HasNext(); it.Advance()) {
343 const net::HostCache::Key& key = it.key(); 346 const net::HostCache::Key& key = it.key();
344 const net::HostCache::Entry& entry = it.value(); 347 const net::HostCache::Entry& entry = it.value();
345 348
346 base::DictionaryValue* entry_dict = new base::DictionaryValue(); 349 base::DictionaryValue* entry_dict = new base::DictionaryValue();
347 350
348 entry_dict->SetString("hostname", key.hostname); 351 entry_dict->SetString("hostname", key.hostname);
349 entry_dict->SetInteger("address_family", 352 entry_dict->SetInteger("address_family",
350 static_cast<int>(key.address_family)); 353 static_cast<int>(key.address_family));
351 entry_dict->SetString("expiration", 354 entry_dict->SetString("expiration",
352 net::NetLog::TickCountToString(it.expiration())); 355 net::NetLog::TickCountToString(it.expiration()));
353 356
354 if (entry.error != net::OK) { 357 if (entry.error != net::OK) {
355 entry_dict->SetInteger("error", entry.error); 358 entry_dict->SetInteger("error", entry.error);
356 } else { 359 } else {
357 // Append all of the resolved addresses. 360 // Append all of the resolved addresses.
358 base::ListValue* address_list = new base::ListValue(); 361 base::ListValue* address_list = new base::ListValue();
359 for (size_t i = 0; i < entry.addrlist.size(); ++i) { 362 for (size_t i = 0; i < entry.addrlist.size(); ++i) {
360 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort()); 363 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort());
361 } 364 }
362 entry_dict->Set("addresses", address_list); 365 entry_dict->Set("addresses", address_list);
363 } 366 }
364 367
365 entry_list->Append(entry_dict); 368 entry_list->Append(entry_dict);
366 } 369 }
367 370
368 cache_info_dict->Set("entries", entry_list); 371 cache_info_dict->Set("entries", entry_list);
369 dict->Set("cache", cache_info_dict); 372 dict->Set("cache", cache_info_dict);
370 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), dict); 373 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), dict);
371 } 374 }
372 } 375 }
373 376
374 net::HttpNetworkSession* http_network_session = 377 net::HttpNetworkSession* http_network_session =
375 context->http_transaction_factory()->GetSession(); 378 context->http_transaction_factory()->GetSession();
376 379
377 if (info_sources & NET_INFO_SOCKET_POOL) { 380 if (info_sources & NET_INFO_SOCKET_POOL) {
378 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), 381 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL),
379 http_network_session->SocketPoolInfoToValue()); 382 http_network_session->SocketPoolInfoToValue());
380 } 383 }
381 384
382 if (info_sources & NET_INFO_SPDY_SESSIONS) { 385 if (info_sources & NET_INFO_SPDY_SESSIONS) {
383 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS), 386 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS),
384 http_network_session->SpdySessionPoolInfoToValue()); 387 http_network_session->SpdySessionPoolInfoToValue());
385 } 388 }
386 389
387 if (info_sources & NET_INFO_SPDY_STATUS) { 390 if (info_sources & NET_INFO_SPDY_STATUS) {
388 base::DictionaryValue* status_dict = new base::DictionaryValue(); 391 base::DictionaryValue* status_dict = new base::DictionaryValue();
389 392
390 status_dict->SetBoolean("spdy_enabled", 393 status_dict->SetBoolean("spdy_enabled",
391 net::HttpStreamFactory::spdy_enabled()); 394 net::HttpStreamFactory::spdy_enabled());
392 status_dict->SetBoolean( 395 status_dict->SetBoolean(
393 "use_alternate_protocols", 396 "use_alternate_protocols",
394 http_network_session->params().use_alternate_protocols); 397 http_network_session->params().use_alternate_protocols);
395 status_dict->SetBoolean( 398 status_dict->SetBoolean("force_spdy_over_ssl",
396 "force_spdy_over_ssl", 399 http_network_session->params().force_spdy_over_ssl);
397 http_network_session->params().force_spdy_over_ssl); 400 status_dict->SetBoolean("force_spdy_always",
398 status_dict->SetBoolean( 401 http_network_session->params().force_spdy_always);
399 "force_spdy_always",
400 http_network_session->params().force_spdy_always);
401 402
402 std::vector<std::string> next_protos; 403 std::vector<std::string> next_protos;
403 http_network_session->GetNextProtos(&next_protos); 404 http_network_session->GetNextProtos(&next_protos);
404 std::string next_protos_string = JoinString(next_protos, ','); 405 std::string next_protos_string = JoinString(next_protos, ',');
405 status_dict->SetString("next_protos", next_protos_string); 406 status_dict->SetString("next_protos", next_protos_string);
406 407
407 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS), 408 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS),
408 status_dict); 409 status_dict);
409 } 410 }
410 411
411 if (info_sources & NET_INFO_SPDY_ALT_PROTO_MAPPINGS) { 412 if (info_sources & NET_INFO_SPDY_ALT_PROTO_MAPPINGS) {
412 base::ListValue* dict_list = new base::ListValue(); 413 base::ListValue* dict_list = new base::ListValue();
413 414
414 const net::HttpServerProperties& http_server_properties = 415 const net::HttpServerProperties& http_server_properties =
415 *context->http_server_properties(); 416 *context->http_server_properties();
416 417
417 const net::AlternateProtocolMap& map = 418 const net::AlternateProtocolMap& map =
418 http_server_properties.alternate_protocol_map(); 419 http_server_properties.alternate_protocol_map();
419 420
420 for (net::AlternateProtocolMap::const_iterator it = map.begin(); 421 for (net::AlternateProtocolMap::const_iterator it = map.begin();
421 it != map.end(); ++it) { 422 it != map.end(); ++it) {
422 base::DictionaryValue* dict = new base::DictionaryValue(); 423 base::DictionaryValue* dict = new base::DictionaryValue();
423 dict->SetString("host_port_pair", it->first.ToString()); 424 dict->SetString("host_port_pair", it->first.ToString());
424 dict->SetString("alternate_protocol", it->second.ToString()); 425 dict->SetString("alternate_protocol", it->second.ToString());
425 dict_list->Append(dict); 426 dict_list->Append(dict);
426 } 427 }
427 428
428 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_ALT_PROTO_MAPPINGS), 429 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_ALT_PROTO_MAPPINGS),
429 dict_list); 430 dict_list);
430 } 431 }
431 432
432 if (info_sources & NET_INFO_QUIC) { 433 if (info_sources & NET_INFO_QUIC) {
433 net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC), 434 net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC),
434 http_network_session->QuicInfoToValue()); 435 http_network_session->QuicInfoToValue());
435 } 436 }
436 437
437 if (info_sources & NET_INFO_HTTP_CACHE) { 438 if (info_sources & NET_INFO_HTTP_CACHE) {
438 base::DictionaryValue* info_dict = new base::DictionaryValue(); 439 base::DictionaryValue* info_dict = new base::DictionaryValue();
439 base::DictionaryValue* stats_dict = new base::DictionaryValue(); 440 base::DictionaryValue* stats_dict = new base::DictionaryValue();
440 441
441 disk_cache::Backend* disk_cache = GetDiskCacheBackend(context); 442 disk_cache::Backend* disk_cache = GetDiskCacheBackend(context);
442 443
443 if (disk_cache) { 444 if (disk_cache) {
444 // Extract the statistics key/value pairs from the backend. 445 // Extract the statistics key/value pairs from the backend.
445 base::StringPairs stats; 446 base::StringPairs stats;
446 disk_cache->GetStats(&stats); 447 disk_cache->GetStats(&stats);
447 for (size_t i = 0; i < stats.size(); ++i) { 448 for (size_t i = 0; i < stats.size(); ++i) {
448 stats_dict->SetStringWithoutPathExpansion( 449 stats_dict->SetStringWithoutPathExpansion(stats[i].first,
449 stats[i].first, stats[i].second); 450 stats[i].second);
450 } 451 }
451 } 452 }
452 info_dict->Set("stats", stats_dict); 453 info_dict->Set("stats", stats_dict);
453 454
454 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE), 455 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE), info_dict);
455 info_dict);
456 } 456 }
457 457
458 return net_info_dict.Pass(); 458 return net_info_dict.Pass();
459 } 459 }
460 460
461 } // namespace net 461 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698