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

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

Issue 15662008: Make net and ipc explicitly use the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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/file_stream_net_log_parameters.cc ('k') | net/base/net_util.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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 namespace { 17 namespace {
18 18
19 // Returns parameters for logging data transferred events. Includes number of 19 // Returns parameters for logging data transferred events. Includes number of
20 // bytes transferred and, if the log level indicates bytes should be logged and 20 // bytes transferred and, if the log level indicates bytes should be logged and
21 // |byte_count| > 0, the bytes themselves. The bytes are hex-encoded, since 21 // |byte_count| > 0, the bytes themselves. The bytes are hex-encoded, since
22 // base::StringValue only supports UTF-8. 22 // base::StringValue only supports UTF-8.
23 Value* BytesTransferredCallback(int byte_count, 23 base::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 base::DictionaryValue* dict = new base::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* SourceEventParametersCallback(const NetLog::Source source, 33 base::Value* SourceEventParametersCallback(const NetLog::Source source,
34 NetLog::LogLevel /* log_level */) { 34 NetLog::LogLevel /* log_level */) {
35 if (!source.IsValid()) 35 if (!source.IsValid())
36 return NULL; 36 return NULL;
37 DictionaryValue* event_params = new DictionaryValue(); 37 base::DictionaryValue* event_params = new base::DictionaryValue();
38 source.AddToEventParameters(event_params); 38 source.AddToEventParameters(event_params);
39 return event_params; 39 return event_params;
40 } 40 }
41 41
42 Value* NetLogIntegerCallback(const char* name, 42 base::Value* NetLogIntegerCallback(const char* name,
43 int value, 43 int value,
44 NetLog::LogLevel /* log_level */) { 44 NetLog::LogLevel /* log_level */) {
45 DictionaryValue* event_params = new DictionaryValue(); 45 base::DictionaryValue* event_params = new base::DictionaryValue();
46 event_params->SetInteger(name, value); 46 event_params->SetInteger(name, value);
47 return event_params; 47 return event_params;
48 } 48 }
49 49
50 Value* NetLogInt64Callback(const char* name, 50 base::Value* NetLogInt64Callback(const char* name,
51 int64 value, 51 int64 value,
52 NetLog::LogLevel /* log_level */) { 52 NetLog::LogLevel /* log_level */) {
53 DictionaryValue* event_params = new DictionaryValue(); 53 base::DictionaryValue* event_params = new base::DictionaryValue();
54 event_params->SetString(name, base::Int64ToString(value)); 54 event_params->SetString(name, base::Int64ToString(value));
55 return event_params; 55 return event_params;
56 } 56 }
57 57
58 Value* NetLogStringCallback(const char* name, 58 base::Value* NetLogStringCallback(const char* name,
59 const std::string* value, 59 const std::string* value,
60 NetLog::LogLevel /* log_level */) { 60 NetLog::LogLevel /* log_level */) {
61 DictionaryValue* event_params = new DictionaryValue(); 61 base::DictionaryValue* event_params = new base::DictionaryValue();
62 event_params->SetString(name, *value); 62 event_params->SetString(name, *value);
63 return event_params; 63 return event_params;
64 } 64 }
65 65
66 Value* NetLogString16Callback(const char* name, 66 base::Value* NetLogString16Callback(const char* name,
67 const base::string16* value, 67 const base::string16* value,
68 NetLog::LogLevel /* log_level */) { 68 NetLog::LogLevel /* log_level */) {
69 DictionaryValue* event_params = new DictionaryValue(); 69 base::DictionaryValue* event_params = new base::DictionaryValue();
70 event_params->SetString(name, *value); 70 event_params->SetString(name, *value);
71 return event_params; 71 return event_params;
72 } 72 }
73 73
74 } // namespace 74 } // namespace
75 75
76 // LoadTimingInfo requires this be 0. 76 // LoadTimingInfo requires this be 0.
77 const uint32 NetLog::Source::kInvalidId = 0; 77 const uint32 NetLog::Source::kInvalidId = 0;
78 78
79 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { 79 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) {
80 } 80 }
81 81
82 NetLog::Source::Source(SourceType type, uint32 id) : type(type), id(id) { 82 NetLog::Source::Source(SourceType type, uint32 id) : type(type), id(id) {
83 } 83 }
84 84
85 bool NetLog::Source::IsValid() const { 85 bool NetLog::Source::IsValid() const {
86 return id != kInvalidId; 86 return id != kInvalidId;
87 } 87 }
88 88
89 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { 89 void NetLog::Source::AddToEventParameters(
90 DictionaryValue* dict = new DictionaryValue(); 90 base::DictionaryValue* event_params) const {
91 base::DictionaryValue* dict = new base::DictionaryValue();
91 dict->SetInteger("type", static_cast<int>(type)); 92 dict->SetInteger("type", static_cast<int>(type));
92 dict->SetInteger("id", static_cast<int>(id)); 93 dict->SetInteger("id", static_cast<int>(id));
93 event_params->Set("source_dependency", dict); 94 event_params->Set("source_dependency", dict);
94 } 95 }
95 96
96 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { 97 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const {
97 return base::Bind(&SourceEventParametersCallback, *this); 98 return base::Bind(&SourceEventParametersCallback, *this);
98 } 99 }
99 100
100 // static 101 // static
101 bool NetLog::Source::FromEventParameters(Value* event_params, Source* source) { 102 bool NetLog::Source::FromEventParameters(Value* event_params, Source* source) {
102 DictionaryValue* dict; 103 base::DictionaryValue* dict;
103 DictionaryValue* source_dict; 104 base::DictionaryValue* source_dict;
104 int source_id; 105 int source_id;
105 int source_type; 106 int source_type;
106 if (!event_params || 107 if (!event_params ||
107 !event_params->GetAsDictionary(&dict) || 108 !event_params->GetAsDictionary(&dict) ||
108 !dict->GetDictionary("source_dependency", &source_dict) || 109 !dict->GetDictionary("source_dependency", &source_dict) ||
109 !source_dict->GetInteger("id", &source_id) || 110 !source_dict->GetInteger("id", &source_id) ||
110 !source_dict->GetInteger("type", &source_type)) { 111 !source_dict->GetInteger("type", &source_type)) {
111 *source = Source(); 112 *source = Source();
112 return false; 113 return false;
113 } 114 }
114 115
115 DCHECK_LE(0, source_id); 116 DCHECK_LE(0, source_id);
116 DCHECK_LT(source_type, NetLog::SOURCE_COUNT); 117 DCHECK_LT(source_type, NetLog::SOURCE_COUNT);
117 *source = Source(static_cast<SourceType>(source_type), source_id); 118 *source = Source(static_cast<SourceType>(source_type), source_id);
118 return true; 119 return true;
119 } 120 }
120 121
121 Value* NetLog::Entry::ToValue() const { 122 base::Value* NetLog::Entry::ToValue() const {
122 DictionaryValue* entry_dict(new DictionaryValue()); 123 base::DictionaryValue* entry_dict(new base::DictionaryValue());
123 124
124 entry_dict->SetString("time", TickCountToString(time_)); 125 entry_dict->SetString("time", TickCountToString(time_));
125 126
126 // Set the entry source. 127 // Set the entry source.
127 DictionaryValue* source_dict = new DictionaryValue(); 128 base::DictionaryValue* source_dict = new base::DictionaryValue();
128 source_dict->SetInteger("id", source_.id); 129 source_dict->SetInteger("id", source_.id);
129 source_dict->SetInteger("type", static_cast<int>(source_.type)); 130 source_dict->SetInteger("type", static_cast<int>(source_.type));
130 entry_dict->Set("source", source_dict); 131 entry_dict->Set("source", source_dict);
131 132
132 // Set the event info. 133 // Set the event info.
133 entry_dict->SetInteger("type", static_cast<int>(type_)); 134 entry_dict->SetInteger("type", static_cast<int>(type_));
134 entry_dict->SetInteger("phase", static_cast<int>(phase_)); 135 entry_dict->SetInteger("phase", static_cast<int>(phase_));
135 136
136 // Set the event-specific parameters. 137 // Set the event-specific parameters.
137 if (parameters_callback_) { 138 if (parameters_callback_) {
138 Value* value = parameters_callback_->Run(log_level_); 139 Value* value = parameters_callback_->Run(log_level_);
139 if (value) 140 if (value)
140 entry_dict->Set("params", value); 141 entry_dict->Set("params", value);
141 } 142 }
142 143
143 return entry_dict; 144 return entry_dict;
144 } 145 }
145 146
146 Value* NetLog::Entry::ParametersToValue() const { 147 base::Value* NetLog::Entry::ParametersToValue() const {
147 if (parameters_callback_) 148 if (parameters_callback_)
148 return parameters_callback_->Run(log_level_); 149 return parameters_callback_->Run(log_level_);
149 return NULL; 150 return NULL;
150 } 151 }
151 152
152 NetLog::Entry::Entry( 153 NetLog::Entry::Entry(
153 EventType type, 154 EventType type,
154 Source source, 155 Source source,
155 EventPhase phase, 156 EventPhase phase,
156 base::TimeTicks time, 157 base::TimeTicks time,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 #include "net/base/net_log_event_type_list.h" 293 #include "net/base/net_log_event_type_list.h"
293 #undef EVENT_TYPE 294 #undef EVENT_TYPE
294 default: 295 default:
295 NOTREACHED(); 296 NOTREACHED();
296 return NULL; 297 return NULL;
297 } 298 }
298 } 299 }
299 300
300 // static 301 // static
301 base::Value* NetLog::GetEventTypesAsValue() { 302 base::Value* NetLog::GetEventTypesAsValue() {
302 DictionaryValue* dict = new DictionaryValue(); 303 base::DictionaryValue* dict = new base::DictionaryValue();
303 for (int i = 0; i < EVENT_COUNT; ++i) { 304 for (int i = 0; i < EVENT_COUNT; ++i) {
304 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); 305 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i);
305 } 306 }
306 return dict; 307 return dict;
307 } 308 }
308 309
309 // static 310 // static
310 const char* NetLog::SourceTypeToString(SourceType source) { 311 const char* NetLog::SourceTypeToString(SourceType source) {
311 switch (source) { 312 switch (source) {
312 #define SOURCE_TYPE(label) case SOURCE_ ## label: return #label; 313 #define SOURCE_TYPE(label) case SOURCE_ ## label: return #label;
313 #include "net/base/net_log_source_type_list.h" 314 #include "net/base/net_log_source_type_list.h"
314 #undef SOURCE_TYPE 315 #undef SOURCE_TYPE
315 default: 316 default:
316 NOTREACHED(); 317 NOTREACHED();
317 return NULL; 318 return NULL;
318 } 319 }
319 } 320 }
320 321
321 // static 322 // static
322 base::Value* NetLog::GetSourceTypesAsValue() { 323 base::Value* NetLog::GetSourceTypesAsValue() {
323 DictionaryValue* dict = new DictionaryValue(); 324 base::DictionaryValue* dict = new base::DictionaryValue();
324 for (int i = 0; i < SOURCE_COUNT; ++i) { 325 for (int i = 0; i < SOURCE_COUNT; ++i) {
325 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); 326 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i);
326 } 327 }
327 return dict; 328 return dict;
328 } 329 }
329 330
330 // static 331 // static
331 const char* NetLog::EventPhaseToString(EventPhase phase) { 332 const char* NetLog::EventPhaseToString(EventPhase phase) {
332 switch (phase) { 333 switch (phase) {
333 case PHASE_BEGIN: 334 case PHASE_BEGIN:
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 BoundNetLog BoundNetLog::Make(NetLog* net_log, 483 BoundNetLog BoundNetLog::Make(NetLog* net_log,
483 NetLog::SourceType source_type) { 484 NetLog::SourceType source_type) {
484 if (!net_log) 485 if (!net_log)
485 return BoundNetLog(); 486 return BoundNetLog();
486 487
487 NetLog::Source source(source_type, net_log->NextID()); 488 NetLog::Source source(source_type, net_log->NextID());
488 return BoundNetLog(source, net_log); 489 return BoundNetLog(source, net_log);
489 } 490 }
490 491
491 } // namespace net 492 } // namespace net
OLDNEW
« no previous file with comments | « net/base/file_stream_net_log_parameters.cc ('k') | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698