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

Side by Side Diff: content/browser/loader/netlog_observer.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/loader/netlog_observer.h" 5 #include "content/browser/loader/netlog_observer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "content/browser/loader/resource_request_info_impl.h" 11 #include "content/browser/loader/resource_request_info_impl.h"
12 #include "content/public/common/resource_response.h" 12 #include "content/public/common/resource_response.h"
13 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
14 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
15 #include "net/http/http_util.h" 15 #include "net/http/http_util.h"
16 #include "net/log/net_log_event_type.h"
17 #include "net/log/net_log_source_type.h"
16 #include "net/spdy/spdy_header_block.h" 18 #include "net/spdy/spdy_header_block.h"
17 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_netlog_params.h" 20 #include "net/url_request/url_request_netlog_params.h"
19 21
20 namespace content { 22 namespace content {
21 const size_t kMaxNumEntries = 1000; 23 const size_t kMaxNumEntries = 1000;
22 24
23 // static 25 // static
24 NetLogObserver* NetLogObserver::instance_ = NULL; 26 NetLogObserver* NetLogObserver::instance_ = NULL;
25 27
(...skipping 12 matching lines...) Expand all
38 return NULL; 40 return NULL;
39 } 41 }
40 42
41 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { 43 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
42 DCHECK(io_thread_checker_.Get().get()); 44 DCHECK(io_thread_checker_.Get().get());
43 45
44 // The events that the Observer is interested in only occur on the IO thread. 46 // The events that the Observer is interested in only occur on the IO thread.
45 if (!io_thread_checker_.Get()->CalledOnValidThread()) 47 if (!io_thread_checker_.Get()->CalledOnValidThread())
46 return; 48 return;
47 49
48 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST) 50 if (entry.source().type == net::NetLogSourceType::URL_REQUEST)
49 OnAddURLRequestEntry(entry); 51 OnAddURLRequestEntry(entry);
50 } 52 }
51 53
52 void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) { 54 void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
53 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN; 55 bool is_begin = entry.phase() == net::NetLogEventPhase::BEGIN;
54 bool is_end = entry.phase() == net::NetLog::PHASE_END; 56 bool is_end = entry.phase() == net::NetLogEventPhase::END;
55 57
56 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) { 58 if (entry.type() == net::NetLogEventType::URL_REQUEST_START_JOB) {
57 if (is_begin) { 59 if (is_begin) {
58 if (request_to_info_.size() > kMaxNumEntries) { 60 if (request_to_info_.size() > kMaxNumEntries) {
59 LOG(WARNING) << "The raw headers observer url request count has grown " 61 LOG(WARNING) << "The raw headers observer url request count has grown "
60 "larger than expected, resetting"; 62 "larger than expected, resetting";
61 request_to_info_.clear(); 63 request_to_info_.clear();
62 } 64 }
63 65
64 request_to_info_[entry.source().id] = new ResourceInfo(); 66 request_to_info_[entry.source().id] = new ResourceInfo();
65 } 67 }
66 return; 68 return;
67 } else if (entry.type() == net::NetLog::TYPE_REQUEST_ALIVE) { 69 } else if (entry.type() == net::NetLogEventType::REQUEST_ALIVE) {
68 // Cleanup records based on the TYPE_REQUEST_ALIVE entry. 70 // Cleanup records based on the TYPE_REQUEST_ALIVE entry.
69 if (is_end) 71 if (is_end)
70 request_to_info_.erase(entry.source().id); 72 request_to_info_.erase(entry.source().id);
71 return; 73 return;
72 } 74 }
73 75
74 ResourceInfo* info = GetResourceInfo(entry.source().id); 76 ResourceInfo* info = GetResourceInfo(entry.source().id);
75 if (!info) 77 if (!info)
76 return; 78 return;
77 79
78 switch (entry.type()) { 80 switch (entry.type()) {
79 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS: { 81 case net::NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS: {
80 std::unique_ptr<base::Value> event_params(entry.ParametersToValue()); 82 std::unique_ptr<base::Value> event_params(entry.ParametersToValue());
81 std::string request_line; 83 std::string request_line;
82 net::HttpRequestHeaders request_headers; 84 net::HttpRequestHeaders request_headers;
83 85
84 if (!net::HttpRequestHeaders::FromNetLogParam( 86 if (!net::HttpRequestHeaders::FromNetLogParam(
85 event_params.get(), &request_headers, &request_line)) { 87 event_params.get(), &request_headers, &request_line)) {
86 NOTREACHED(); 88 NOTREACHED();
87 } 89 }
88 90
89 // We need to clear headers in case the same url_request is reused for 91 // We need to clear headers in case the same url_request is reused for
90 // several http requests (e.g. see http://crbug.com/80157). 92 // several http requests (e.g. see http://crbug.com/80157).
91 info->request_headers.clear(); 93 info->request_headers.clear();
92 94
93 for (net::HttpRequestHeaders::Iterator it(request_headers); 95 for (net::HttpRequestHeaders::Iterator it(request_headers);
94 it.GetNext();) { 96 it.GetNext();) {
95 info->request_headers.push_back(std::make_pair(it.name(), it.value())); 97 info->request_headers.push_back(std::make_pair(it.name(), it.value()));
96 } 98 }
97 info->request_headers_text = request_line + request_headers.ToString(); 99 info->request_headers_text = request_line + request_headers.ToString();
98 break; 100 break;
99 } 101 }
100 case net::NetLog::TYPE_HTTP_TRANSACTION_HTTP2_SEND_REQUEST_HEADERS: { 102 case net::NetLogEventType::HTTP_TRANSACTION_HTTP2_SEND_REQUEST_HEADERS: {
101 std::unique_ptr<base::Value> event_params(entry.ParametersToValue()); 103 std::unique_ptr<base::Value> event_params(entry.ParametersToValue());
102 net::SpdyHeaderBlock request_headers; 104 net::SpdyHeaderBlock request_headers;
103 105
104 if (!net::SpdyHeaderBlockFromNetLogParam(event_params.get(), 106 if (!net::SpdyHeaderBlockFromNetLogParam(event_params.get(),
105 &request_headers)) { 107 &request_headers)) {
106 NOTREACHED(); 108 NOTREACHED();
107 } 109 }
108 110
109 // We need to clear headers in case the same url_request is reused for 111 // We need to clear headers in case the same url_request is reused for
110 // several http requests (e.g. see http://crbug.com/80157). 112 // several http requests (e.g. see http://crbug.com/80157).
111 info->request_headers.clear(); 113 info->request_headers.clear();
112 114
113 for (net::SpdyHeaderBlock::const_iterator it = request_headers.begin(); 115 for (net::SpdyHeaderBlock::const_iterator it = request_headers.begin();
114 it != request_headers.end(); ++it) { 116 it != request_headers.end(); ++it) {
115 info->request_headers.push_back( 117 info->request_headers.push_back(
116 std::make_pair(it->first.as_string(), it->second.as_string())); 118 std::make_pair(it->first.as_string(), it->second.as_string()));
117 } 119 }
118 info->request_headers_text = ""; 120 info->request_headers_text = "";
119 break; 121 break;
120 } 122 }
121 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS: { 123 case net::NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS: {
122 std::unique_ptr<base::Value> event_params(entry.ParametersToValue()); 124 std::unique_ptr<base::Value> event_params(entry.ParametersToValue());
123 125
124 scoped_refptr<net::HttpResponseHeaders> response_headers; 126 scoped_refptr<net::HttpResponseHeaders> response_headers;
125 127
126 if (!net::HttpResponseHeaders::FromNetLogParam(event_params.get(), 128 if (!net::HttpResponseHeaders::FromNetLogParam(event_params.get(),
127 &response_headers)) { 129 &response_headers)) {
128 NOTREACHED(); 130 NOTREACHED();
129 } 131 }
130 132
131 info->http_status_code = response_headers->response_code(); 133 info->http_status_code = response_headers->response_code();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 200
199 uint32_t source_id = request->net_log().source().id; 201 uint32_t source_id = request->net_log().source().id;
200 NetLogObserver* dev_tools_net_log_observer = NetLogObserver::GetInstance(); 202 NetLogObserver* dev_tools_net_log_observer = NetLogObserver::GetInstance();
201 if (dev_tools_net_log_observer == NULL) 203 if (dev_tools_net_log_observer == NULL)
202 return; 204 return;
203 response->head.devtools_info = 205 response->head.devtools_info =
204 dev_tools_net_log_observer->GetResourceInfo(source_id); 206 dev_tools_net_log_observer->GetResourceInfo(source_id);
205 } 207 }
206 208
207 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/browser/media/media_internals_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698