[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/base/net_log.h" |
[email protected] | f6f1bebc | 2011-01-07 03:04:54 | [diff] [blame] | 6 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 8 | #include "base/logging.h" |
| 9 | #include "base/string_number_conversions.h" |
[email protected] | 5097dc8 | 2010-07-15 17:23:23 | [diff] [blame] | 10 | #include "base/time.h" |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 11 | #include "base/utf_string_conversions.h" |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 12 | #include "base/values.h" |
[email protected] | f6f1bebc | 2011-01-07 03:04:54 | [diff] [blame] | 13 | #include "net/base/net_errors.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 14 | |
| 15 | namespace net { |
| 16 | |
[email protected] | 267a0d66d | 2011-06-01 21:15:19 | [diff] [blame] | 17 | namespace { |
| 18 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 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 |
| 21 | // |byte_count| > 0, the bytes themselves. The bytes are hex-encoded, since |
| 22 | // base::StringValue only supports UTF-8. |
| 23 | Value* BytesTransferredCallback(int byte_count, |
| 24 | const char* bytes, |
| 25 | NetLog::LogLevel log_level) { |
| 26 | DictionaryValue* dict = new DictionaryValue(); |
| 27 | dict->SetInteger("byte_count", byte_count); |
| 28 | if (NetLog::IsLoggingBytes(log_level) && byte_count > 0) |
| 29 | dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); |
| 30 | return dict; |
[email protected] | 267a0d66d | 2011-06-01 21:15:19 | [diff] [blame] | 31 | } |
| 32 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 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, |
| 42 | NetLog::LogLevel /* log_level */) { |
| 43 | DictionaryValue* event_params = new DictionaryValue(); |
| 44 | source.AddToEventParameters(event_params); |
| 45 | return event_params; |
| 46 | } |
| 47 | |
| 48 | Value* SingleIntegerCallback(const char* name, |
| 49 | int value, |
| 50 | NetLog::LogLevel /* log_level */) { |
| 51 | if (!value) |
| 52 | return NULL; |
| 53 | DictionaryValue* event_params = new DictionaryValue(); |
| 54 | event_params->SetInteger(name, value); |
| 55 | return event_params; |
[email protected] | 267a0d66d | 2011-06-01 21:15:19 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | |
[email protected] | ee094b8 | 2010-08-24 15:55:51 | [diff] [blame] | 60 | Value* NetLog::Source::ToValue() const { |
| 61 | DictionaryValue* dict = new DictionaryValue(); |
| 62 | dict->SetInteger("type", static_cast<int>(type)); |
| 63 | dict->SetInteger("id", static_cast<int>(id)); |
| 64 | return dict; |
| 65 | } |
| 66 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 67 | void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { |
| 68 | DictionaryValue* dict = new DictionaryValue(); |
| 69 | dict->SetInteger("type", static_cast<int>(type)); |
| 70 | dict->SetInteger("id", static_cast<int>(id)); |
| 71 | event_params->Set("source_dependency", dict); |
| 72 | } |
| 73 | |
| 74 | NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { |
| 75 | return base::Bind(&SourceEventParametersCallback, *this); |
| 76 | } |
| 77 | |
| 78 | // static |
| 79 | bool NetLog::Source::FromEventParameters(Value* event_params, Source* source) { |
| 80 | DictionaryValue* dict; |
| 81 | DictionaryValue* source_dict; |
| 82 | int source_id; |
| 83 | int source_type; |
| 84 | if (!event_params || |
| 85 | !event_params->GetAsDictionary(&dict) || |
| 86 | !dict->GetDictionary("source_dependency", &source_dict) || |
| 87 | !source_dict->GetInteger("id", &source_id) || |
| 88 | !source_dict->GetInteger("type", &source_type)) { |
| 89 | *source = Source(); |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | DCHECK_LE(0, source_id); |
| 94 | DCHECK_LT(source_type, NetLog::SOURCE_COUNT); |
| 95 | *source = Source(static_cast<SourceType>(source_type), source_id); |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | Value* NetLog::Entry::ToValue() const { |
| 100 | DictionaryValue* entry_dict(new DictionaryValue()); |
| 101 | |
| 102 | entry_dict->SetString("time", TickCountToString(base::TimeTicks::Now())); |
| 103 | |
| 104 | // Set the entry source. |
| 105 | DictionaryValue* source_dict = new DictionaryValue(); |
| 106 | source_dict->SetInteger("id", source_.id); |
| 107 | source_dict->SetInteger("type", static_cast<int>(source_.type)); |
| 108 | entry_dict->Set("source", source_dict); |
| 109 | |
| 110 | // Set the event info. |
| 111 | entry_dict->SetInteger("type", static_cast<int>(type_)); |
| 112 | entry_dict->SetInteger("phase", static_cast<int>(phase_)); |
| 113 | |
| 114 | // Set the event-specific parameters. |
| 115 | if (parameters_callback_) { |
| 116 | Value* value = parameters_callback_->Run(log_level_); |
| 117 | if (value) |
| 118 | entry_dict->Set("params", value); |
| 119 | } |
| 120 | |
| 121 | return entry_dict; |
| 122 | } |
| 123 | |
| 124 | Value* NetLog::Entry::ParametersToValue() const { |
| 125 | if (parameters_callback_) |
| 126 | return parameters_callback_->Run(log_level_); |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | NetLog::Entry::Entry( |
| 131 | EventType type, |
| 132 | Source source, |
| 133 | EventPhase phase, |
| 134 | const ParametersCallback* parameters_callback, |
| 135 | LogLevel log_level) |
| 136 | : type_(type), |
| 137 | source_(source), |
| 138 | phase_(phase), |
| 139 | parameters_callback_(parameters_callback), |
| 140 | log_level_(log_level) { |
| 141 | }; |
| 142 | |
| 143 | NetLog::Entry::~Entry() { |
| 144 | } |
| 145 | |
[email protected] | d5cbd92a | 2012-02-29 12:43:23 | [diff] [blame] | 146 | NetLog::ThreadSafeObserver::ThreadSafeObserver() : log_level_(LOG_BASIC), |
| 147 | net_log_(NULL) { |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | NetLog::ThreadSafeObserver::~ThreadSafeObserver() { |
[email protected] | d5cbd92a | 2012-02-29 12:43:23 | [diff] [blame] | 151 | // Make sure we aren't watching a NetLog on destruction. Because the NetLog |
| 152 | // may pass events to each observer on multiple threads, we cannot safely |
| 153 | // stop watching a NetLog automatically from a parent class. |
| 154 | DCHECK(!net_log_); |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | NetLog::LogLevel NetLog::ThreadSafeObserver::log_level() const { |
[email protected] | d5cbd92a | 2012-02-29 12:43:23 | [diff] [blame] | 158 | DCHECK(net_log_); |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 159 | return log_level_; |
| 160 | } |
| 161 | |
[email protected] | d5cbd92a | 2012-02-29 12:43:23 | [diff] [blame] | 162 | NetLog* NetLog::ThreadSafeObserver::net_log() const { |
| 163 | return net_log_; |
| 164 | } |
| 165 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 166 | void NetLog::AddGlobalEntry(EventType type) { |
| 167 | AddEntry(type, |
| 168 | Source(net::NetLog::SOURCE_NONE, NextID()), |
| 169 | net::NetLog::PHASE_NONE, |
| 170 | NULL); |
| 171 | } |
| 172 | |
| 173 | void NetLog::AddGlobalEntry( |
| 174 | EventType type, |
| 175 | const NetLog::ParametersCallback& parameters_callback) { |
| 176 | AddEntry(type, |
| 177 | Source(net::NetLog::SOURCE_NONE, NextID()), |
| 178 | net::NetLog::PHASE_NONE, |
| 179 | ¶meters_callback); |
| 180 | } |
| 181 | |
[email protected] | fba65f7b | 2012-03-15 05:22:13 | [diff] [blame] | 182 | void NetLog::AddGlobalEntry(EventType type, |
| 183 | const scoped_refptr<EventParameters>& params) { |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 184 | ParametersCallback callback = base::Bind(&EventParametersCallback, params); |
[email protected] | fba65f7b | 2012-03-15 05:22:13 | [diff] [blame] | 185 | AddEntry(type, |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 186 | Source(net::NetLog::SOURCE_NONE, NextID()), |
[email protected] | fba65f7b | 2012-03-15 05:22:13 | [diff] [blame] | 187 | net::NetLog::PHASE_NONE, |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 188 | &callback); |
[email protected] | fba65f7b | 2012-03-15 05:22:13 | [diff] [blame] | 189 | } |
| 190 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 191 | // static |
[email protected] | 1ce7b66b | 2010-10-12 20:32:44 | [diff] [blame] | 192 | std::string NetLog::TickCountToString(const base::TimeTicks& time) { |
| 193 | int64 delta_time = (time - base::TimeTicks()).InMilliseconds(); |
| 194 | return base::Int64ToString(delta_time); |
| 195 | } |
| 196 | |
| 197 | // static |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 198 | const char* NetLog::EventTypeToString(EventType event) { |
| 199 | switch (event) { |
| 200 | #define EVENT_TYPE(label) case TYPE_ ## label: return #label; |
| 201 | #include "net/base/net_log_event_type_list.h" |
| 202 | #undef EVENT_TYPE |
[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 203 | default: |
| 204 | NOTREACHED(); |
| 205 | return NULL; |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 206 | } |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | fd9c0d9 | 2010-03-23 17:47:49 | [diff] [blame] | 209 | // static |
[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 210 | base::Value* NetLog::GetEventTypesAsValue() { |
| 211 | DictionaryValue* dict = new DictionaryValue(); |
| 212 | for (int i = 0; i < EVENT_COUNT; ++i) { |
| 213 | dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); |
| 214 | } |
| 215 | return dict; |
[email protected] | fd9c0d9 | 2010-03-23 17:47:49 | [diff] [blame] | 216 | } |
| 217 | |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 218 | // static |
| 219 | const char* NetLog::SourceTypeToString(SourceType source) { |
| 220 | switch (source) { |
[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 221 | #define SOURCE_TYPE(label) case SOURCE_ ## label: return #label; |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 222 | #include "net/base/net_log_source_type_list.h" |
| 223 | #undef SOURCE_TYPE |
[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 224 | default: |
| 225 | NOTREACHED(); |
| 226 | return NULL; |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 227 | } |
[email protected] | 988394e | 2012-02-22 16:37:55 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // static |
| 231 | base::Value* NetLog::GetSourceTypesAsValue() { |
| 232 | DictionaryValue* dict = new DictionaryValue(); |
| 233 | for (int i = 0; i < SOURCE_COUNT; ++i) { |
| 234 | dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); |
| 235 | } |
| 236 | return dict; |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // static |
| 240 | const char* NetLog::EventPhaseToString(EventPhase phase) { |
| 241 | switch (phase) { |
| 242 | case PHASE_BEGIN: |
| 243 | return "PHASE_BEGIN"; |
| 244 | case PHASE_END: |
| 245 | return "PHASE_END"; |
| 246 | case PHASE_NONE: |
| 247 | return "PHASE_NONE"; |
| 248 | } |
| 249 | NOTREACHED(); |
| 250 | return NULL; |
| 251 | } |
| 252 | |
| 253 | // static |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 254 | bool NetLog::IsLoggingBytes(LogLevel log_level) { |
| 255 | return log_level == NetLog::LOG_ALL; |
| 256 | } |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 257 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 258 | // static |
| 259 | bool NetLog::IsLoggingAllEvents(LogLevel log_level) { |
| 260 | return log_level <= NetLog::LOG_ALL_BUT_BYTES; |
| 261 | } |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 262 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 263 | // static |
| 264 | NetLog::ParametersCallback NetLog::IntegerCallback(const char* name, |
| 265 | int value) { |
| 266 | return base::Bind(&SingleIntegerCallback, name, value); |
[email protected] | 9319035 | 2010-08-13 13:55:10 | [diff] [blame] | 267 | } |
| 268 | |
[email protected] | d5cbd92a | 2012-02-29 12:43:23 | [diff] [blame] | 269 | void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) { |
| 270 | DCHECK(!observer->net_log_); |
| 271 | observer->net_log_ = this; |
| 272 | observer->log_level_ = log_level; |
| 273 | } |
| 274 | |
| 275 | void NetLog::OnSetObserverLogLevel(ThreadSafeObserver* observer, |
| 276 | LogLevel log_level) { |
| 277 | DCHECK_EQ(this, observer->net_log_); |
| 278 | observer->log_level_ = log_level; |
| 279 | } |
| 280 | |
| 281 | void NetLog::OnRemoveObserver(ThreadSafeObserver* observer) { |
| 282 | DCHECK_EQ(this, observer->net_log_); |
| 283 | observer->net_log_ = NULL; |
| 284 | } |
| 285 | |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 286 | void NetLog::AddEntry(EventType type, |
| 287 | const Source& source, |
| 288 | EventPhase phase, |
| 289 | const NetLog::ParametersCallback* parameters_callback) { |
| 290 | Entry entry(type, source, phase, parameters_callback, GetLogLevel()); |
| 291 | OnAddEntry(entry); |
| 292 | } |
| 293 | |
| 294 | void BoundNetLog::AddEntry(NetLog::EventType type, |
| 295 | NetLog::EventPhase phase) const { |
| 296 | if (!net_log_) |
| 297 | return; |
| 298 | net_log_->AddEntry(type, source_, phase, NULL); |
| 299 | } |
| 300 | |
| 301 | void BoundNetLog::AddEntry( |
| 302 | NetLog::EventType type, |
| 303 | NetLog::EventPhase phase, |
| 304 | const NetLog::ParametersCallback& get_parameters) const { |
| 305 | if (!net_log_) |
| 306 | return; |
| 307 | net_log_->AddEntry(type, source_, phase, &get_parameters); |
| 308 | } |
| 309 | |
| 310 | void BoundNetLog::AddEvent(NetLog::EventType type) const { |
| 311 | AddEntry(type, NetLog::PHASE_NONE); |
| 312 | } |
| 313 | |
| 314 | void BoundNetLog::AddEvent( |
| 315 | NetLog::EventType type, |
| 316 | const NetLog::ParametersCallback& get_parameters) const { |
| 317 | AddEntry(type, NetLog::PHASE_NONE, get_parameters); |
| 318 | } |
| 319 | |
| 320 | void BoundNetLog::BeginEvent(NetLog::EventType type) const { |
| 321 | AddEntry(type, NetLog::PHASE_BEGIN); |
| 322 | } |
| 323 | |
| 324 | void BoundNetLog::BeginEvent( |
| 325 | NetLog::EventType type, |
| 326 | const NetLog::ParametersCallback& get_parameters) const { |
| 327 | AddEntry(type, NetLog::PHASE_BEGIN, get_parameters); |
| 328 | } |
| 329 | |
| 330 | void BoundNetLog::EndEvent(NetLog::EventType type) const { |
| 331 | AddEntry(type, NetLog::PHASE_END); |
| 332 | } |
| 333 | |
| 334 | void BoundNetLog::EndEvent( |
| 335 | NetLog::EventType type, |
| 336 | const NetLog::ParametersCallback& get_parameters) const { |
| 337 | AddEntry(type, NetLog::PHASE_END, get_parameters); |
| 338 | } |
| 339 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 340 | void BoundNetLog::AddEntry( |
| 341 | NetLog::EventType type, |
| 342 | NetLog::EventPhase phase, |
| 343 | const scoped_refptr<NetLog::EventParameters>& params) const { |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 344 | if (!net_log_) |
| 345 | return; |
| 346 | NetLog::ParametersCallback callback = |
| 347 | base::Bind(&EventParametersCallback, params); |
| 348 | net_log_->AddEntry(type, source_, phase, &callback); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 351 | void BoundNetLog::AddEvent( |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 352 | NetLog::EventType event_type, |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 353 | const scoped_refptr<NetLog::EventParameters>& params) const { |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 354 | AddEntry(event_type, NetLog::PHASE_NONE, params); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 357 | void BoundNetLog::BeginEvent( |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 358 | NetLog::EventType event_type, |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 359 | const scoped_refptr<NetLog::EventParameters>& params) const { |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 360 | AddEntry(event_type, NetLog::PHASE_BEGIN, params); |
| 361 | } |
| 362 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 363 | void BoundNetLog::EndEvent( |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 364 | NetLog::EventType event_type, |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 365 | const scoped_refptr<NetLog::EventParameters>& params) const { |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 366 | AddEntry(event_type, NetLog::PHASE_END, params); |
| 367 | } |
| 368 | |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 369 | void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type, |
| 370 | int net_error) const { |
| 371 | DCHECK_GT(0, net_error); |
| 372 | DCHECK_NE(ERR_IO_PENDING, net_error); |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 373 | AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | f6f1bebc | 2011-01-07 03:04:54 | [diff] [blame] | 376 | void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type, |
| 377 | int net_error) const { |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 378 | DCHECK_NE(ERR_IO_PENDING, net_error); |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 379 | EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); |
[email protected] | f6f1bebc | 2011-01-07 03:04:54 | [diff] [blame] | 380 | } |
| 381 | |
[email protected] | 267a0d66d | 2011-06-01 21:15:19 | [diff] [blame] | 382 | void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 383 | int byte_count, |
| 384 | const char* bytes) const { |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 385 | AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); |
[email protected] | 267a0d66d | 2011-06-01 21:15:19 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | be1a48b | 2011-01-20 00:12:13 | [diff] [blame] | 388 | NetLog::LogLevel BoundNetLog::GetLogLevel() const { |
| 389 | if (net_log_) |
| 390 | return net_log_->GetLogLevel(); |
| 391 | return NetLog::LOG_BASIC; |
| 392 | } |
| 393 | |
| 394 | bool BoundNetLog::IsLoggingBytes() const { |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 395 | return NetLog::IsLoggingBytes(GetLogLevel()); |
[email protected] | be1a48b | 2011-01-20 00:12:13 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | bool BoundNetLog::IsLoggingAllEvents() const { |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 399 | return NetLog::IsLoggingAllEvents(GetLogLevel()); |
[email protected] | be1a48b | 2011-01-20 00:12:13 | [diff] [blame] | 400 | } |
| 401 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 402 | // static |
| 403 | BoundNetLog BoundNetLog::Make(NetLog* net_log, |
| 404 | NetLog::SourceType source_type) { |
| 405 | if (!net_log) |
| 406 | return BoundNetLog(); |
| 407 | |
| 408 | NetLog::Source source(source_type, net_log->NextID()); |
| 409 | return BoundNetLog(source, net_log); |
| 410 | } |
| 411 | |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 412 | NetLogStringParameter::NetLogStringParameter(const char* name, |
| 413 | const std::string& value) |
| 414 | : name_(name), value_(value) { |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 417 | NetLogStringParameter::~NetLogStringParameter() { |
| 418 | } |
| 419 | |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 420 | Value* NetLogIntegerParameter::ToValue() const { |
| 421 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | ccaff65 | 2010-07-31 06:28:20 | [diff] [blame] | 422 | dict->SetInteger(name_, value_); |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 423 | return dict; |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 426 | Value* NetLogStringParameter::ToValue() const { |
| 427 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | ccaff65 | 2010-07-31 06:28:20 | [diff] [blame] | 428 | dict->SetString(name_, value_); |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 429 | return dict; |
[email protected] | 1f0e32b | 2010-04-09 04:34:47 | [diff] [blame] | 430 | } |
| 431 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 432 | Value* NetLogSourceParameter::ToValue() const { |
| 433 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 68697a4 | 2011-12-19 21:47:55 | [diff] [blame] | 434 | if (value_.is_valid()) |
| 435 | dict->Set(name_, value_.ToValue()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 436 | return dict; |
| 437 | } |
| 438 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 439 | } // namespace net |