Chromium Code Reviews| 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 "chrome/browser/net/chrome_net_log.h" | 5 #include "chrome/browser/net/chrome_net_log.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.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/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/net/load_timing_observer.h" | 12 #include "chrome/browser/net/load_timing_observer.h" |
| 13 #include "chrome/browser/net/net_log_logger.h" | 13 #include "chrome/browser/net/net_log_logger.h" |
| 14 #include "chrome/browser/net/net_log_temp_file.h" | |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 | 16 |
| 16 ChromeNetLog::ChromeNetLog() | 17 ChromeNetLog::ChromeNetLog() |
| 17 : last_id_(0), | 18 : last_id_(0), |
| 18 base_log_level_(LOG_BASIC), | 19 base_log_level_(LOG_BASIC), |
| 19 effective_log_level_(LOG_BASIC), | 20 effective_log_level_(LOG_BASIC), |
| 20 load_timing_observer_(new LoadTimingObserver()) { | 21 load_timing_observer_(new LoadTimingObserver()), |
| 22 net_log_temp_file_(new NetLogTempFile(this)) { | |
| 21 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 23 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 22 // Adjust base log level based on command line switch, if present. | 24 // Adjust base log level based on command line switch, if present. |
| 23 // This is done before adding any observers so the call to UpdateLogLevel when | 25 // This is done before adding any observers so the call to UpdateLogLevel when |
| 24 // an observers is added will set |effective_log_level_| correctly. | 26 // an observers is added will set |effective_log_level_| correctly. |
| 25 if (command_line->HasSwitch(switches::kNetLogLevel)) { | 27 if (command_line->HasSwitch(switches::kNetLogLevel)) { |
| 26 std::string log_level_string = | 28 std::string log_level_string = |
| 27 command_line->GetSwitchValueASCII(switches::kNetLogLevel); | 29 command_line->GetSwitchValueASCII(switches::kNetLogLevel); |
| 28 int command_line_log_level; | 30 int command_line_log_level; |
| 29 if (base::StringToInt(log_level_string, &command_line_log_level) && | 31 if (base::StringToInt(log_level_string, &command_line_log_level) && |
| 30 command_line_log_level >= LOG_ALL && | 32 command_line_log_level >= LOG_ALL && |
| 31 command_line_log_level <= LOG_BASIC) { | 33 command_line_log_level <= LOG_BASIC) { |
| 32 base_log_level_ = static_cast<LogLevel>(command_line_log_level); | 34 base_log_level_ = static_cast<LogLevel>(command_line_log_level); |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 | 37 |
| 36 load_timing_observer_->StartObserving(this); | 38 load_timing_observer_->StartObserving(this); |
| 37 | 39 |
| 38 if (command_line->HasSwitch(switches::kLogNetLog)) { | 40 if (command_line->HasSwitch(switches::kLogNetLog)) { |
| 39 net_log_logger_.reset(new NetLogLogger( | 41 net_log_logger_.reset(new NetLogLogger( |
| 40 command_line->GetSwitchValuePath(switches::kLogNetLog))); | 42 command_line->GetSwitchValuePath(switches::kLogNetLog))); |
| 41 net_log_logger_->StartObserving(this); | 43 net_log_logger_->StartObserving(this); |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 ChromeNetLog::~ChromeNetLog() { | 47 ChromeNetLog::~ChromeNetLog() { |
| 48 net_log_temp_file_.reset(); | |
|
mmenke
2013/01/18 15:58:00
Think we should have the temp file stop watching t
mmenke
2013/01/18 15:58:00
Also, there's no need to delete this. Just need t
ramant (doing other things)
2013/01/18 23:22:33
We do the above in NetLogTempFile::~NetLogTempFile
| |
| 46 // Remove the observers we own before we're destroyed. | 49 // Remove the observers we own before we're destroyed. |
| 47 RemoveThreadSafeObserver(load_timing_observer_.get()); | 50 RemoveThreadSafeObserver(load_timing_observer_.get()); |
| 48 if (net_log_logger_.get()) | 51 if (net_log_logger_.get()) |
| 49 RemoveThreadSafeObserver(net_log_logger_.get()); | 52 RemoveThreadSafeObserver(net_log_logger_.get()); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void ChromeNetLog::OnAddEntry(const net::NetLog::Entry& entry) { | 55 void ChromeNetLog::OnAddEntry(const net::NetLog::Entry& entry) { |
| 53 base::AutoLock lock(lock_); | 56 base::AutoLock lock(lock_); |
| 54 | 57 |
| 55 // Notify all of the log observers. | 58 // Notify all of the log observers. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 LogLevel new_effective_log_level = base_log_level_; | 107 LogLevel new_effective_log_level = base_log_level_; |
| 105 ObserverListBase<ThreadSafeObserver>::Iterator it(observers_); | 108 ObserverListBase<ThreadSafeObserver>::Iterator it(observers_); |
| 106 ThreadSafeObserver* observer; | 109 ThreadSafeObserver* observer; |
| 107 while ((observer = it.GetNext()) != NULL) { | 110 while ((observer = it.GetNext()) != NULL) { |
| 108 new_effective_log_level = | 111 new_effective_log_level = |
| 109 std::min(new_effective_log_level, observer->log_level()); | 112 std::min(new_effective_log_level, observer->log_level()); |
| 110 } | 113 } |
| 111 base::subtle::NoBarrier_Store(&effective_log_level_, | 114 base::subtle::NoBarrier_Store(&effective_log_level_, |
| 112 new_effective_log_level); | 115 new_effective_log_level); |
| 113 } | 116 } |
| OLD | NEW |