| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 return params->ToValue(); | 38 return params->ToValue(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 Value* SourceEventParametersCallback(const NetLog::Source source, | 41 Value* SourceEventParametersCallback(const NetLog::Source source, |
| 42 NetLog::LogLevel /* log_level */) { | 42 NetLog::LogLevel /* log_level */) { |
| 43 DictionaryValue* event_params = new DictionaryValue(); | 43 DictionaryValue* event_params = new DictionaryValue(); |
| 44 source.AddToEventParameters(event_params); | 44 source.AddToEventParameters(event_params); |
| 45 return event_params; | 45 return event_params; |
| 46 } | 46 } |
| 47 | 47 |
| 48 Value* SingleIntegerCallback(const char* name, | 48 Value* NetLogIntegerCallback(const char* name, |
| 49 int value, | 49 int value, |
| 50 NetLog::LogLevel /* log_level */) { | 50 NetLog::LogLevel /* log_level */) { |
| 51 if (!value) | |
| 52 return NULL; | |
| 53 DictionaryValue* event_params = new DictionaryValue(); | 51 DictionaryValue* event_params = new DictionaryValue(); |
| 54 event_params->SetInteger(name, value); | 52 event_params->SetInteger(name, value); |
| 55 return event_params; | 53 return event_params; |
| 56 } | 54 } |
| 57 | 55 |
| 56 Value* NetLogStringCallback(const char* name, |
| 57 const std::string* value, |
| 58 NetLog::LogLevel /* log_level */) { |
| 59 DictionaryValue* event_params = new DictionaryValue(); |
| 60 event_params->SetString(name, *value); |
| 61 return event_params; |
| 62 } |
| 63 |
| 58 } // namespace | 64 } // namespace |
| 59 | 65 |
| 60 Value* NetLog::Source::ToValue() const { | 66 Value* NetLog::Source::ToValue() const { |
| 61 DictionaryValue* dict = new DictionaryValue(); | 67 DictionaryValue* dict = new DictionaryValue(); |
| 62 dict->SetInteger("type", static_cast<int>(type)); | 68 dict->SetInteger("type", static_cast<int>(type)); |
| 63 dict->SetInteger("id", static_cast<int>(id)); | 69 dict->SetInteger("id", static_cast<int>(id)); |
| 64 return dict; | 70 return dict; |
| 65 } | 71 } |
| 66 | 72 |
| 67 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { | 73 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 262 } |
| 257 | 263 |
| 258 // static | 264 // static |
| 259 bool NetLog::IsLoggingAllEvents(LogLevel log_level) { | 265 bool NetLog::IsLoggingAllEvents(LogLevel log_level) { |
| 260 return log_level <= NetLog::LOG_ALL_BUT_BYTES; | 266 return log_level <= NetLog::LOG_ALL_BUT_BYTES; |
| 261 } | 267 } |
| 262 | 268 |
| 263 // static | 269 // static |
| 264 NetLog::ParametersCallback NetLog::IntegerCallback(const char* name, | 270 NetLog::ParametersCallback NetLog::IntegerCallback(const char* name, |
| 265 int value) { | 271 int value) { |
| 266 return base::Bind(&SingleIntegerCallback, name, value); | 272 return base::Bind(&NetLogIntegerCallback, name, value); |
| 273 } |
| 274 |
| 275 // static |
| 276 NetLog::ParametersCallback NetLog::StringCallback(const char* name, |
| 277 const std::string* value) { |
| 278 DCHECK(value); |
| 279 return base::Bind(&NetLogStringCallback, name, value); |
| 267 } | 280 } |
| 268 | 281 |
| 269 void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) { | 282 void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) { |
| 270 DCHECK(!observer->net_log_); | 283 DCHECK(!observer->net_log_); |
| 271 observer->net_log_ = this; | 284 observer->net_log_ = this; |
| 272 observer->log_level_ = log_level; | 285 observer->log_level_ = log_level; |
| 273 } | 286 } |
| 274 | 287 |
| 275 void NetLog::OnSetObserverLogLevel(ThreadSafeObserver* observer, | 288 void NetLog::OnSetObserverLogLevel(ThreadSafeObserver* observer, |
| 276 LogLevel log_level) { | 289 LogLevel log_level) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 void BoundNetLog::EndEvent( | 376 void BoundNetLog::EndEvent( |
| 364 NetLog::EventType event_type, | 377 NetLog::EventType event_type, |
| 365 const scoped_refptr<NetLog::EventParameters>& params) const { | 378 const scoped_refptr<NetLog::EventParameters>& params) const { |
| 366 AddEntry(event_type, NetLog::PHASE_END, params); | 379 AddEntry(event_type, NetLog::PHASE_END, params); |
| 367 } | 380 } |
| 368 | 381 |
| 369 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type, | 382 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type, |
| 370 int net_error) const { | 383 int net_error) const { |
| 371 DCHECK_GT(0, net_error); | 384 DCHECK_GT(0, net_error); |
| 372 DCHECK_NE(ERR_IO_PENDING, net_error); | 385 DCHECK_NE(ERR_IO_PENDING, net_error); |
| 373 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); | 386 if (net_error >= 0) { |
| 387 AddEvent(event_type); |
| 388 } else { |
| 389 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); |
| 390 } |
| 374 } | 391 } |
| 375 | 392 |
| 376 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type, | 393 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type, |
| 377 int net_error) const { | 394 int net_error) const { |
| 378 DCHECK_NE(ERR_IO_PENDING, net_error); | 395 DCHECK_NE(ERR_IO_PENDING, net_error); |
| 379 EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); | 396 if (net_error >= 0) { |
| 397 EndEvent(event_type); |
| 398 } else { |
| 399 EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); |
| 400 } |
| 380 } | 401 } |
| 381 | 402 |
| 382 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, | 403 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, |
| 383 int byte_count, | 404 int byte_count, |
| 384 const char* bytes) const { | 405 const char* bytes) const { |
| 385 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); | 406 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); |
| 386 } | 407 } |
| 387 | 408 |
| 388 NetLog::LogLevel BoundNetLog::GetLogLevel() const { | 409 NetLog::LogLevel BoundNetLog::GetLogLevel() const { |
| 389 if (net_log_) | 410 if (net_log_) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 451 } |
| 431 | 452 |
| 432 Value* NetLogSourceParameter::ToValue() const { | 453 Value* NetLogSourceParameter::ToValue() const { |
| 433 DictionaryValue* dict = new DictionaryValue(); | 454 DictionaryValue* dict = new DictionaryValue(); |
| 434 if (value_.is_valid()) | 455 if (value_.is_valid()) |
| 435 dict->Set(name_, value_.ToValue()); | 456 dict->Set(name_, value_.ToValue()); |
| 436 return dict; | 457 return dict; |
| 437 } | 458 } |
| 438 | 459 |
| 439 } // namespace net | 460 } // namespace net |
| OLD | NEW |