| 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 #ifdef TEMP_INSTRUMENTATION_467797 |
| 9 #include "base/debug/alias.h" |
| 10 #endif |
| 8 #include "base/logging.h" | 11 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 12 #include "base/values.h" | 15 #include "base/values.h" |
| 13 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 14 | 17 |
| 15 namespace net { | 18 namespace net { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (GetLogLevel() == LOG_NONE) | 394 if (GetLogLevel() == LOG_NONE) |
| 392 return; | 395 return; |
| 393 EntryData entry_data(type, source, phase, base::TimeTicks::Now(), | 396 EntryData entry_data(type, source, phase, base::TimeTicks::Now(), |
| 394 parameters_callback); | 397 parameters_callback); |
| 395 | 398 |
| 396 // Notify all of the log observers. | 399 // Notify all of the log observers. |
| 397 base::AutoLock lock(lock_); | 400 base::AutoLock lock(lock_); |
| 398 FOR_EACH_OBSERVER(ThreadSafeObserver, observers_, OnAddEntryData(entry_data)); | 401 FOR_EACH_OBSERVER(ThreadSafeObserver, observers_, OnAddEntryData(entry_data)); |
| 399 } | 402 } |
| 400 | 403 |
| 404 BoundNetLog::~BoundNetLog() { |
| 405 #ifdef TEMP_INSTRUMENTATION_467797 |
| 406 liveness_ = DEAD; |
| 407 stack_trace_ = base::debug::StackTrace(); |
| 408 |
| 409 // Probably not necessary, but just in case compiler tries to optimize out the |
| 410 // writes to liveness_ and stack_trace_. |
| 411 base::debug::Alias(&liveness_); |
| 412 base::debug::Alias(&stack_trace_); |
| 413 #endif |
| 414 } |
| 415 |
| 401 void BoundNetLog::AddEntry(NetLog::EventType type, | 416 void BoundNetLog::AddEntry(NetLog::EventType type, |
| 402 NetLog::EventPhase phase) const { | 417 NetLog::EventPhase phase) const { |
| 418 CrashIfInvalid(); |
| 419 |
| 403 if (!net_log_) | 420 if (!net_log_) |
| 404 return; | 421 return; |
| 405 net_log_->AddEntry(type, source_, phase, NULL); | 422 net_log_->AddEntry(type, source_, phase, NULL); |
| 406 } | 423 } |
| 407 | 424 |
| 408 void BoundNetLog::AddEntry( | 425 void BoundNetLog::AddEntry( |
| 409 NetLog::EventType type, | 426 NetLog::EventType type, |
| 410 NetLog::EventPhase phase, | 427 NetLog::EventPhase phase, |
| 411 const NetLog::ParametersCallback& get_parameters) const { | 428 const NetLog::ParametersCallback& get_parameters) const { |
| 429 CrashIfInvalid(); |
| 430 |
| 412 if (!net_log_) | 431 if (!net_log_) |
| 413 return; | 432 return; |
| 414 net_log_->AddEntry(type, source_, phase, &get_parameters); | 433 net_log_->AddEntry(type, source_, phase, &get_parameters); |
| 415 } | 434 } |
| 416 | 435 |
| 417 void BoundNetLog::AddEvent(NetLog::EventType type) const { | 436 void BoundNetLog::AddEvent(NetLog::EventType type) const { |
| 418 AddEntry(type, NetLog::PHASE_NONE); | 437 AddEntry(type, NetLog::PHASE_NONE); |
| 419 } | 438 } |
| 420 | 439 |
| 421 void BoundNetLog::AddEvent( | 440 void BoundNetLog::AddEvent( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 483 } |
| 465 } | 484 } |
| 466 | 485 |
| 467 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, | 486 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, |
| 468 int byte_count, | 487 int byte_count, |
| 469 const char* bytes) const { | 488 const char* bytes) const { |
| 470 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); | 489 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); |
| 471 } | 490 } |
| 472 | 491 |
| 473 NetLog::LogLevel BoundNetLog::GetLogLevel() const { | 492 NetLog::LogLevel BoundNetLog::GetLogLevel() const { |
| 493 CrashIfInvalid(); |
| 494 |
| 474 if (net_log_) | 495 if (net_log_) |
| 475 return net_log_->GetLogLevel(); | 496 return net_log_->GetLogLevel(); |
| 476 return NetLog::LOG_NONE; | 497 return NetLog::LOG_NONE; |
| 477 } | 498 } |
| 478 | 499 |
| 479 bool BoundNetLog::IsLoggingBytes() const { | 500 bool BoundNetLog::IsLoggingBytes() const { |
| 480 return NetLog::IsLoggingBytes(GetLogLevel()); | 501 return NetLog::IsLoggingBytes(GetLogLevel()); |
| 481 } | 502 } |
| 482 | 503 |
| 483 bool BoundNetLog::IsLogging() const { | 504 bool BoundNetLog::IsLogging() const { |
| 484 return NetLog::IsLogging(GetLogLevel()); | 505 return NetLog::IsLogging(GetLogLevel()); |
| 485 } | 506 } |
| 486 | 507 |
| 487 // static | 508 // static |
| 488 BoundNetLog BoundNetLog::Make(NetLog* net_log, | 509 BoundNetLog BoundNetLog::Make(NetLog* net_log, |
| 489 NetLog::SourceType source_type) { | 510 NetLog::SourceType source_type) { |
| 490 if (!net_log) | 511 if (!net_log) |
| 491 return BoundNetLog(); | 512 return BoundNetLog(); |
| 492 | 513 |
| 493 NetLog::Source source(source_type, net_log->NextID()); | 514 NetLog::Source source(source_type, net_log->NextID()); |
| 494 return BoundNetLog(source, net_log); | 515 return BoundNetLog(source, net_log); |
| 495 } | 516 } |
| 496 | 517 |
| 518 void BoundNetLog::CrashIfInvalid() const { |
| 519 #ifdef TEMP_INSTRUMENTATION_467797 |
| 520 Liveness liveness = liveness_; |
| 521 |
| 522 if (liveness == ALIVE) |
| 523 return; |
| 524 |
| 525 // Copy relevant variables onto the stack to guarantee they will be available |
| 526 // in minidumps, and then crash. |
| 527 base::debug::StackTrace stack_trace = stack_trace_; |
| 528 |
| 529 base::debug::Alias(&liveness); |
| 530 base::debug::Alias(&stack_trace); |
| 531 |
| 532 CHECK_EQ(ALIVE, liveness); |
| 533 #endif |
| 534 } |
| 535 |
| 497 } // namespace net | 536 } // namespace net |
| OLD | NEW |