Chromium Code Reviews| Index: chrome/browser/net/chrome_net_log.cc |
| diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc |
| index 1dda8cce8f78e17571b7324e4fef2da936a75abf..521d8c26409bb15d552553f042ec92f640e5ea3d 100644 |
| --- a/chrome/browser/net/chrome_net_log.cc |
| +++ b/chrome/browser/net/chrome_net_log.cc |
| @@ -19,6 +19,46 @@ |
| #include "net/log/trace_net_log_observer.h" |
| #include "net/log/write_to_file_net_log_observer.h" |
| +namespace { |
| + |
| +bool GetCaptureModeFromCommandLine(const base::CommandLine* command_line, |
|
mmenke
2015/04/22 18:52:17
nit: Think const base::CommandLine& command_line
eroman
2015/04/22 20:01:46
Done.
|
| + net::NetLogCaptureMode* mode) { |
|
mmenke
2015/04/22 18:52:17
optional: Could just make this return a net::NetL
eroman
2015/04/22 20:01:46
Done.
|
| + // TODO(eroman): The NetLog "capture mode" used to be called the "log |
| + // level". To preserve backwards compatibility the log level of old is |
| + // converted into a capture mode. |
| + if (!command_line->HasSwitch(switches::kNetLogLevel)) |
| + return false; |
| + |
| + std::string log_level_string = |
| + command_line->GetSwitchValueASCII(switches::kNetLogLevel); |
| + |
| + int level; |
| + if (!base::StringToInt(log_level_string, &level)) |
| + return false; |
| + |
| + switch (level) { |
| + case 0: |
| + *mode = net::NetLogCaptureMode::IncludeSocketBytes(); |
| + return true; |
| + case 1: |
| + *mode = net::NetLogCaptureMode::IncludeCookiesAndCredentials(); |
| + return true; |
| + case 2: |
| + *mode = net::NetLogCaptureMode::Default(); |
| + return true; |
| + case 3: |
| + *mode = net::NetLogCaptureMode::None(); |
| + return true; |
| + default: |
| + LOG(ERROR) << "Unrecognized --" << switches::kNetLogLevel; |
| + break; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| ChromeNetLog::ChromeNetLog() |
| : net_log_temp_file_(new NetLogTempFile(this)) { |
| const base::CommandLine* command_line = |
| @@ -46,17 +86,11 @@ ChromeNetLog::ChromeNetLog() |
| } else { |
| scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); |
| net_log_logger_.reset(new net::WriteToFileNetLogObserver()); |
| - if (command_line->HasSwitch(switches::kNetLogLevel)) { |
| - std::string log_level_string = |
| - command_line->GetSwitchValueASCII(switches::kNetLogLevel); |
| - int command_line_log_level; |
| - if (base::StringToInt(log_level_string, &command_line_log_level) && |
| - command_line_log_level >= LOG_ALL && |
| - command_line_log_level <= LOG_NONE) { |
| - net_log_logger_->set_log_level( |
| - static_cast<LogLevel>(command_line_log_level)); |
| - } |
| - } |
| + |
| + net::NetLogCaptureMode capture_mode; |
| + if (GetCaptureModeFromCommandLine(command_line, &capture_mode)) |
| + net_log_logger_->set_capture_mode(capture_mode); |
| + |
| net_log_logger_->StartObserving(this, file.Pass(), constants.get(), |
| nullptr); |
| } |