Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: chrome/browser/net/chrome_net_log.cc

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again to fix a merge conflict Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..674ee64a72e9df096506edb4043014a5fc0adbcf 100644
--- a/chrome/browser/net/chrome_net_log.cc
+++ b/chrome/browser/net/chrome_net_log.cc
@@ -19,14 +19,52 @@
#include "net/log/trace_net_log_observer.h"
#include "net/log/write_to_file_net_log_observer.h"
+namespace {
+
+net::NetLogCaptureMode GetCaptureModeFromCommandLine(
+ const base::CommandLine& command_line) {
+ const net::NetLogCaptureMode kDefault = net::NetLogCaptureMode::Default();
+
+ // 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 kDefault;
+
+ std::string log_level_string =
+ command_line.GetSwitchValueASCII(switches::kNetLogLevel);
+
+ int level;
+ if (!base::StringToInt(log_level_string, &level))
+ return kDefault;
+
+ switch (level) {
+ case 0:
+ return net::NetLogCaptureMode::IncludeSocketBytes();
+ case 1:
+ return net::NetLogCaptureMode::IncludeCookiesAndCredentials();
+ case 2:
+ return net::NetLogCaptureMode::Default();
+ case 3:
+ return net::NetLogCaptureMode::None();
+ default:
+ LOG(ERROR) << "Unrecognized --" << switches::kNetLogLevel;
+ break;
+ }
+
+ return kDefault;
+}
+
+} // namespace
+
ChromeNetLog::ChromeNetLog()
: net_log_temp_file_(new NetLogTempFile(this)) {
- const base::CommandLine* command_line =
- base::CommandLine::ForCurrentProcess();
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kLogNetLog)) {
+ if (command_line.HasSwitch(switches::kLogNetLog)) {
base::FilePath log_path =
- command_line->GetSwitchValuePath(switches::kLogNetLog);
+ command_line.GetSwitchValuePath(switches::kLogNetLog);
// Much like logging.h, bypass threading restrictions by using fopen
// directly. Have to write on a thread that's shutdown to handle events on
// shutdown properly, and posting events to another thread as they occur
@@ -46,17 +84,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 =
+ GetCaptureModeFromCommandLine(command_line);
+ net_log_logger_->set_capture_mode(capture_mode);
+
net_log_logger_->StartObserving(this, file.Pass(), constants.get(),
nullptr);
}
« no previous file with comments | « chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc ('k') | chrome/browser/net/net_log_temp_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698