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

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

Issue 1953593002: Move DevToolsNetLogObserver to c/b/loader and create stub of network service interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 4 years, 7 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/devtools/devtools_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/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/content_browser_client.h" 13 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/common/resource_response.h" 14 #include "content/public/common/resource_response.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
18 #include "net/spdy/spdy_header_block.h" 18 #include "net/spdy/spdy_header_block.h"
19 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_netlog_params.h" 20 #include "net/url_request/url_request_netlog_params.h"
21 21
22 namespace content { 22 namespace content {
23 const size_t kMaxNumEntries = 1000; 23 const size_t kMaxNumEntries = 1000;
24 24
25 DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; 25 NetLogObserver* NetLogObserver::instance_ = NULL;
26 26
27 DevToolsNetLogObserver::DevToolsNetLogObserver() { 27 NetLogObserver::NetLogObserver() {}
28 }
29 28
30 DevToolsNetLogObserver::~DevToolsNetLogObserver() { 29 NetLogObserver::~NetLogObserver() {}
31 }
32 30
33 DevToolsNetLogObserver::ResourceInfo* DevToolsNetLogObserver::GetResourceInfo( 31 NetLogObserver::ResourceInfo* NetLogObserver::GetResourceInfo(uint32_t id) {
34 uint32_t id) {
35 RequestToInfoMap::iterator it = request_to_info_.find(id); 32 RequestToInfoMap::iterator it = request_to_info_.find(id);
36 if (it != request_to_info_.end()) 33 if (it != request_to_info_.end())
37 return it->second.get(); 34 return it->second.get();
38 return NULL; 35 return NULL;
39 } 36 }
40 37
41 void DevToolsNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { 38 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
42 // The events that the Observer is interested in only occur on the IO thread. 39 // The events that the Observer is interested in only occur on the IO thread.
43 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) 40 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
44 return; 41 return;
45 42
46 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST) 43 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST)
47 OnAddURLRequestEntry(entry); 44 OnAddURLRequestEntry(entry);
48 } 45 }
49 46
50 void DevToolsNetLogObserver::OnAddURLRequestEntry( 47 void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
51 const net::NetLog::Entry& entry) {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO); 48 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 49
54 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN; 50 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
55 bool is_end = entry.phase() == net::NetLog::PHASE_END; 51 bool is_end = entry.phase() == net::NetLog::PHASE_END;
56 52
57 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) { 53 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
58 if (is_begin) { 54 if (is_begin) {
59 if (request_to_info_.size() > kMaxNumEntries) { 55 if (request_to_info_.size() > kMaxNumEntries) {
60 LOG(WARNING) << "The raw headers observer url request count has grown " 56 LOG(WARNING) << "The raw headers observer url request count has grown "
61 "larger than expected, resetting"; 57 "larger than expected, resetting";
(...skipping 13 matching lines...) Expand all
75 ResourceInfo* info = GetResourceInfo(entry.source().id); 71 ResourceInfo* info = GetResourceInfo(entry.source().id);
76 if (!info) 72 if (!info)
77 return; 73 return;
78 74
79 switch (entry.type()) { 75 switch (entry.type()) {
80 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS: { 76 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS: {
81 std::unique_ptr<base::Value> event_params(entry.ParametersToValue()); 77 std::unique_ptr<base::Value> event_params(entry.ParametersToValue());
82 std::string request_line; 78 std::string request_line;
83 net::HttpRequestHeaders request_headers; 79 net::HttpRequestHeaders request_headers;
84 80
85 if (!net::HttpRequestHeaders::FromNetLogParam(event_params.get(), 81 if (!net::HttpRequestHeaders::FromNetLogParam(
86 &request_headers, 82 event_params.get(), &request_headers, &request_line)) {
87 &request_line)) {
88 NOTREACHED(); 83 NOTREACHED();
89 } 84 }
90 85
91 // We need to clear headers in case the same url_request is reused for 86 // We need to clear headers in case the same url_request is reused for
92 // several http requests (e.g. see http://crbug.com/80157). 87 // several http requests (e.g. see http://crbug.com/80157).
93 info->request_headers.clear(); 88 info->request_headers.clear();
94 89
95 for (net::HttpRequestHeaders::Iterator it(request_headers); 90 for (net::HttpRequestHeaders::Iterator it(request_headers);
96 it.GetNext();) { 91 it.GetNext();) {
97 info->request_headers.push_back(std::make_pair(it.name(), it.value())); 92 info->request_headers.push_back(std::make_pair(it.name(), it.value()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // SPDY request. 146 // SPDY request.
152 info->response_headers_text = ""; 147 info->response_headers_text = "";
153 } 148 }
154 break; 149 break;
155 } 150 }
156 default: 151 default:
157 break; 152 break;
158 } 153 }
159 } 154 }
160 155
161 void DevToolsNetLogObserver::Attach() { 156 void NetLogObserver::Attach() {
162 DCHECK(!instance_); 157 DCHECK(!instance_);
163 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog(); 158 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog();
164 if (net_log) { 159 if (net_log) {
165 instance_ = new DevToolsNetLogObserver(); 160 instance_ = new NetLogObserver();
166 net_log->DeprecatedAddObserver( 161 net_log->DeprecatedAddObserver(
167 instance_, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); 162 instance_, net::NetLogCaptureMode::IncludeCookiesAndCredentials());
168 } 163 }
169 } 164 }
170 165
171 void DevToolsNetLogObserver::Detach() { 166 void NetLogObserver::Detach() {
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); 167 DCHECK_CURRENTLY_ON(BrowserThread::IO);
173 168
174 if (instance_) { 169 if (instance_) {
175 // Safest not to do this in the destructor to maintain thread safety across 170 // Safest not to do this in the destructor to maintain thread safety across
176 // refactorings. 171 // refactorings.
177 instance_->net_log()->DeprecatedRemoveObserver(instance_); 172 instance_->net_log()->DeprecatedRemoveObserver(instance_);
178 delete instance_; 173 delete instance_;
179 instance_ = NULL; 174 instance_ = NULL;
180 } 175 }
181 } 176 }
182 177
183 DevToolsNetLogObserver* DevToolsNetLogObserver::GetInstance() { 178 NetLogObserver* NetLogObserver::GetInstance() {
184 DCHECK_CURRENTLY_ON(BrowserThread::IO); 179 DCHECK_CURRENTLY_ON(BrowserThread::IO);
185 180
186 return instance_; 181 return instance_;
187 } 182 }
188 183
189 // static 184 // static
190 void DevToolsNetLogObserver::PopulateResponseInfo( 185 void NetLogObserver::PopulateResponseInfo(net::URLRequest* request,
191 net::URLRequest* request, 186 ResourceResponse* response) {
192 ResourceResponse* response) {
193 const ResourceRequestInfoImpl* request_info = 187 const ResourceRequestInfoImpl* request_info =
194 ResourceRequestInfoImpl::ForRequest(request); 188 ResourceRequestInfoImpl::ForRequest(request);
195 if (!request_info || !request_info->ShouldReportRawHeaders()) 189 if (!request_info || !request_info->ShouldReportRawHeaders())
196 return; 190 return;
197 191
198 uint32_t source_id = request->net_log().source().id; 192 uint32_t source_id = request->net_log().source().id;
199 DevToolsNetLogObserver* dev_tools_net_log_observer = 193 NetLogObserver* dev_tools_net_log_observer = NetLogObserver::GetInstance();
200 DevToolsNetLogObserver::GetInstance();
201 if (dev_tools_net_log_observer == NULL) 194 if (dev_tools_net_log_observer == NULL)
202 return; 195 return;
203 response->head.devtools_info = 196 response->head.devtools_info =
204 dev_tools_net_log_observer->GetResourceInfo(source_id); 197 dev_tools_net_log_observer->GetResourceInfo(source_id);
205 } 198 }
206 199
207 } // namespace content 200 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/netlog_observer.h ('k') | content/browser/loader/sync_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698