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

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

Issue 754433003: Update from https://crrev.com/305340 (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
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 <algorithm>
7 #include <string> 8 #include <string>
9 #include <vector>
8 10
11 #include "base/bind.h"
12 #include "base/logging.h"
9 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/time/time.h"
13 #include "base/values.h" 18 #include "base/values.h"
14 #include "net/base/address_family.h" 19 #include "net/base/address_family.h"
15 #include "net/base/load_states.h" 20 #include "net/base/load_states.h"
16 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
17 #include "net/base/net_log.h" 22 #include "net/base/net_log.h"
18 #include "net/base/sdch_manager.h" 23 #include "net/base/sdch_manager.h"
19 #include "net/disk_cache/disk_cache.h" 24 #include "net/disk_cache/disk_cache.h"
20 #include "net/dns/host_cache.h" 25 #include "net/dns/host_cache.h"
21 #include "net/dns/host_resolver.h" 26 #include "net/dns/host_resolver.h"
22 #include "net/http/http_cache.h" 27 #include "net/http/http_cache.h"
23 #include "net/http/http_network_session.h" 28 #include "net/http/http_network_session.h"
24 #include "net/http/http_server_properties.h" 29 #include "net/http/http_server_properties.h"
25 #include "net/http/http_transaction_factory.h" 30 #include "net/http/http_transaction_factory.h"
26 #include "net/proxy/proxy_config.h" 31 #include "net/proxy/proxy_config.h"
27 #include "net/proxy/proxy_retry_info.h" 32 #include "net/proxy/proxy_retry_info.h"
28 #include "net/proxy/proxy_service.h" 33 #include "net/proxy/proxy_service.h"
29 #include "net/quic/quic_protocol.h" 34 #include "net/quic/quic_protocol.h"
30 #include "net/quic/quic_utils.h" 35 #include "net/quic/quic_utils.h"
36 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_context.h" 37 #include "net/url_request/url_request_context.h"
32 38
33 namespace net { 39 namespace net {
34 40
35 namespace { 41 namespace {
36 42
37 // This should be incremented when significant changes are made that will 43 // This should be incremented when significant changes are made that will
38 // invalidate the old loading code. 44 // invalidate the old loading code.
39 const int kLogFormatVersion = 1; 45 const int kLogFormatVersion = 1;
40 46
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!context->http_transaction_factory()) 100 if (!context->http_transaction_factory())
95 return NULL; 101 return NULL;
96 102
97 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache(); 103 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache();
98 if (!http_cache) 104 if (!http_cache)
99 return NULL; 105 return NULL;
100 106
101 return http_cache->GetCurrentBackend(); 107 return http_cache->GetCurrentBackend();
102 } 108 }
103 109
110 // Returns true if |request1| was created before |request2|.
111 bool RequestCreatedBefore(const net::URLRequest* request1,
112 const net::URLRequest* request2) {
113 if (request1->creation_time() < request2->creation_time())
114 return true;
115 if (request1->creation_time() > request2->creation_time())
116 return false;
117 // If requests were created at the same time, sort by ID. Mostly matters for
118 // testing purposes.
119 return request1->identifier() < request2->identifier();
120 }
121
122 // Returns a Value representing the state of a pre-existing URLRequest when
123 // net-internals was opened.
124 base::Value* GetRequestStateAsValue(const net::URLRequest* request,
125 net::NetLog::LogLevel log_level) {
126 return request->GetStateAsValue();
127 }
128
104 } // namespace 129 } // namespace
105 130
106 scoped_ptr<base::DictionaryValue> GetNetConstants() { 131 scoped_ptr<base::DictionaryValue> GetNetConstants() {
107 scoped_ptr<base::DictionaryValue> constants_dict(new base::DictionaryValue()); 132 scoped_ptr<base::DictionaryValue> constants_dict(new base::DictionaryValue());
108 133
109 // Version of the file format. 134 // Version of the file format.
110 constants_dict->SetInteger("logFormatVersion", kLogFormatVersion); 135 constants_dict->SetInteger("logFormatVersion", kLogFormatVersion);
111 136
112 // Add a dictionary with information on the relationship between event type 137 // Add a dictionary with information on the relationship between event type
113 // enums and their symbolic names. 138 // enums and their symbolic names.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 it->group_name); 316 it->group_name);
292 } 317 }
293 constants_dict->Set("activeFieldTrialGroups", field_trial_groups); 318 constants_dict->Set("activeFieldTrialGroups", field_trial_groups);
294 } 319 }
295 320
296 return constants_dict.Pass(); 321 return constants_dict.Pass();
297 } 322 }
298 323
299 NET_EXPORT scoped_ptr<base::DictionaryValue> GetNetInfo( 324 NET_EXPORT scoped_ptr<base::DictionaryValue> GetNetInfo(
300 URLRequestContext* context, int info_sources) { 325 URLRequestContext* context, int info_sources) {
326 // May only be called on the context's thread.
327 DCHECK(context->CalledOnValidThread());
328
301 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue()); 329 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue());
302 330
303 // TODO(mmenke): The code for most of these sources should probably be moved 331 // TODO(mmenke): The code for most of these sources should probably be moved
304 // into the sources themselves. 332 // into the sources themselves.
305 if (info_sources & NET_INFO_PROXY_SETTINGS) { 333 if (info_sources & NET_INFO_PROXY_SETTINGS) {
306 net::ProxyService* proxy_service = context->proxy_service(); 334 net::ProxyService* proxy_service = context->proxy_service();
307 335
308 base::DictionaryValue* dict = new base::DictionaryValue(); 336 base::DictionaryValue* dict = new base::DictionaryValue();
309 if (proxy_service->fetched_config().is_valid()) 337 if (proxy_service->fetched_config().is_valid())
310 dict->Set("original", proxy_service->fetched_config().ToValue()); 338 dict->Set("original", proxy_service->fetched_config().ToValue());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 info_dict = sdch_manager->SdchInfoToValue(); 510 info_dict = sdch_manager->SdchInfoToValue();
483 } else { 511 } else {
484 info_dict = new base::DictionaryValue(); 512 info_dict = new base::DictionaryValue();
485 } 513 }
486 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SDCH), info_dict); 514 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SDCH), info_dict);
487 } 515 }
488 516
489 return net_info_dict.Pass(); 517 return net_info_dict.Pass();
490 } 518 }
491 519
520 NET_EXPORT void CreateNetLogEntriesForActiveObjects(
521 const std::set<URLRequestContext*>& contexts,
522 NetLog::ThreadSafeObserver* observer) {
523 // Not safe to call this when the observer is watching a NetLog.
524 DCHECK(!observer->net_log());
525
526 // Put together the list of all requests.
527 std::vector<const URLRequest*> requests;
528 for (const auto& context : contexts) {
529 // May only be called on the context's thread.
530 DCHECK(context->CalledOnValidThread());
531 // Contexts should all be using the same NetLog.
532 DCHECK_EQ((*contexts.begin())->net_log(), context->net_log());
533 for (const auto& request : *context->url_requests()) {
534 requests.push_back(request);
535 }
536 }
537
538 // Sort by creation time.
539 std::sort(requests.begin(), requests.end(), RequestCreatedBefore);
540
541 // Create fake events.
542 ScopedVector<NetLog::Entry> entries;
543 for (const auto& request : requests) {
544 net::NetLog::ParametersCallback callback =
545 base::Bind(&GetRequestStateAsValue, base::Unretained(request));
546
547 net::NetLog::EntryData entry_data(net::NetLog::TYPE_REQUEST_ALIVE,
548 request->net_log().source(),
549 net::NetLog::PHASE_BEGIN,
550 request->creation_time(),
551 &callback);
552 NetLog::Entry entry(&entry_data, request->net_log().GetLogLevel());
553 observer->OnAddEntry(entry);
554 }
555 }
556
492 } // namespace net 557 } // 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