summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/chrome_net_log.cc45
-rw-r--r--chrome/browser/net/chrome_net_log.h9
-rw-r--r--chrome/browser/net/net_log_logger.cc9
-rw-r--r--chrome/browser/net/net_log_logger.h2
-rw-r--r--chrome/browser/resources/net_internals/index.html4
-rw-r--r--chrome/browser/resources/net_internals/main.js2
-rw-r--r--chrome/common/chrome_switches.cc11
-rw-r--r--chrome/common/chrome_switches.h1
8 files changed, 57 insertions, 26 deletions
diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc
index 39ebe79..3c9625d 100644
--- a/chrome/browser/net/chrome_net_log.cc
+++ b/chrome/browser/net/chrome_net_log.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/net/load_timing_observer.h"
@@ -38,7 +39,7 @@ void ChromeNetLog::ThreadSafeObserver::SetLogLevel(
DCHECK(net_log_);
base::AutoLock lock(net_log_->lock_);
log_level_ = log_level;
- net_log_->UpdateLogLevel_();
+ net_log_->UpdateLogLevel();
}
ChromeNetLog::Entry::Entry(uint32 order,
@@ -59,16 +60,31 @@ ChromeNetLog::Entry::~Entry() {}
ChromeNetLog::ChromeNetLog()
: last_id_(0),
- log_level_(LOG_BASIC),
+ base_log_level_(LOG_BASIC),
+ effective_log_level_(LOG_BASIC),
passive_collector_(new PassiveLogCollector),
load_timing_observer_(new LoadTimingObserver) {
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ // Adjust base log level based on command line switch, if present.
+ // This is done before adding any observers so the call to UpdateLogLevel when
+ // an observers is added will set |effective_log_level_| correctly.
+ 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_BASIC) {
+ base_log_level_ = static_cast<LogLevel>(command_line_log_level);
+ }
+ }
+
AddObserver(passive_collector_.get());
AddObserver(load_timing_observer_.get());
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kLogNetLog)) {
+ if (command_line->HasSwitch(switches::kLogNetLog)) {
net_log_logger_.reset(new NetLogLogger(
- command_line.GetSwitchValuePath(switches::kLogNetLog)));
+ command_line->GetSwitchValuePath(switches::kLogNetLog)));
AddObserver(net_log_logger_.get());
}
}
@@ -98,7 +114,8 @@ uint32 ChromeNetLog::NextID() {
}
net::NetLog::LogLevel ChromeNetLog::GetLogLevel() const {
- base::subtle::Atomic32 log_level = base::subtle::NoBarrier_Load(&log_level_);
+ base::subtle::Atomic32 log_level =
+ base::subtle::NoBarrier_Load(&effective_log_level_);
return static_cast<net::NetLog::LogLevel>(log_level);
}
@@ -112,7 +129,7 @@ void ChromeNetLog::RemoveObserver(ThreadSafeObserver* observer) {
DCHECK_EQ(observer->net_log_, this);
observer->net_log_ = NULL;
observers_.RemoveObserver(observer);
- UpdateLogLevel_();
+ UpdateLogLevel();
}
void ChromeNetLog::AddObserverAndGetAllPassivelyCapturedEvents(
@@ -132,23 +149,25 @@ void ChromeNetLog::ClearAllPassivelyCapturedEvents() {
passive_collector_->Clear();
}
-void ChromeNetLog::UpdateLogLevel_() {
+void ChromeNetLog::UpdateLogLevel() {
lock_.AssertAcquired();
// Look through all the observers and find the finest granularity
// log level (higher values of the enum imply *lower* log levels).
- LogLevel new_log_level = LOG_BASIC;
+ LogLevel new_effective_log_level = base_log_level_;
ObserverListBase<ThreadSafeObserver>::Iterator it(observers_);
ThreadSafeObserver* observer;
while ((observer = it.GetNext()) != NULL) {
- new_log_level = std::min(new_log_level, observer->log_level());
+ new_effective_log_level =
+ std::min(new_effective_log_level, observer->log_level());
}
- base::subtle::NoBarrier_Store(&log_level_, new_log_level);
+ base::subtle::NoBarrier_Store(&effective_log_level_,
+ new_effective_log_level);
}
void ChromeNetLog::AddObserverWhileLockHeld(ThreadSafeObserver* observer) {
DCHECK(!observer->net_log_);
observer->net_log_ = this;
observers_.AddObserver(observer);
- UpdateLogLevel_();
+ UpdateLogLevel();
}
diff --git a/chrome/browser/net/chrome_net_log.h b/chrome/browser/net/chrome_net_log.h
index f10b01c..0d55b78 100644
--- a/chrome/browser/net/chrome_net_log.h
+++ b/chrome/browser/net/chrome_net_log.h
@@ -138,7 +138,7 @@ class ChromeNetLog : public net::NetLog {
// Called whenever an observer is added or removed, or changes its log level.
// Must have acquired |lock_| prior to calling.
- void UpdateLogLevel_();
+ void UpdateLogLevel();
// |lock_| protects access to |observers_| and, indirectly, to
// |passive_collector_|. Should not be acquired by observers.
@@ -147,7 +147,12 @@ class ChromeNetLog : public net::NetLog {
// Last assigned source ID. Incremented to get the next one.
base::subtle::Atomic32 last_id_;
- base::subtle::Atomic32 log_level_;
+ // The lowest allowed log level, regardless of any ChromeNetLogObservers.
+ // Normally defaults to LOG_BASIC, but can be changed with command line flags.
+ LogLevel base_log_level_;
+
+ // The current log level.
+ base::subtle::Atomic32 effective_log_level_;
// Not thread safe. Must only be used when |lock_| is acquired.
scoped_ptr<PassiveLogCollector> passive_collector_;
diff --git a/chrome/browser/net/net_log_logger.cc b/chrome/browser/net/net_log_logger.cc
index 1468e6f..e0f67a3 100644
--- a/chrome/browser/net/net_log_logger.cc
+++ b/chrome/browser/net/net_log_logger.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -26,9 +26,9 @@ void NetLogLogger::OnAddEntry(net::NetLog::EventType type,
const net::NetLog::Source& source,
net::NetLog::EventPhase phase,
net::NetLog::EventParameters* params) {
- scoped_ptr<Value> value(net::NetLog::EntryToDictionaryValue(type, time,
- source, phase,
- params, true));
+ scoped_ptr<Value> value(
+ net::NetLog::EntryToDictionaryValue(
+ type, time, source, phase, params, true));
// Don't pretty print, so each JSON value occupies a single line, with no
// breaks (Line breaks in any text field will be escaped). Using strings
// instead of integer identifiers allows logs from older versions to be
@@ -41,4 +41,3 @@ void NetLogLogger::OnAddEntry(net::NetLog::EventType type,
fprintf(file_.get(), "%s\n", json.c_str());
}
}
-
diff --git a/chrome/browser/net/net_log_logger.h b/chrome/browser/net/net_log_logger.h
index 4ea6288b..b1440b7 100644
--- a/chrome/browser/net/net_log_logger.h
+++ b/chrome/browser/net/net_log_logger.h
@@ -30,7 +30,7 @@ class NetLogLogger : public ChromeNetLog::ThreadSafeObserver {
const base::TimeTicks& time,
const net::NetLog::Source& source,
net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
+ net::NetLog::EventParameters* params) OVERRIDE;
private:
ScopedStdioHandle file_;
diff --git a/chrome/browser/resources/net_internals/index.html b/chrome/browser/resources/net_internals/index.html
index e50ac55..b79ea03 100644
--- a/chrome/browser/resources/net_internals/index.html
+++ b/chrome/browser/resources/net_internals/index.html
@@ -264,7 +264,9 @@ found in the LICENSE file.
<h2>Load data</h2>
<div style="margin: 8px">
<p><input type=button value="Load log from file" id=dataViewLoadLogFile /></p>
- <p>Only works with log files created with "--log-net-log=file_name".</p>
+ <p>Only works with log files created with "--log-net-log=file_name".
+ "--net-log-level=#" will set the default log level used.
+ </p>
<p>Once a log is loaded, this page will stop collecting data, and will
only start gathering data again when the page is
<a href="javascript:history.go(0);">reloaded</a>.<BR>
diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js
index 4555639..9f500df 100644
--- a/chrome/browser/resources/net_internals/main.js
+++ b/chrome/browser/resources/net_internals/main.js
@@ -601,7 +601,7 @@ BrowserBridge.prototype.loadedLogFile = function(logFileContents) {
if (numInvalidEntries > 0 || numInvalidLines > 0) {
window.alert(
numInvalidLines.toString() +
- ' could not be parsed as JSON strings, and ' +
+ ' entries could not be parsed as JSON strings, and ' +
numInvalidEntries.toString() +
' entries don\'t have valid data.\n\n' +
'Unparseable lines may indicate log file corruption.\n' +
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 0160969..b2c1f21 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -348,9 +348,6 @@ const char kDomAutomationController[] = "dom-automation";
// scripts.
const char kDumpHistogramsOnExit[] = "dump-histograms-on-exit";
-// Enable displaying net log events on the command line.
-extern const char kLogNetLog[] = "log-net-log";
-
// Enable gpu-accelerated 2d canvas.
const char kEnableAccelerated2dCanvas[] = "enable-accelerated-2d-canvas";
@@ -637,6 +634,10 @@ const char kLoadExtension[] = "load-extension";
// http://crosbug.com/12295 and http://crosbug.com/12304
const char kLoadOpencryptoki[] = "load-opencryptoki";
+// Enable displaying net log events on the command line, or writing the events
+// to a separate file if a file name is given.
+const char kLogNetLog[] = "log-net-log";
+
// Uninstall an extension with the specified extension id.
const char kUninstallExtension[] = "uninstall-extension";
@@ -681,6 +682,10 @@ const char kNaClBrokerProcess[] = "nacl-broker";
// Causes the Native Client process to display a dialog on launch.
const char kNaClStartupDialog[] = "nacl-startup-dialog";
+// Sets the base logging level for the net log. Log 0 logs the most data.
+// Intended primarily for use with --log-net-log.
+const char kNetLogLevel[] = "net-log-level";
+
// Use the latest incarnation of the new tab page.
const char kNewTabPage4[] = "new-tab-page-4";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 19b97ad..db116c5 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -195,6 +195,7 @@ extern const char kNaClDebugIP[];
extern const char kNaClDebugPorts[];
extern const char kNaClBrokerProcess[];
extern const char kNaClStartupDialog[];
+extern const char kNetLogLevel[];
extern const char kNewTabPage4[];
extern const char kNoDefaultBrowserCheck[];
extern const char kNoEvents[];