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

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

Issue 10565009: (Finally) Remove NetLog::EventParameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix a couple more files Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/net_log.h ('k') | net/http/http_request_headers_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 (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 "net/base/net_log.h" 5 #include "net/base/net_log.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 12 matching lines...) Expand all
23 Value* BytesTransferredCallback(int byte_count, 23 Value* BytesTransferredCallback(int byte_count,
24 const char* bytes, 24 const char* bytes,
25 NetLog::LogLevel log_level) { 25 NetLog::LogLevel log_level) {
26 DictionaryValue* dict = new DictionaryValue(); 26 DictionaryValue* dict = new DictionaryValue();
27 dict->SetInteger("byte_count", byte_count); 27 dict->SetInteger("byte_count", byte_count);
28 if (NetLog::IsLoggingBytes(log_level) && byte_count > 0) 28 if (NetLog::IsLoggingBytes(log_level) && byte_count > 0)
29 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); 29 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count));
30 return dict; 30 return dict;
31 } 31 }
32 32
33 Value* EventParametersCallback(
34 const scoped_refptr<NetLog::EventParameters>& params,
35 NetLog::LogLevel /* log_level */) {
36 if (!params.get())
37 return NULL;
38 return params->ToValue();
39 }
40
41 Value* SourceEventParametersCallback(const NetLog::Source source, 33 Value* SourceEventParametersCallback(const NetLog::Source source,
42 NetLog::LogLevel /* log_level */) { 34 NetLog::LogLevel /* log_level */) {
43 if (!source.is_valid()) 35 if (!source.is_valid())
44 return NULL; 36 return NULL;
45 DictionaryValue* event_params = new DictionaryValue(); 37 DictionaryValue* event_params = new DictionaryValue();
46 source.AddToEventParameters(event_params); 38 source.AddToEventParameters(event_params);
47 return event_params; 39 return event_params;
48 } 40 }
49 41
50 Value* NetLogIntegerCallback(const char* name, 42 Value* NetLogIntegerCallback(const char* name,
(...skipping 23 matching lines...) Expand all
74 Value* NetLogString16Callback(const char* name, 66 Value* NetLogString16Callback(const char* name,
75 const string16* value, 67 const string16* value,
76 NetLog::LogLevel /* log_level */) { 68 NetLog::LogLevel /* log_level */) {
77 DictionaryValue* event_params = new DictionaryValue(); 69 DictionaryValue* event_params = new DictionaryValue();
78 event_params->SetString(name, *value); 70 event_params->SetString(name, *value);
79 return event_params; 71 return event_params;
80 } 72 }
81 73
82 } // namespace 74 } // namespace
83 75
84 Value* NetLog::Source::ToValue() const {
85 DictionaryValue* dict = new DictionaryValue();
86 dict->SetInteger("type", static_cast<int>(type));
87 dict->SetInteger("id", static_cast<int>(id));
88 return dict;
89 }
90
91 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { 76 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const {
92 DictionaryValue* dict = new DictionaryValue(); 77 DictionaryValue* dict = new DictionaryValue();
93 dict->SetInteger("type", static_cast<int>(type)); 78 dict->SetInteger("type", static_cast<int>(type));
94 dict->SetInteger("id", static_cast<int>(id)); 79 dict->SetInteger("id", static_cast<int>(id));
95 event_params->Set("source_dependency", dict); 80 event_params->Set("source_dependency", dict);
96 } 81 }
97 82
98 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { 83 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const {
99 return base::Bind(&SourceEventParametersCallback, *this); 84 return base::Bind(&SourceEventParametersCallback, *this);
100 } 85 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 181
197 void NetLog::AddGlobalEntry( 182 void NetLog::AddGlobalEntry(
198 EventType type, 183 EventType type,
199 const NetLog::ParametersCallback& parameters_callback) { 184 const NetLog::ParametersCallback& parameters_callback) {
200 AddEntry(type, 185 AddEntry(type,
201 Source(net::NetLog::SOURCE_NONE, NextID()), 186 Source(net::NetLog::SOURCE_NONE, NextID()),
202 net::NetLog::PHASE_NONE, 187 net::NetLog::PHASE_NONE,
203 &parameters_callback); 188 &parameters_callback);
204 } 189 }
205 190
206 void NetLog::AddGlobalEntry(EventType type,
207 const scoped_refptr<EventParameters>& params) {
208 ParametersCallback callback = base::Bind(&EventParametersCallback, params);
209 AddEntry(type,
210 Source(net::NetLog::SOURCE_NONE, NextID()),
211 net::NetLog::PHASE_NONE,
212 &callback);
213 }
214
215 // static 191 // static
216 std::string NetLog::TickCountToString(const base::TimeTicks& time) { 192 std::string NetLog::TickCountToString(const base::TimeTicks& time) {
217 int64 delta_time = (time - base::TimeTicks()).InMilliseconds(); 193 int64 delta_time = (time - base::TimeTicks()).InMilliseconds();
218 return base::Int64ToString(delta_time); 194 return base::Int64ToString(delta_time);
219 } 195 }
220 196
221 // static 197 // static
222 const char* NetLog::EventTypeToString(EventType event) { 198 const char* NetLog::EventTypeToString(EventType event) {
223 switch (event) { 199 switch (event) {
224 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; 200 #define EVENT_TYPE(label) case TYPE_ ## label: return #label;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 void BoundNetLog::EndEvent(NetLog::EventType type) const { 350 void BoundNetLog::EndEvent(NetLog::EventType type) const {
375 AddEntry(type, NetLog::PHASE_END); 351 AddEntry(type, NetLog::PHASE_END);
376 } 352 }
377 353
378 void BoundNetLog::EndEvent( 354 void BoundNetLog::EndEvent(
379 NetLog::EventType type, 355 NetLog::EventType type,
380 const NetLog::ParametersCallback& get_parameters) const { 356 const NetLog::ParametersCallback& get_parameters) const {
381 AddEntry(type, NetLog::PHASE_END, get_parameters); 357 AddEntry(type, NetLog::PHASE_END, get_parameters);
382 } 358 }
383 359
384 void BoundNetLog::AddEntry(
385 NetLog::EventType type,
386 NetLog::EventPhase phase,
387 const scoped_refptr<NetLog::EventParameters>& params) const {
388 if (!net_log_)
389 return;
390 NetLog::ParametersCallback callback =
391 base::Bind(&EventParametersCallback, params);
392 net_log_->AddEntry(type, source_, phase, &callback);
393 }
394
395 void BoundNetLog::AddEvent(
396 NetLog::EventType event_type,
397 const scoped_refptr<NetLog::EventParameters>& params) const {
398 AddEntry(event_type, NetLog::PHASE_NONE, params);
399 }
400
401 void BoundNetLog::BeginEvent(
402 NetLog::EventType event_type,
403 const scoped_refptr<NetLog::EventParameters>& params) const {
404 AddEntry(event_type, NetLog::PHASE_BEGIN, params);
405 }
406
407 void BoundNetLog::EndEvent(
408 NetLog::EventType event_type,
409 const scoped_refptr<NetLog::EventParameters>& params) const {
410 AddEntry(event_type, NetLog::PHASE_END, params);
411 }
412
413 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type, 360 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type,
414 int net_error) const { 361 int net_error) const {
415 DCHECK_GT(0, net_error); 362 DCHECK_GT(0, net_error);
416 DCHECK_NE(ERR_IO_PENDING, net_error); 363 DCHECK_NE(ERR_IO_PENDING, net_error);
417 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); 364 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error));
418 } 365 }
419 366
420 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type, 367 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type,
421 int net_error) const { 368 int net_error) const {
422 DCHECK_NE(ERR_IO_PENDING, net_error); 369 DCHECK_NE(ERR_IO_PENDING, net_error);
(...skipping 27 matching lines...) Expand all
450 // static 397 // static
451 BoundNetLog BoundNetLog::Make(NetLog* net_log, 398 BoundNetLog BoundNetLog::Make(NetLog* net_log,
452 NetLog::SourceType source_type) { 399 NetLog::SourceType source_type) {
453 if (!net_log) 400 if (!net_log)
454 return BoundNetLog(); 401 return BoundNetLog();
455 402
456 NetLog::Source source(source_type, net_log->NextID()); 403 NetLog::Source source(source_type, net_log->NextID());
457 return BoundNetLog(source, net_log); 404 return BoundNetLog(source, net_log);
458 } 405 }
459 406
460 NetLogStringParameter::NetLogStringParameter(const char* name,
461 const std::string& value)
462 : name_(name), value_(value) {
463 }
464
465 NetLogStringParameter::~NetLogStringParameter() {
466 }
467
468 Value* NetLogIntegerParameter::ToValue() const {
469 DictionaryValue* dict = new DictionaryValue();
470 dict->SetInteger(name_, value_);
471 return dict;
472 }
473
474 Value* NetLogStringParameter::ToValue() const {
475 DictionaryValue* dict = new DictionaryValue();
476 dict->SetString(name_, value_);
477 return dict;
478 }
479
480 Value* NetLogSourceParameter::ToValue() const {
481 DictionaryValue* dict = new DictionaryValue();
482 if (value_.is_valid())
483 dict->Set(name_, value_.ToValue());
484 return dict;
485 }
486
487 } // namespace net 407 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_log.h ('k') | net/http/http_request_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698