OLD | NEW |
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/log/net_log_util.h" | 5 #include "net/log/net_log_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "net/base/address_family.h" | 21 #include "net/base/address_family.h" |
21 #include "net/base/load_states.h" | 22 #include "net/base/load_states.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
23 #include "net/base/sdch_manager.h" | 24 #include "net/base/sdch_manager.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 constants_dict->Set("logEventPhase", std::move(dict)); | 258 constants_dict->Set("logEventPhase", std::move(dict)); |
258 } | 259 } |
259 | 260 |
260 // Information about the relationship between source type enums and | 261 // Information about the relationship between source type enums and |
261 // their symbolic names. | 262 // their symbolic names. |
262 constants_dict->Set("logSourceType", NetLog::GetSourceTypesAsValue()); | 263 constants_dict->Set("logSourceType", NetLog::GetSourceTypesAsValue()); |
263 | 264 |
264 // TODO(eroman): This is here for compatibility in loading new log files with | 265 // TODO(eroman): This is here for compatibility in loading new log files with |
265 // older builds of Chrome. Safe to remove this once M45 is on the stable | 266 // older builds of Chrome. Safe to remove this once M45 is on the stable |
266 // channel. | 267 // channel. |
267 constants_dict->Set("logLevelType", new base::DictionaryValue()); | 268 constants_dict->Set("logLevelType", |
| 269 base::MakeUnique<base::DictionaryValue>()); |
268 | 270 |
269 // Information about the relationship between address family enums and | 271 // Information about the relationship between address family enums and |
270 // their symbolic names. | 272 // their symbolic names. |
271 { | 273 { |
272 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 274 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
273 | 275 |
274 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED); | 276 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED); |
275 dict->SetInteger("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4); | 277 dict->SetInteger("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4); |
276 dict->SetInteger("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6); | 278 dict->SetInteger("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6); |
277 | 279 |
(...skipping 18 matching lines...) Expand all Loading... |
296 int64_t tick_to_unix_time_ms = | 298 int64_t tick_to_unix_time_ms = |
297 (time_since_epoch - reference_time_ticks).InMilliseconds(); | 299 (time_since_epoch - reference_time_ticks).InMilliseconds(); |
298 | 300 |
299 // Pass it as a string, since it may be too large to fit in an integer. | 301 // Pass it as a string, since it may be too large to fit in an integer. |
300 constants_dict->SetString("timeTickOffset", | 302 constants_dict->SetString("timeTickOffset", |
301 base::Int64ToString(tick_to_unix_time_ms)); | 303 base::Int64ToString(tick_to_unix_time_ms)); |
302 } | 304 } |
303 | 305 |
304 // "clientInfo" key is required for some WriteToFileNetLogObserver log | 306 // "clientInfo" key is required for some WriteToFileNetLogObserver log |
305 // readers. Provide a default empty value for compatibility. | 307 // readers. Provide a default empty value for compatibility. |
306 constants_dict->Set("clientInfo", new base::DictionaryValue()); | 308 constants_dict->Set("clientInfo", base::MakeUnique<base::DictionaryValue>()); |
307 | 309 |
308 // Add a list of active field experiments. | 310 // Add a list of active field experiments. |
309 { | 311 { |
310 base::FieldTrial::ActiveGroups active_groups; | 312 base::FieldTrial::ActiveGroups active_groups; |
311 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | 313 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); |
312 base::ListValue* field_trial_groups = new base::ListValue(); | 314 auto field_trial_groups = base::MakeUnique<base::ListValue>(); |
313 for (base::FieldTrial::ActiveGroups::const_iterator it = | 315 for (base::FieldTrial::ActiveGroups::const_iterator it = |
314 active_groups.begin(); | 316 active_groups.begin(); |
315 it != active_groups.end(); ++it) { | 317 it != active_groups.end(); ++it) { |
316 field_trial_groups->AppendString(it->trial_name + ":" + it->group_name); | 318 field_trial_groups->AppendString(it->trial_name + ":" + it->group_name); |
317 } | 319 } |
318 constants_dict->Set("activeFieldTrialGroups", field_trial_groups); | 320 constants_dict->Set("activeFieldTrialGroups", |
| 321 std::move(field_trial_groups)); |
319 } | 322 } |
320 | 323 |
321 return constants_dict; | 324 return constants_dict; |
322 } | 325 } |
323 | 326 |
324 NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo( | 327 NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo( |
325 URLRequestContext* context, | 328 URLRequestContext* context, |
326 int info_sources) { | 329 int info_sources) { |
327 // May only be called on the context's thread. | 330 // May only be called on the context's thread. |
328 DCHECK(context->CalledOnValidThread()); | 331 DCHECK(context->CalledOnValidThread()); |
(...skipping 13 matching lines...) Expand all Loading... |
342 dict->Set("effective", proxy_service->config().ToValue()); | 345 dict->Set("effective", proxy_service->config().ToValue()); |
343 | 346 |
344 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), | 347 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), |
345 std::move(dict)); | 348 std::move(dict)); |
346 } | 349 } |
347 | 350 |
348 if (info_sources & NET_INFO_BAD_PROXIES) { | 351 if (info_sources & NET_INFO_BAD_PROXIES) { |
349 const ProxyRetryInfoMap& bad_proxies_map = | 352 const ProxyRetryInfoMap& bad_proxies_map = |
350 context->proxy_service()->proxy_retry_info(); | 353 context->proxy_service()->proxy_retry_info(); |
351 | 354 |
352 base::ListValue* list = new base::ListValue(); | 355 auto list = base::MakeUnique<base::ListValue>(); |
353 | 356 |
354 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); | 357 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); |
355 it != bad_proxies_map.end(); ++it) { | 358 it != bad_proxies_map.end(); ++it) { |
356 const std::string& proxy_uri = it->first; | 359 const std::string& proxy_uri = it->first; |
357 const ProxyRetryInfo& retry_info = it->second; | 360 const ProxyRetryInfo& retry_info = it->second; |
358 | 361 |
359 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 362 auto dict = base::MakeUnique<base::DictionaryValue>(); |
360 dict->SetString("proxy_uri", proxy_uri); | 363 dict->SetString("proxy_uri", proxy_uri); |
361 dict->SetString("bad_until", | 364 dict->SetString("bad_until", |
362 NetLog::TickCountToString(retry_info.bad_until)); | 365 NetLog::TickCountToString(retry_info.bad_until)); |
363 | 366 |
364 list->Append(std::move(dict)); | 367 list->Append(std::move(dict)); |
365 } | 368 } |
366 | 369 |
367 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), list); | 370 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), |
| 371 std::move(list)); |
368 } | 372 } |
369 | 373 |
370 if (info_sources & NET_INFO_HOST_RESOLVER) { | 374 if (info_sources & NET_INFO_HOST_RESOLVER) { |
371 HostResolver* host_resolver = context->host_resolver(); | 375 HostResolver* host_resolver = context->host_resolver(); |
372 DCHECK(host_resolver); | 376 DCHECK(host_resolver); |
373 HostCache* cache = host_resolver->GetHostCache(); | 377 HostCache* cache = host_resolver->GetHostCache(); |
374 if (cache) { | 378 if (cache) { |
375 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 379 auto dict = base::MakeUnique<base::DictionaryValue>(); |
376 std::unique_ptr<base::Value> dns_config = | 380 std::unique_ptr<base::Value> dns_config = |
377 host_resolver->GetDnsConfigAsValue(); | 381 host_resolver->GetDnsConfigAsValue(); |
378 if (dns_config) | 382 if (dns_config) |
379 dict->Set("dns_config", std::move(dns_config)); | 383 dict->Set("dns_config", std::move(dns_config)); |
380 | 384 |
381 base::DictionaryValue* cache_info_dict = new base::DictionaryValue(); | 385 auto cache_info_dict = base::MakeUnique<base::DictionaryValue>(); |
382 | 386 |
383 cache_info_dict->SetInteger("capacity", | 387 cache_info_dict->SetInteger("capacity", |
384 static_cast<int>(cache->max_entries())); | 388 static_cast<int>(cache->max_entries())); |
385 cache_info_dict->SetInteger("network_changes", cache->network_changes()); | 389 cache_info_dict->SetInteger("network_changes", cache->network_changes()); |
386 | 390 |
387 cache_info_dict->Set("entries", | 391 cache_info_dict->Set("entries", |
388 cache->GetAsListValue(/*include_staleness=*/true)); | 392 cache->GetAsListValue(/*include_staleness=*/true)); |
389 dict->Set("cache", cache_info_dict); | 393 dict->Set("cache", std::move(cache_info_dict)); |
390 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), | 394 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), |
391 std::move(dict)); | 395 std::move(dict)); |
392 } | 396 } |
393 } | 397 } |
394 | 398 |
395 HttpNetworkSession* http_network_session = | 399 HttpNetworkSession* http_network_session = |
396 context->http_transaction_factory()->GetSession(); | 400 context->http_transaction_factory()->GetSession(); |
397 | 401 |
398 if (info_sources & NET_INFO_SOCKET_POOL) { | 402 if (info_sources & NET_INFO_SOCKET_POOL) { |
399 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), | 403 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), |
400 http_network_session->SocketPoolInfoToValue()); | 404 http_network_session->SocketPoolInfoToValue()); |
401 } | 405 } |
402 | 406 |
403 if (info_sources & NET_INFO_SPDY_SESSIONS) { | 407 if (info_sources & NET_INFO_SPDY_SESSIONS) { |
404 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS), | 408 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS), |
405 http_network_session->SpdySessionPoolInfoToValue()); | 409 http_network_session->SpdySessionPoolInfoToValue()); |
406 } | 410 } |
407 | 411 |
408 if (info_sources & NET_INFO_SPDY_STATUS) { | 412 if (info_sources & NET_INFO_SPDY_STATUS) { |
409 base::DictionaryValue* status_dict = new base::DictionaryValue(); | 413 auto status_dict = base::MakeUnique<base::DictionaryValue>(); |
410 | 414 |
411 status_dict->SetBoolean("enable_http2", | 415 status_dict->SetBoolean("enable_http2", |
412 http_network_session->params().enable_http2); | 416 http_network_session->params().enable_http2); |
413 | 417 |
414 NextProtoVector alpn_protos; | 418 NextProtoVector alpn_protos; |
415 http_network_session->GetAlpnProtos(&alpn_protos); | 419 http_network_session->GetAlpnProtos(&alpn_protos); |
416 if (!alpn_protos.empty()) { | 420 if (!alpn_protos.empty()) { |
417 std::string next_protos_string; | 421 std::string next_protos_string; |
418 for (NextProto proto : alpn_protos) { | 422 for (NextProto proto : alpn_protos) { |
419 if (!next_protos_string.empty()) | 423 if (!next_protos_string.empty()) |
420 next_protos_string.append(","); | 424 next_protos_string.append(","); |
421 next_protos_string.append(NextProtoToString(proto)); | 425 next_protos_string.append(NextProtoToString(proto)); |
422 } | 426 } |
423 status_dict->SetString("alpn_protos", next_protos_string); | 427 status_dict->SetString("alpn_protos", next_protos_string); |
424 } | 428 } |
425 | 429 |
426 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS), | 430 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS), |
427 status_dict); | 431 std::move(status_dict)); |
428 } | 432 } |
429 | 433 |
430 if (info_sources & NET_INFO_ALT_SVC_MAPPINGS) { | 434 if (info_sources & NET_INFO_ALT_SVC_MAPPINGS) { |
431 const HttpServerProperties& http_server_properties = | 435 const HttpServerProperties& http_server_properties = |
432 *context->http_server_properties(); | 436 *context->http_server_properties(); |
433 net_info_dict->Set( | 437 net_info_dict->Set( |
434 NetInfoSourceToString(NET_INFO_ALT_SVC_MAPPINGS), | 438 NetInfoSourceToString(NET_INFO_ALT_SVC_MAPPINGS), |
435 http_server_properties.GetAlternativeServiceInfoAsValue()); | 439 http_server_properties.GetAlternativeServiceInfoAsValue()); |
436 } | 440 } |
437 | 441 |
438 if (info_sources & NET_INFO_QUIC) { | 442 if (info_sources & NET_INFO_QUIC) { |
439 net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC), | 443 net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC), |
440 http_network_session->QuicInfoToValue()); | 444 http_network_session->QuicInfoToValue()); |
441 } | 445 } |
442 | 446 |
443 if (info_sources & NET_INFO_HTTP_CACHE) { | 447 if (info_sources & NET_INFO_HTTP_CACHE) { |
444 base::DictionaryValue* info_dict = new base::DictionaryValue(); | 448 auto info_dict = base::MakeUnique<base::DictionaryValue>(); |
445 base::DictionaryValue* stats_dict = new base::DictionaryValue(); | 449 auto stats_dict = base::MakeUnique<base::DictionaryValue>(); |
446 | 450 |
447 disk_cache::Backend* disk_cache = GetDiskCacheBackend(context); | 451 disk_cache::Backend* disk_cache = GetDiskCacheBackend(context); |
448 | 452 |
449 if (disk_cache) { | 453 if (disk_cache) { |
450 // Extract the statistics key/value pairs from the backend. | 454 // Extract the statistics key/value pairs from the backend. |
451 base::StringPairs stats; | 455 base::StringPairs stats; |
452 disk_cache->GetStats(&stats); | 456 disk_cache->GetStats(&stats); |
453 for (size_t i = 0; i < stats.size(); ++i) { | 457 for (size_t i = 0; i < stats.size(); ++i) { |
454 stats_dict->SetStringWithoutPathExpansion(stats[i].first, | 458 stats_dict->SetStringWithoutPathExpansion(stats[i].first, |
455 stats[i].second); | 459 stats[i].second); |
456 } | 460 } |
457 } | 461 } |
458 info_dict->Set("stats", stats_dict); | 462 info_dict->Set("stats", std::move(stats_dict)); |
459 | 463 |
460 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE), info_dict); | 464 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE), |
| 465 std::move(info_dict)); |
461 } | 466 } |
462 | 467 |
463 if (info_sources & NET_INFO_SDCH) { | 468 if (info_sources & NET_INFO_SDCH) { |
464 std::unique_ptr<base::Value> info_dict; | 469 std::unique_ptr<base::Value> info_dict; |
465 SdchManager* sdch_manager = context->sdch_manager(); | 470 SdchManager* sdch_manager = context->sdch_manager(); |
466 if (sdch_manager) { | 471 if (sdch_manager) { |
467 info_dict = sdch_manager->SdchInfoToValue(); | 472 info_dict = sdch_manager->SdchInfoToValue(); |
468 } else { | 473 } else { |
469 info_dict.reset(new base::DictionaryValue()); | 474 info_dict.reset(new base::DictionaryValue()); |
470 } | 475 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // fine, since GetRequestStateAsValue() ignores the capture mode. | 507 // fine, since GetRequestStateAsValue() ignores the capture mode. |
503 NetLogEntryData entry_data( | 508 NetLogEntryData entry_data( |
504 NetLogEventType::REQUEST_ALIVE, request->net_log().source(), | 509 NetLogEventType::REQUEST_ALIVE, request->net_log().source(), |
505 NetLogEventPhase::BEGIN, request->creation_time(), &callback); | 510 NetLogEventPhase::BEGIN, request->creation_time(), &callback); |
506 NetLogEntry entry(&entry_data, NetLogCaptureMode::Default()); | 511 NetLogEntry entry(&entry_data, NetLogCaptureMode::Default()); |
507 observer->OnAddEntry(entry); | 512 observer->OnAddEntry(entry); |
508 } | 513 } |
509 } | 514 } |
510 | 515 |
511 } // namespace net | 516 } // namespace net |
OLD | NEW |