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

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

Issue 1149763005: Change NetLog::ParametersCallback to return a scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments on ownership removed Created 5 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
« no previous file with comments | « net/log/net_log_unittest.cc ('k') | net/proxy/proxy_config.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/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
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();
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
144 // Add a dictionary with information on the relationship between event type 144 // Add a dictionary with information on the relationship between event type
145 // enums and their symbolic names. 145 // enums and their symbolic names.
146 constants_dict->Set("logEventTypes", NetLog::GetEventTypesAsValue()); 146 constants_dict->Set("logEventTypes", NetLog::GetEventTypesAsValue());
147 147
148 // Add a dictionary with information about the relationship between CertStatus 148 // Add a dictionary with information about the relationship between CertStatus
149 // flags and their symbolic names. 149 // flags and their symbolic names.
150 { 150 {
151 base::DictionaryValue* dict = new base::DictionaryValue(); 151 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
152 152
153 for (size_t i = 0; i < arraysize(kCertStatusFlags); i++) 153 for (size_t i = 0; i < arraysize(kCertStatusFlags); i++)
154 dict->SetInteger(kCertStatusFlags[i].name, kCertStatusFlags[i].constant); 154 dict->SetInteger(kCertStatusFlags[i].name, kCertStatusFlags[i].constant);
155 155
156 constants_dict->Set("certStatusFlag", dict); 156 constants_dict->Set("certStatusFlag", dict.Pass());
157 } 157 }
158 158
159 // Add a dictionary with information about the relationship between load flag 159 // Add a dictionary with information about the relationship between load flag
160 // enums and their symbolic names. 160 // enums and their symbolic names.
161 { 161 {
162 base::DictionaryValue* dict = new base::DictionaryValue(); 162 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
163 163
164 for (size_t i = 0; i < arraysize(kLoadFlags); i++) 164 for (size_t i = 0; i < arraysize(kLoadFlags); i++)
165 dict->SetInteger(kLoadFlags[i].name, kLoadFlags[i].constant); 165 dict->SetInteger(kLoadFlags[i].name, kLoadFlags[i].constant);
166 166
167 constants_dict->Set("loadFlag", dict); 167 constants_dict->Set("loadFlag", dict.Pass());
168 } 168 }
169 169
170 // Add a dictionary with information about the relationship between load state 170 // Add a dictionary with information about the relationship between load state
171 // enums and their symbolic names. 171 // enums and their symbolic names.
172 { 172 {
173 base::DictionaryValue* dict = new base::DictionaryValue(); 173 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
174 174
175 for (size_t i = 0; i < arraysize(kLoadStateTable); i++) 175 for (size_t i = 0; i < arraysize(kLoadStateTable); i++)
176 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant); 176 dict->SetInteger(kLoadStateTable[i].name, kLoadStateTable[i].constant);
177 177
178 constants_dict->Set("loadState", dict); 178 constants_dict->Set("loadState", dict.Pass());
179 } 179 }
180 180
181 { 181 {
182 base::DictionaryValue* dict = new base::DictionaryValue(); 182 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
183 #define NET_INFO_SOURCE(label, string, value) \ 183 #define NET_INFO_SOURCE(label, string, value) \
184 dict->SetInteger(string, NET_INFO_##label); 184 dict->SetInteger(string, NET_INFO_##label);
185 #include "net/base/net_info_source_list.h" 185 #include "net/base/net_info_source_list.h"
186 #undef NET_INFO_SOURCE 186 #undef NET_INFO_SOURCE
187 constants_dict->Set("netInfoSources", dict); 187 constants_dict->Set("netInfoSources", dict.Pass());
188 } 188 }
189 189
190 // Add information on the relationship between net error codes and their 190 // Add information on the relationship between net error codes and their
191 // symbolic names. 191 // symbolic names.
192 { 192 {
193 base::DictionaryValue* dict = new base::DictionaryValue(); 193 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
194 194
195 for (size_t i = 0; i < arraysize(kNetErrors); i++) 195 for (size_t i = 0; i < arraysize(kNetErrors); i++)
196 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]); 196 dict->SetInteger(ErrorToShortString(kNetErrors[i]), kNetErrors[i]);
197 197
198 constants_dict->Set("netError", dict); 198 constants_dict->Set("netError", dict.Pass());
199 } 199 }
200 200
201 // Add information on the relationship between QUIC error codes and their 201 // Add information on the relationship between QUIC error codes and their
202 // symbolic names. 202 // symbolic names.
203 { 203 {
204 base::DictionaryValue* dict = new base::DictionaryValue(); 204 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
205 205
206 for (QuicErrorCode error = QUIC_NO_ERROR; error < QUIC_LAST_ERROR; 206 for (QuicErrorCode error = QUIC_NO_ERROR; error < QUIC_LAST_ERROR;
207 error = static_cast<QuicErrorCode>(error + 1)) { 207 error = static_cast<QuicErrorCode>(error + 1)) {
208 dict->SetInteger(QuicUtils::ErrorToString(error), 208 dict->SetInteger(QuicUtils::ErrorToString(error),
209 static_cast<int>(error)); 209 static_cast<int>(error));
210 } 210 }
211 211
212 constants_dict->Set("quicError", dict); 212 constants_dict->Set("quicError", dict.Pass());
213 } 213 }
214 214
215 // Add information on the relationship between QUIC RST_STREAM error codes 215 // Add information on the relationship between QUIC RST_STREAM error codes
216 // and their symbolic names. 216 // and their symbolic names.
217 { 217 {
218 base::DictionaryValue* dict = new base::DictionaryValue(); 218 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
219 219
220 for (QuicRstStreamErrorCode error = QUIC_STREAM_NO_ERROR; 220 for (QuicRstStreamErrorCode error = QUIC_STREAM_NO_ERROR;
221 error < QUIC_STREAM_LAST_ERROR; 221 error < QUIC_STREAM_LAST_ERROR;
222 error = static_cast<QuicRstStreamErrorCode>(error + 1)) { 222 error = static_cast<QuicRstStreamErrorCode>(error + 1)) {
223 dict->SetInteger(QuicUtils::StreamErrorToString(error), 223 dict->SetInteger(QuicUtils::StreamErrorToString(error),
224 static_cast<int>(error)); 224 static_cast<int>(error));
225 } 225 }
226 226
227 constants_dict->Set("quicRstStreamError", dict); 227 constants_dict->Set("quicRstStreamError", dict.Pass());
228 } 228 }
229 229
230 // Add information on the relationship between SDCH problem codes and their 230 // Add information on the relationship between SDCH problem codes and their
231 // symbolic names. 231 // symbolic names.
232 { 232 {
233 base::DictionaryValue* dict = new base::DictionaryValue(); 233 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
234 234
235 for (size_t i = 0; i < arraysize(kSdchProblems); i++) 235 for (size_t i = 0; i < arraysize(kSdchProblems); i++)
236 dict->SetInteger(kSdchProblems[i].name, kSdchProblems[i].constant); 236 dict->SetInteger(kSdchProblems[i].name, kSdchProblems[i].constant);
237 237
238 constants_dict->Set("sdchProblemCode", dict); 238 constants_dict->Set("sdchProblemCode", dict.Pass());
239 } 239 }
240 240
241 // Information about the relationship between event phase enums and their 241 // Information about the relationship between event phase enums and their
242 // symbolic names. 242 // symbolic names.
243 { 243 {
244 base::DictionaryValue* dict = new base::DictionaryValue(); 244 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
245 245
246 dict->SetInteger("PHASE_BEGIN", NetLog::PHASE_BEGIN); 246 dict->SetInteger("PHASE_BEGIN", NetLog::PHASE_BEGIN);
247 dict->SetInteger("PHASE_END", NetLog::PHASE_END); 247 dict->SetInteger("PHASE_END", NetLog::PHASE_END);
248 dict->SetInteger("PHASE_NONE", NetLog::PHASE_NONE); 248 dict->SetInteger("PHASE_NONE", NetLog::PHASE_NONE);
249 249
250 constants_dict->Set("logEventPhase", dict); 250 constants_dict->Set("logEventPhase", dict.Pass());
251 } 251 }
252 252
253 // Information about the relationship between source type enums and 253 // Information about the relationship between source type enums and
254 // their symbolic names. 254 // their symbolic names.
255 constants_dict->Set("logSourceType", NetLog::GetSourceTypesAsValue()); 255 constants_dict->Set("logSourceType", NetLog::GetSourceTypesAsValue());
256 256
257 // TODO(eroman): This is here for compatibility in loading new log files with 257 // TODO(eroman): This is here for compatibility in loading new log files with
258 // older builds of Chrome. Safe to remove this once M45 is on the stable 258 // older builds of Chrome. Safe to remove this once M45 is on the stable
259 // channel. 259 // channel.
260 constants_dict->Set("logLevelType", new base::DictionaryValue()); 260 constants_dict->Set("logLevelType", new base::DictionaryValue());
261 261
262 // Information about the relationship between address family enums and 262 // Information about the relationship between address family enums and
263 // their symbolic names. 263 // their symbolic names.
264 { 264 {
265 base::DictionaryValue* dict = new base::DictionaryValue(); 265 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
266 266
267 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED); 267 dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED);
268 dict->SetInteger("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4); 268 dict->SetInteger("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4);
269 dict->SetInteger("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6); 269 dict->SetInteger("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6);
270 270
271 constants_dict->Set("addressFamily", dict); 271 constants_dict->Set("addressFamily", dict.Pass());
272 } 272 }
273 273
274 // Information about how the "time ticks" values we have given it relate to 274 // Information about how the "time ticks" values we have given it relate to
275 // actual system times. Time ticks are used throughout since they are stable 275 // actual system times. Time ticks are used throughout since they are stable
276 // across system clock changes. 276 // across system clock changes.
277 { 277 {
278 int64 tick_to_unix_time_ms = 278 int64 tick_to_unix_time_ms =
279 (base::TimeTicks() - base::TimeTicks::UnixEpoch()).InMilliseconds(); 279 (base::TimeTicks() - base::TimeTicks::UnixEpoch()).InMilliseconds();
280 280
281 // Pass it as a string, since it may be too large to fit in an integer. 281 // Pass it as a string, since it may be too large to fit in an integer.
(...skipping 27 matching lines...) Expand all
309 // May only be called on the context's thread. 309 // May only be called on the context's thread.
310 DCHECK(context->CalledOnValidThread()); 310 DCHECK(context->CalledOnValidThread());
311 311
312 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue()); 312 scoped_ptr<base::DictionaryValue> net_info_dict(new base::DictionaryValue());
313 313
314 // TODO(mmenke): The code for most of these sources should probably be moved 314 // TODO(mmenke): The code for most of these sources should probably be moved
315 // into the sources themselves. 315 // into the sources themselves.
316 if (info_sources & NET_INFO_PROXY_SETTINGS) { 316 if (info_sources & NET_INFO_PROXY_SETTINGS) {
317 ProxyService* proxy_service = context->proxy_service(); 317 ProxyService* proxy_service = context->proxy_service();
318 318
319 base::DictionaryValue* dict = new base::DictionaryValue(); 319 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
320 if (proxy_service->fetched_config().is_valid()) 320 if (proxy_service->fetched_config().is_valid())
321 dict->Set("original", proxy_service->fetched_config().ToValue()); 321 dict->Set("original", proxy_service->fetched_config().ToValue());
322 if (proxy_service->config().is_valid()) 322 if (proxy_service->config().is_valid())
323 dict->Set("effective", proxy_service->config().ToValue()); 323 dict->Set("effective", proxy_service->config().ToValue());
324 324
325 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS), dict); 325 net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS),
326 dict.Pass());
326 } 327 }
327 328
328 if (info_sources & NET_INFO_BAD_PROXIES) { 329 if (info_sources & NET_INFO_BAD_PROXIES) {
329 const ProxyRetryInfoMap& bad_proxies_map = 330 const ProxyRetryInfoMap& bad_proxies_map =
330 context->proxy_service()->proxy_retry_info(); 331 context->proxy_service()->proxy_retry_info();
331 332
332 base::ListValue* list = new base::ListValue(); 333 base::ListValue* list = new base::ListValue();
333 334
334 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); 335 for (ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin();
335 it != bad_proxies_map.end(); ++it) { 336 it != bad_proxies_map.end(); ++it) {
336 const std::string& proxy_uri = it->first; 337 const std::string& proxy_uri = it->first;
337 const ProxyRetryInfo& retry_info = it->second; 338 const ProxyRetryInfo& retry_info = it->second;
338 339
339 base::DictionaryValue* dict = new base::DictionaryValue(); 340 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
340 dict->SetString("proxy_uri", proxy_uri); 341 dict->SetString("proxy_uri", proxy_uri);
341 dict->SetString("bad_until", 342 dict->SetString("bad_until",
342 NetLog::TickCountToString(retry_info.bad_until)); 343 NetLog::TickCountToString(retry_info.bad_until));
343 344
344 list->Append(dict); 345 list->Append(dict.Pass());
345 } 346 }
346 347
347 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), list); 348 net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES), list);
348 } 349 }
349 350
350 if (info_sources & NET_INFO_HOST_RESOLVER) { 351 if (info_sources & NET_INFO_HOST_RESOLVER) {
351 HostResolver* host_resolver = context->host_resolver(); 352 HostResolver* host_resolver = context->host_resolver();
352 DCHECK(host_resolver); 353 DCHECK(host_resolver);
353 HostCache* cache = host_resolver->GetHostCache(); 354 HostCache* cache = host_resolver->GetHostCache();
354 if (cache) { 355 if (cache) {
355 base::DictionaryValue* dict = new base::DictionaryValue(); 356 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
356 base::Value* dns_config = host_resolver->GetDnsConfigAsValue(); 357 base::Value* dns_config = host_resolver->GetDnsConfigAsValue();
357 if (dns_config) 358 if (dns_config)
358 dict->Set("dns_config", dns_config); 359 dict->Set("dns_config", dns_config);
359 360
360 dict->SetInteger( 361 dict->SetInteger(
361 "default_address_family", 362 "default_address_family",
362 static_cast<int>(host_resolver->GetDefaultAddressFamily())); 363 static_cast<int>(host_resolver->GetDefaultAddressFamily()));
363 364
364 base::DictionaryValue* cache_info_dict = new base::DictionaryValue(); 365 base::DictionaryValue* cache_info_dict = new base::DictionaryValue();
365 366
(...skipping 24 matching lines...) Expand all
390 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort()); 391 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort());
391 } 392 }
392 entry_dict->Set("addresses", address_list); 393 entry_dict->Set("addresses", address_list);
393 } 394 }
394 395
395 entry_list->Append(entry_dict); 396 entry_list->Append(entry_dict);
396 } 397 }
397 398
398 cache_info_dict->Set("entries", entry_list); 399 cache_info_dict->Set("entries", entry_list);
399 dict->Set("cache", cache_info_dict); 400 dict->Set("cache", cache_info_dict);
400 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER), dict); 401 net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER),
402 dict.Pass());
401 } 403 }
402 } 404 }
403 405
404 HttpNetworkSession* http_network_session = 406 HttpNetworkSession* http_network_session =
405 context->http_transaction_factory()->GetSession(); 407 context->http_transaction_factory()->GetSession();
406 408
407 if (info_sources & NET_INFO_SOCKET_POOL) { 409 if (info_sources & NET_INFO_SOCKET_POOL) {
408 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL), 410 net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL),
409 http_network_session->SocketPoolInfoToValue()); 411 http_network_session->SocketPoolInfoToValue());
410 } 412 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 // fine, since GetRequestStateAsValue() ignores the capture mode. 515 // fine, since GetRequestStateAsValue() ignores the capture mode.
514 NetLog::EntryData entry_data( 516 NetLog::EntryData entry_data(
515 NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(), 517 NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(),
516 NetLog::PHASE_BEGIN, request->creation_time(), &callback); 518 NetLog::PHASE_BEGIN, request->creation_time(), &callback);
517 NetLog::Entry entry(&entry_data, NetLogCaptureMode::Default()); 519 NetLog::Entry entry(&entry_data, NetLogCaptureMode::Default());
518 observer->OnAddEntry(entry); 520 observer->OnAddEntry(entry);
519 } 521 }
520 } 522 }
521 523
522 } // namespace net 524 } // namespace net
OLDNEW
« no previous file with comments | « net/log/net_log_unittest.cc ('k') | net/proxy/proxy_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698