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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return true; | 121 return true; |
122 if (request1->creation_time() > request2->creation_time()) | 122 if (request1->creation_time() > request2->creation_time()) |
123 return false; | 123 return false; |
124 // If requests were created at the same time, sort by ID. Mostly matters for | 124 // If requests were created at the same time, sort by ID. Mostly matters for |
125 // testing purposes. | 125 // testing purposes. |
126 return request1->identifier() < request2->identifier(); | 126 return request1->identifier() < request2->identifier(); |
127 } | 127 } |
128 | 128 |
129 // Returns a Value representing the state of a pre-existing URLRequest when | 129 // Returns a Value representing the state of a pre-existing URLRequest when |
130 // net-internals was opened. | 130 // net-internals was opened. |
131 base::Value* GetRequestStateAsValue(const net::URLRequest* request, | 131 scoped_ptr<base::Value> GetRequestStateAsValue(const net::URLRequest* request, |
132 NetLogCaptureMode capture_mode) { | 132 NetLogCaptureMode capture_mode) { |
133 return request->GetStateAsValue().release(); | 133 return request->GetStateAsValue().Pass(); |
134 } | 134 } |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 | 137 |
138 scoped_ptr<base::DictionaryValue> GetNetConstants() { | 138 scoped_ptr<base::DictionaryValue> GetNetConstants() { |
139 scoped_ptr<base::DictionaryValue> constants_dict(new base::DictionaryValue()); | 139 scoped_ptr<base::DictionaryValue> constants_dict(new base::DictionaryValue()); |
140 | 140 |
141 // Version of the file format. | 141 // Version of the file format. |
142 constants_dict->SetInteger("logFormatVersion", kLogFormatVersion); | 142 constants_dict->SetInteger("logFormatVersion", kLogFormatVersion); |
143 | 143 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // May only be called on the context's thread. | 321 // May only be called on the context's thread. |
322 DCHECK(context->CalledOnValidThread()); | 322 DCHECK(context->CalledOnValidThread()); |
323 | 323 |
324 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue()); | 324 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue()); |
325 | 325 |
326 // TODO(mmenke): The code for most of these sources should probably be moved | 326 // TODO(mmenke): The code for most of these sources should probably be moved |
327 // into the sources themselves. | 327 // into the sources themselves. |
328 if (info_sources & NET_INFO_PROXY_SETTINGS) { | 328 if (info_sources & NET_INFO_PROXY_SETTINGS) { |
329 ProxyService* proxy_service = context->proxy_service(); | 329 ProxyService* proxy_service = context->proxy_service(); |
330 | 330 |
331 base::DictionaryValue* dict = new base::DictionaryValue(); | 331 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
332 if (proxy_service->fetched_config().is_valid()) | 332 if (proxy_service->fetched_config().is_valid()) |
333 dict->Set("original", proxy_service->fetched_config().ToValue()); | 333 dict->Set("original", proxy_service->fetched_config().ToValue()); |
334 if (proxy_service->config().is_valid()) | 334 if (proxy_service->config().is_valid()) |
335 dict->Set("effective", proxy_service->config().ToValue()); | 335 dict->Set("effective", proxy_service->config().ToValue()); |
336 | 336 |
337 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), dict); | 337 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), |
| 338 dict.get()); |
338 } | 339 } |
339 | 340 |
340 if (info_sources & NET_INFO_BAD_PROXIES) { | 341 if (info_sources & NET_INFO_BAD_PROXIES) { |
341 const ProxyRetryInfoMap& bad_proxies_map = | 342 const ProxyRetryInfoMap& bad_proxies_map = |
342 context->proxy_service()->proxy_retry_info(); | 343 context->proxy_service()->proxy_retry_info(); |
343 | 344 |
344 base::ListValue* list = new base::ListValue(); | 345 scoped_ptr<base::ListValue> list(new base::ListValue()); |
345 | 346 |
346 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); | 347 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); |
347 it != bad_proxies_map.end(); ++it) { | 348 it != bad_proxies_map.end(); ++it) { |
348 const std::string& proxy_uri = it->first; | 349 const std::string& proxy_uri = it->first; |
349 const ProxyRetryInfo& retry_info = it->second; | 350 const ProxyRetryInfo& retry_info = it->second; |
350 | 351 |
351 base::DictionaryValue* dict = new base::DictionaryValue(); | 352 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
352 dict->SetString("proxy_uri", proxy_uri); | 353 dict->SetString("proxy_uri", proxy_uri); |
353 dict->SetString("bad_until", | 354 dict->SetString("bad_until", |
354 NetLog::TickCountToString(retry_info.bad_until)); | 355 NetLog::TickCountToString(retry_info.bad_until)); |
355 | 356 |
356 list->Append(dict); | 357 list->Append(dict.Pass()); |
357 } | 358 } |
358 | 359 |
359 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), list); | 360 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), |
| 361 list.Pass()); |
360 } | 362 } |
361 | 363 |
362 if (info_sources & NET_INFO_HOST_RESOLVER) { | 364 if (info_sources & NET_INFO_HOST_RESOLVER) { |
363 HostResolver* host_resolver = context->host_resolver(); | 365 HostResolver* host_resolver = context->host_resolver(); |
364 DCHECK(host_resolver); | 366 DCHECK(host_resolver); |
365 HostCache* cache = host_resolver->GetHostCache(); | 367 HostCache* cache = host_resolver->GetHostCache(); |
366 if (cache) { | 368 if (cache) { |
367 base::DictionaryValue* dict = new base::DictionaryValue(); | 369 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
368 base::Value* dns_config = host_resolver->GetDnsConfigAsValue(); | 370 scoped_ptr<base::Value> dns_config(host_resolver->GetDnsConfigAsValue()); |
369 if (dns_config) | 371 if (dns_config) |
370 dict->Set("dns_config", dns_config); | 372 dict->Set("dns_config", dns_config.Pass()); |
371 | 373 |
372 dict->SetInteger( | 374 dict->SetInteger( |
373 "default_address_family", | 375 "default_address_family", |
374 static_cast<int>(host_resolver->GetDefaultAddressFamily())); | 376 static_cast<int>(host_resolver->GetDefaultAddressFamily())); |
375 | 377 |
376 base::DictionaryValue* cache_info_dict = new base::DictionaryValue(); | 378 base::DictionaryValue* cache_info_dict = new base::DictionaryValue(); |
377 | 379 |
378 cache_info_dict->SetInteger("capacity", | 380 cache_info_dict->SetInteger("capacity", |
379 static_cast<int>(cache->max_entries())); | 381 static_cast<int>(cache->max_entries())); |
380 | 382 |
381 base::ListValue* entry_list = new base::ListValue(); | 383 scoped_ptr<base::ListValue> entry_list(new base::ListValue()); |
382 | 384 |
383 HostCache::EntryMap::Iterator it(cache->entries()); | 385 HostCache::EntryMap::Iterator it(cache->entries()); |
384 for (; it.HasNext(); it.Advance()) { | 386 for (; it.HasNext(); it.Advance()) { |
385 const HostCache::Key& key = it.key(); | 387 const HostCache::Key& key = it.key(); |
386 const HostCache::Entry& entry = it.value(); | 388 const HostCache::Entry& entry = it.value(); |
387 | 389 |
388 base::DictionaryValue* entry_dict = new base::DictionaryValue(); | 390 scoped_ptr<base::DictionaryValue> entry_dict( |
| 391 new base::DictionaryValue()); |
389 | 392 |
390 entry_dict->SetString("hostname", key.hostname); | 393 entry_dict->SetString("hostname", key.hostname); |
391 entry_dict->SetInteger("address_family", | 394 entry_dict->SetInteger("address_family", |
392 static_cast<int>(key.address_family)); | 395 static_cast<int>(key.address_family)); |
393 entry_dict->SetString("expiration", | 396 entry_dict->SetString("expiration", |
394 NetLog::TickCountToString(it.expiration())); | 397 NetLog::TickCountToString(it.expiration())); |
395 | 398 |
396 if (entry.error != OK) { | 399 if (entry.error != OK) { |
397 entry_dict->SetInteger("error", entry.error); | 400 entry_dict->SetInteger("error", entry.error); |
398 } else { | 401 } else { |
399 // Append all of the resolved addresses. | 402 // Append all of the resolved addresses. |
400 base::ListValue* address_list = new base::ListValue(); | 403 scoped_ptr<base::ListValue> address_list(new base::ListValue()); |
401 for (size_t i = 0; i < entry.addrlist.size(); ++i) { | 404 for (size_t i = 0; i < entry.addrlist.size(); ++i) { |
402 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort()); | 405 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort()); |
403 } | 406 } |
404 entry_dict->Set("addresses", address_list); | 407 entry_dict->Set("addresses", address_list.Pass()); |
405 } | 408 } |
406 | 409 |
407 entry_list->Append(entry_dict); | 410 entry_list->Append(entry_dict.Pass()); |
408 } | 411 } |
409 | 412 |
410 cache_info_dict->Set("entries", entry_list); | 413 cache_info_dict->Set("entries", entry_list.Pass()); |
411 dict->Set("cache", cache_info_dict); | 414 dict->Set("cache", cache_info_dict); |
412 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), dict); | 415 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), |
| 416 dict.get()); |
413 } | 417 } |
414 } | 418 } |
415 | 419 |
416 HttpNetworkSession* http_network_session = | 420 HttpNetworkSession* http_network_session = |
417 context->http_transaction_factory()->GetSession(); | 421 context->http_transaction_factory()->GetSession(); |
418 | 422 |
419 if (info_sources & NET_INFO_SOCKET_POOL) { | 423 if (info_sources & NET_INFO_SOCKET_POOL) { |
420 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), | 424 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), |
421 http_network_session->SocketPoolInfoToValue()); | 425 http_network_session->SocketPoolInfoToValue()); |
422 } | 426 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } | 516 } |
513 } | 517 } |
514 | 518 |
515 // Sort by creation time. | 519 // Sort by creation time. |
516 std::sort(requests.begin(), requests.end(), RequestCreatedBefore); | 520 std::sort(requests.begin(), requests.end(), RequestCreatedBefore); |
517 | 521 |
518 // Create fake events. | 522 // Create fake events. |
519 ScopedVector<NetLog::Entry> entries; | 523 ScopedVector<NetLog::Entry> entries; |
520 for (const auto& request : requests) { | 524 for (const auto& request : requests) { |
521 NetLog::ParametersCallback callback = | 525 NetLog::ParametersCallback callback = |
522 base::Bind(&GetRequestStateAsValue, base::Unretained(request)); | 526 base::Bind(GetRequestStateAsValue, base::Unretained(request)); |
523 | 527 |
524 // Note that passing the hardcoded NetLogCaptureMode::Default() below is | 528 // Note that passing the hardcoded NetLogCaptureMode::Default() below is |
525 // fine, since GetRequestStateAsValue() ignores the capture mode. | 529 // fine, since GetRequestStateAsValue() ignores the capture mode. |
526 NetLog::EntryData entry_data( | 530 NetLog::EntryData entry_data( |
527 NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(), | 531 NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(), |
528 NetLog::PHASE_BEGIN, request->creation_time(), &callback); | 532 NetLog::PHASE_BEGIN, request->creation_time(), &callback); |
529 NetLog::Entry entry(&entry_data, NetLogCaptureMode::Default()); | 533 NetLog::Entry entry(&entry_data, NetLogCaptureMode::Default()); |
530 observer->OnAddEntry(entry); | 534 observer->OnAddEntry(entry); |
531 } | 535 } |
532 } | 536 } |
533 | 537 |
534 } // namespace net | 538 } // namespace net |
OLD | NEW |