diff options
100 files changed, 964 insertions, 637 deletions
diff --git a/chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc b/chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc index e53007b..5423b48 100644 --- a/chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc +++ b/chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc @@ -288,9 +288,10 @@ void LogPrivateAPI::StartObservingNetEvents( return; write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); - write_to_file_observer_->set_log_level(net::NetLog::LOG_ALL_BUT_BYTES); + write_to_file_observer_->set_capture_mode( + net::NetLogCaptureMode::IncludeCookiesAndCredentials()); write_to_file_observer_->StartObserving(io_thread->net_log(), file->Pass(), - nullptr, nullptr); + nullptr, nullptr); } void LogPrivateAPI::MaybeStartNetInternalLogging( @@ -304,7 +305,7 @@ void LogPrivateAPI::MaybeStartNetInternalLogging( switch (event_sink_) { case api::log_private::EVENT_SINK_CAPTURE: { io_thread->net_log()->DeprecatedAddObserver( - this, net::NetLog::LOG_ALL_BUT_BYTES); + this, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); break; } case api::log_private::EVENT_SINK_FILE: { diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc index 1dda8cce..674ee64 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); } diff --git a/chrome/browser/net/net_log_temp_file.cc b/chrome/browser/net/net_log_temp_file.cc index 3674b2b..99f29aa 100644 --- a/chrome/browser/net/net_log_temp_file.cc +++ b/chrome/browser/net/net_log_temp_file.cc @@ -93,19 +93,20 @@ base::DictionaryValue* NetLogTempFile::GetState() { return dict; } -net::NetLog::LogLevel NetLogTempFile::GetLogLevelForLogType(LogType log_type) { +net::NetLogCaptureMode NetLogTempFile::GetCaptureModeForLogType( + LogType log_type) { switch (log_type) { case LOG_TYPE_LOG_BYTES: - return net::NetLog::LOG_ALL; + return net::NetLogCaptureMode::IncludeSocketBytes(); case LOG_TYPE_NORMAL: - return net::NetLog::LOG_ALL_BUT_BYTES; + return net::NetLogCaptureMode::IncludeCookiesAndCredentials(); case LOG_TYPE_STRIP_PRIVATE_DATA: - return net::NetLog::LOG_STRIP_PRIVATE_DATA; + return net::NetLogCaptureMode::Default(); case LOG_TYPE_NONE: case LOG_TYPE_UNKNOWN: NOTREACHED(); } - return net::NetLog::LOG_STRIP_PRIVATE_DATA; + return net::NetLogCaptureMode::Default(); } bool NetLogTempFile::EnsureInit() { @@ -145,7 +146,7 @@ void NetLogTempFile::StartNetLog(LogType log_type) { scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); net_log_logger_.reset(new net::WriteToFileNetLogObserver()); - net_log_logger_->set_log_level(GetLogLevelForLogType(log_type)); + net_log_logger_->set_capture_mode(GetCaptureModeForLogType(log_type)); net_log_logger_->StartObserving(chrome_net_log_, file.Pass(), constants.get(), nullptr); } diff --git a/chrome/browser/net/net_log_temp_file.h b/chrome/browser/net/net_log_temp_file.h index 46598e3..2b96276 100644 --- a/chrome/browser/net/net_log_temp_file.h +++ b/chrome/browser/net/net_log_temp_file.h @@ -113,8 +113,8 @@ class NetLogTempFile { LOG_TYPE_STRIP_PRIVATE_DATA, }; - // Returns the NetLog::LogLevel corresponding to a LogType. - static net::NetLog::LogLevel GetLogLevelForLogType(LogType log_type); + // Returns the NetLog::CaptureMode corresponding to a LogType. + static net::NetLogCaptureMode GetCaptureModeForLogType(LogType log_type); // Initializes the |state_| to STATE_NOT_LOGGING and |log_type_| to // LOG_TYPE_NONE (if there is no temporary file from earlier run) or @@ -123,8 +123,9 @@ class NetLogTempFile { bool EnsureInit(); // Start collecting NetLog data into chrome-net-export-log.json file in - // base::GetTempDir() directory, using the specified log level. It is a no-op - // if we are already collecting data into a file, and |log_level| is ignored. + // base::GetTempDir() directory, using the specified capture mode. It is a + // no-op if we are already collecting data into a file, and |capture_mode| is + // ignored. // TODO(mmenke): That's rather weird behavior, think about improving it. void StartNetLog(LogType log_type); diff --git a/chrome/browser/net/net_log_temp_file_unittest.cc b/chrome/browser/net/net_log_temp_file_unittest.cc index 89b0b62..572f12c 100644 --- a/chrome/browser/net/net_log_temp_file_unittest.cc +++ b/chrome/browser/net/net_log_temp_file_unittest.cc @@ -148,19 +148,21 @@ class NetLogTempFileTest : public ::testing::Test { // initialized by a DO_START command of the given type. void VerifyFileAndStateAfterDoStart() { - VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL", - net::NetLog::LOG_ALL_BUT_BYTES); + VerifyFileAndStateAfterStart( + NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL", + net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } void VerifyFileAndStateAfterDoStartStripPrivateData() const { VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, "STRIP_PRIVATE_DATA", - net::NetLog::LOG_STRIP_PRIVATE_DATA); + net::NetLogCaptureMode::Default()); } void VerifyFileAndStateAfterDoStartLogBytes() const { VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES, - "LOG_BYTES", net::NetLog::LOG_ALL); + "LOG_BYTES", + net::NetLogCaptureMode::IncludeSocketBytes()); } // Make sure the export file has been successfully initialized after DO_STOP @@ -191,13 +193,13 @@ class NetLogTempFileTest : public ::testing::Test { void VerifyFileAndStateAfterStart( NetLogTempFile::LogType expected_log_type, const std::string& expected_log_type_string, - net::NetLog::LogLevel expected_log_level) const { + net::NetLogCaptureMode expected_capture_mode) const { EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); EXPECT_EQ("LOGGING", GetStateString()); EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); EXPECT_EQ(expected_log_type_string, GetLogTypeString()); - EXPECT_EQ(expected_log_level, net_log_->GetLogLevel()); + EXPECT_EQ(expected_capture_mode, net_log_->GetCaptureMode()); // Check GetFilePath returns false when still writing to the file. base::FilePath net_export_file_path; diff --git a/chrome/browser/net/predictor_browsertest.cc b/chrome/browser/net/predictor_browsertest.cc index 48b9d66..c0ff959 100644 --- a/chrome/browser/net/predictor_browsertest.cc +++ b/chrome/browser/net/predictor_browsertest.cc @@ -121,7 +121,7 @@ class ConnectNetLogObserver : public net::NetLog::ThreadSafeObserver { void Attach() { g_browser_process->net_log()->DeprecatedAddObserver( - this, net::NetLog::LOG_ALL_BUT_BYTES); + this, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } void Detach() { diff --git a/chrome/browser/resources/net_internals/browser_bridge.js b/chrome/browser/resources/net_internals/browser_bridge.js index 2031582..2b976a4c 100644 --- a/chrome/browser/resources/net_internals/browser_bridge.js +++ b/chrome/browser/resources/net_internals/browser_bridge.js @@ -215,8 +215,8 @@ var BrowserBridge = (function() { this.send('enableIPv6'); }, - setLogLevel: function(logLevel) { - this.send('setLogLevel', ['' + logLevel]); + setCaptureMode: function(captureMode) { + this.send('setCaptureMode', ['' + captureMode]); }, importONCFile: function(fileContent, passcode) { diff --git a/chrome/browser/resources/net_internals/capture_view.js b/chrome/browser/resources/net_internals/capture_view.js index 4b0a20f..244dc1c 100644 --- a/chrome/browser/resources/net_internals/capture_view.js +++ b/chrome/browser/resources/net_internals/capture_view.js @@ -85,7 +85,7 @@ var CaptureView = (function() { var byteLoggingCheckbox = $(CaptureView.BYTE_LOGGING_CHECKBOX_ID); if (byteLoggingCheckbox.checked) { - g_browser.setLogLevel(LogLevelType.LOG_ALL); + g_browser.setCaptureMode('IncludeSocketBytes'); // Once we enable byte logging, all bets are off on what gets captured. // Have the export view warn that the "strip cookies" option is @@ -97,7 +97,7 @@ var CaptureView = (function() { // reload. ExportView.getInstance().showPrivacyWarning(); } else { - g_browser.setLogLevel(LogLevelType.LOG_ALL_BUT_BYTES); + g_browser.setCaptureMode('IncludeCookiesAndCredentials'); } }, diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js index 0b49ad7..ab87b14 100644 --- a/chrome/browser/resources/net_internals/main.js +++ b/chrome/browser/resources/net_internals/main.js @@ -12,7 +12,6 @@ var EventTypeNames = null; var EventPhase = null; var EventSourceType = null; var EventSourceTypeNames = null; -var LogLevelType = null; var ClientInfo = null; var NetError = null; var QuicError = null; @@ -300,7 +299,6 @@ ConstantsObserver.prototype.onReceivedConstants = function(receivedConstants) { EventPhase = Constants.logEventPhase; EventSourceType = Constants.logSourceType; EventSourceTypeNames = makeInverseMap(EventSourceType); - LogLevelType = Constants.logLevelType; ClientInfo = Constants.clientInfo; LoadFlag = Constants.loadFlag; NetError = Constants.netError; @@ -331,7 +329,6 @@ function areValidConstants(receivedConstants) { typeof(receivedConstants.clientInfo) == 'object' && typeof(receivedConstants.logEventPhase) == 'object' && typeof(receivedConstants.logSourceType) == 'object' && - typeof(receivedConstants.logLevelType) == 'object' && typeof(receivedConstants.loadFlag) == 'object' && typeof(receivedConstants.netError) == 'object' && typeof(receivedConstants.addressFamily) == 'object' && diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc index 78ca7bc..c80cfbe 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc @@ -299,7 +299,7 @@ class NetInternalsMessageHandler::IOThreadImpl #if defined(OS_WIN) void OnGetServiceProviders(const base::ListValue* list); #endif - void OnSetLogLevel(const base::ListValue* list); + void OnSetCaptureMode(const base::ListValue* list); // ChromeNetLog::ThreadSafeObserver implementation: void OnAddEntry(const net::NetLog::Entry& entry) override; @@ -466,9 +466,8 @@ void NetInternalsMessageHandler::RegisterMessages() { #endif web_ui()->RegisterMessageCallback( - "setLogLevel", - base::Bind(&IOThreadImpl::CallbackHelper, - &IOThreadImpl::OnSetLogLevel, proxy_)); + "setCaptureMode", base::Bind(&IOThreadImpl::CallbackHelper, + &IOThreadImpl::OnSetCaptureMode, proxy_)); web_ui()->RegisterMessageCallback( "clearBrowserCache", base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache, @@ -683,8 +682,8 @@ void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady( PrePopulateEventList(); // Register with network stack to observe events. - io_thread_->net_log()->DeprecatedAddObserver(this, - net::NetLog::LOG_ALL_BUT_BYTES); + io_thread_->net_log()->DeprecatedAddObserver( + this, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } void NetInternalsMessageHandler::IOThreadImpl::OnGetNetInfo( @@ -1070,20 +1069,25 @@ void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted( } #endif // defined(OS_CHROMEOS) -void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel( +void NetInternalsMessageHandler::IOThreadImpl::OnSetCaptureMode( const base::ListValue* list) { - int log_level; - std::string log_level_string; - if (!list->GetString(0, &log_level_string) || - !base::StringToInt(log_level_string, &log_level)) { + std::string capture_mode_string; + if (!list->GetString(0, &capture_mode_string)) { NOTREACHED(); return; } - DCHECK_GE(log_level, net::NetLog::LOG_ALL); - DCHECK_LT(log_level, net::NetLog::LOG_NONE); - net_log()->SetObserverLogLevel( - this, static_cast<net::NetLog::LogLevel>(log_level)); + // Convert the string to a NetLogCaptureMode. + net::NetLogCaptureMode mode; + if (capture_mode_string == "IncludeSocketBytes") { + mode = net::NetLogCaptureMode::IncludeSocketBytes(); + } else if (capture_mode_string == "IncludeCookiesAndCredentials") { + mode = net::NetLogCaptureMode::IncludeCookiesAndCredentials(); + } else { + NOTREACHED(); + } + + net_log()->SetObserverCaptureMode(this, mode); } // Note that unlike other methods of IOThreadImpl, this function diff --git a/components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequestContext.java index f0207ec..03246f4 100644 --- a/components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequestContext.java +++ b/components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequestContext.java @@ -77,8 +77,8 @@ public class ChromiumUrlRequestContext { } /** - * Starts NetLog logging to a file. The NetLog log level used is - * LOG_ALL_BUT_BYTES. + * Starts NetLog logging to a file. The NetLog capture mode is + * NetLogCaptureMode::Default(). * @param fileName The complete file path. It must not be empty. If file * exists, it is truncated before starting. If actively logging, * this method is ignored. diff --git a/components/cronet/android/java/src/org/chromium/net/UrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/UrlRequestContext.java index 54eee3f..cddd64d 100644 --- a/components/cronet/android/java/src/org/chromium/net/UrlRequestContext.java +++ b/components/cronet/android/java/src/org/chromium/net/UrlRequestContext.java @@ -56,8 +56,8 @@ public abstract class UrlRequestContext { public abstract void shutdown(); /** - * Starts NetLog logging to a file. The NetLog log level used is - * LOG_ALL_BUT_BYTES. + * Starts NetLog logging to a file. The NetLog capture mode used is + * NetLogCaptureMode::Default(). * @param fileName The complete file path. It must not be empty. If file * exists, it is truncated before starting. If actively logging, * this method is ignored. diff --git a/components/cronet/android/url_request_context_adapter.cc b/components/cronet/android/url_request_context_adapter.cc index 45ed5fb..8fc3e02 100644 --- a/components/cronet/android/url_request_context_adapter.cc +++ b/components/cronet/android/url_request_context_adapter.cc @@ -199,8 +199,9 @@ void URLRequestContextAdapter::InitRequestContextOnNetworkThread() { if (VLOG_IS_ON(2)) { net_log_observer_.reset(new NetLogObserver()); - context_->net_log()->DeprecatedAddObserver(net_log_observer_.get(), - net::NetLog::LOG_ALL_BUT_BYTES); + context_->net_log()->DeprecatedAddObserver( + net_log_observer_.get(), + net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } is_context_initialized_ = true; diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.cc index e1f41d7..1ce6246 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.cc @@ -20,7 +20,8 @@ scoped_ptr<base::Value> BuildDataReductionProxyEvent( base::TimeTicks ticks_now = base::TimeTicks::Now(); net::NetLog::EntryData entry_data(type, source, phase, ticks_now, ¶meters_callback); - net::NetLog::Entry entry(&entry_data, net::NetLog::LOG_ALL); + net::NetLog::Entry entry(&entry_data, + net::NetLogCaptureMode::IncludeSocketBytes()); scoped_ptr<base::Value> entry_value(entry.ToValue()); return entry_value; @@ -52,7 +53,7 @@ base::Value* EnableDataReductionProxyCallback( const std::string& primary_origin, const std::string& fallback_origin, const std::string& ssl_origin, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetBoolean("enabled", true); dict->SetBoolean("primary_restricted", primary_restricted); @@ -67,7 +68,7 @@ base::Value* EnableDataReductionProxyCallback( // the Data Reduction Proxy. Ownership of the base::Value is passed to the // caller. base::Value* DisableDataReductionProxyCallback( - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetBoolean("enabled", false); return dict; @@ -76,11 +77,12 @@ base::Value* DisableDataReductionProxyCallback( // A callback which creates a base::Value containing information about bypassing // the Data Reduction Proxy. Ownership of the base::Value is passed to the // caller. -base::Value* UrlBypassActionCallback(const std::string& action, - const GURL& url, - int bypass_seconds, - int64 expiration_ticks, - net::NetLog::LogLevel /* log_level */) { +base::Value* UrlBypassActionCallback( + const std::string& action, + const GURL& url, + int bypass_seconds, + int64 expiration_ticks, + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("action", action); dict->SetString("url", url.spec()); @@ -98,7 +100,7 @@ base::Value* UrlBypassTypeCallback( const GURL& url, int bypass_seconds, int64 expiration_ticks, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("bypass_type", bypass_type); dict->SetString("url", url.spec()); @@ -111,10 +113,11 @@ base::Value* UrlBypassTypeCallback( // A callback which creates a base::Value containing information about // completing the Data Reduction Proxy secure proxy check. Ownership of the // base::Value is passed to the caller. -base::Value* EndCanaryRequestCallback(int net_error, - int http_response_code, - bool succeeded, - net::NetLog::LogLevel /* log_level */) { +base::Value* EndCanaryRequestCallback( + int net_error, + int http_response_code, + bool succeeded, + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); dict->SetInteger("http_response_code", http_response_code); diff --git a/content/browser/devtools/devtools_netlog_observer.cc b/content/browser/devtools/devtools_netlog_observer.cc index cb6b84f..f20ef34 100644 --- a/content/browser/devtools/devtools_netlog_observer.cc +++ b/content/browser/devtools/devtools_netlog_observer.cc @@ -169,7 +169,8 @@ void DevToolsNetLogObserver::Attach() { net::NetLog* net_log = GetContentClient()->browser()->GetNetLog(); if (net_log) { instance_ = new DevToolsNetLogObserver(); - net_log->DeprecatedAddObserver(instance_, net::NetLog::LOG_ALL_BUT_BYTES); + net_log->DeprecatedAddObserver( + instance_, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } } diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc index 203c689..4c8203d 100644 --- a/content/browser/download/download_file_impl.cc +++ b/content/browser/download/download_file_impl.cc @@ -337,7 +337,7 @@ void DownloadFileImpl::StreamActive() { &DownloadDestinationObserver::DestinationCompleted, observer_, hash)); } - if (bound_net_log_.IsLogging()) { + if (bound_net_log_.GetCaptureMode().enabled()) { bound_net_log_.AddEvent( net::NetLog::TYPE_DOWNLOAD_STREAM_DRAINED, base::Bind(&FileStreamDrainedNetLogCallback, total_incoming_data_size, diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc index a0dea56..dbcf7c4 100644 --- a/content/browser/download/download_item_impl.cc +++ b/content/browser/download/download_item_impl.cc @@ -1055,7 +1055,7 @@ void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, if (received_bytes_ > total_bytes_) total_bytes_ = 0; - if (bound_net_log_.IsLogging()) { + if (bound_net_log_.GetCaptureMode().enabled()) { bound_net_log_.AddEvent( net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); @@ -1106,8 +1106,8 @@ void DownloadItemImpl::Init(bool active, file_name = GetURL().ExtractFileName(); } - base::Callback<base::Value*(net::NetLog::LogLevel)> active_data = base::Bind( - &ItemActivatedNetLogCallback, this, download_type, &file_name); + net::NetLog::ParametersCallback active_data = + base::Bind(&ItemActivatedNetLogCallback, this, download_type, &file_name); if (active) { bound_net_log_.BeginEvent( net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); diff --git a/content/browser/download/download_net_log_parameters.cc b/content/browser/download/download_net_log_parameters.cc index 8fe755c..8d04ae1 100644 --- a/content/browser/download/download_net_log_parameters.cc +++ b/content/browser/download/download_net_log_parameters.cc @@ -41,11 +41,10 @@ static_assert(arraysize(download_danger_names) == DOWNLOAD_DANGER_TYPE_MAX, } // namespace -base::Value* ItemActivatedNetLogCallback( - const DownloadItem* download_item, - DownloadType download_type, - const std::string* file_name, - net::NetLog::LogLevel log_level) { +base::Value* ItemActivatedNetLogCallback(const DownloadItem* download_item, + DownloadType download_type, + const std::string* file_name, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("type", download_type_names[download_type]); @@ -62,9 +61,8 @@ base::Value* ItemActivatedNetLogCallback( return dict; } -base::Value* ItemCheckedNetLogCallback( - DownloadDangerType danger_type, - net::NetLog::LogLevel log_level) { +base::Value* ItemCheckedNetLogCallback(DownloadDangerType danger_type, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("danger_type", download_danger_names[danger_type]); @@ -74,7 +72,7 @@ base::Value* ItemCheckedNetLogCallback( base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename, const base::FilePath* new_filename, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); @@ -83,10 +81,11 @@ base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename, return dict; } -base::Value* ItemInterruptedNetLogCallback(DownloadInterruptReason reason, - int64 bytes_so_far, - const std::string* hash_state, - net::NetLog::LogLevel log_level) { +base::Value* ItemInterruptedNetLogCallback( + DownloadInterruptReason reason, + int64 bytes_so_far, + const std::string* hash_state, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); @@ -101,7 +100,7 @@ base::Value* ItemResumingNetLogCallback(bool user_initiated, DownloadInterruptReason reason, int64 bytes_so_far, const std::string* hash_state, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("user_initiated", user_initiated ? "true" : "false"); @@ -115,7 +114,7 @@ base::Value* ItemResumingNetLogCallback(bool user_initiated, base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far, const std::string* final_hash, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); @@ -126,7 +125,7 @@ base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far, } base::Value* ItemFinishedNetLogCallback(bool auto_opened, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("auto_opened", auto_opened ? "yes" : "no"); @@ -136,7 +135,7 @@ base::Value* ItemFinishedNetLogCallback(bool auto_opened, base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far, const std::string* hash_state, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); @@ -148,7 +147,7 @@ base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far, base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name, int64 start_offset, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("file_name", file_name->AsUTF8Unsafe()); @@ -157,9 +156,10 @@ base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name, return dict; } -base::Value* FileStreamDrainedNetLogCallback(size_t stream_size, - size_t num_buffers, - net::NetLog::LogLevel log_level) { +base::Value* FileStreamDrainedNetLogCallback( + size_t stream_size, + size_t num_buffers, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_size", static_cast<int>(stream_size)); @@ -170,7 +170,7 @@ base::Value* FileStreamDrainedNetLogCallback(size_t stream_size, base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename, const base::FilePath* new_filename, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); @@ -181,7 +181,7 @@ base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename, base::Value* FileErrorNetLogCallback(const char* operation, net::Error net_error, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("operation", operation); @@ -190,10 +190,11 @@ base::Value* FileErrorNetLogCallback(const char* operation, return dict; } -base::Value* FileInterruptedNetLogCallback(const char* operation, - int os_error, - DownloadInterruptReason reason, - net::NetLog::LogLevel log_level) { +base::Value* FileInterruptedNetLogCallback( + const char* operation, + int os_error, + DownloadInterruptReason reason, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("operation", operation); diff --git a/content/browser/download/download_net_log_parameters.h b/content/browser/download/download_net_log_parameters.h index 6d027cf..de0c957 100644 --- a/content/browser/download/download_net_log_parameters.h +++ b/content/browser/download/download_net_log_parameters.h @@ -26,74 +26,73 @@ enum DownloadType { }; // Returns NetLog parameters when a DownloadItem is activated. -base::Value* ItemActivatedNetLogCallback( - const DownloadItem* download_item, - DownloadType download_type, - const std::string* file_name, - net::NetLog::LogLevel log_level); +base::Value* ItemActivatedNetLogCallback(const DownloadItem* download_item, + DownloadType download_type, + const std::string* file_name, + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is checked for danger. -base::Value* ItemCheckedNetLogCallback( - DownloadDangerType danger_type, - net::NetLog::LogLevel log_level); +base::Value* ItemCheckedNetLogCallback(DownloadDangerType danger_type, + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is renamed. base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename, const base::FilePath* new_filename, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is interrupted. base::Value* ItemInterruptedNetLogCallback(DownloadInterruptReason reason, int64 bytes_so_far, const std::string* hash_state, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is resumed. base::Value* ItemResumingNetLogCallback(bool user_initiated, DownloadInterruptReason reason, int64 bytes_so_far, const std::string* hash_state, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is completing. base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far, const std::string* final_hash, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is finished. base::Value* ItemFinishedNetLogCallback(bool auto_opened, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadItem is canceled. base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far, const std::string* hash_state, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadFile is opened. base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name, int64 start_offset, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadFile is opened. -base::Value* FileStreamDrainedNetLogCallback(size_t stream_size, - size_t num_buffers, - net::NetLog::LogLevel log_level); +base::Value* FileStreamDrainedNetLogCallback( + size_t stream_size, + size_t num_buffers, + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a DownloadFile is renamed. base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename, const base::FilePath* new_filename, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters when a File has an error. base::Value* FileErrorNetLogCallback(const char* operation, net::Error net_error, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); // Returns NetLog parameters for a download interruption. base::Value* FileInterruptedNetLogCallback(const char* operation, int os_error, DownloadInterruptReason reason, - net::NetLog::LogLevel log_level); + net::NetLogCaptureMode capture_mode); } // namespace content diff --git a/content/browser/media/media_internals_proxy.cc b/content/browser/media/media_internals_proxy.cc index 2181caa..05f4dd8 100644 --- a/content/browser/media/media_internals_proxy.cc +++ b/content/browser/media/media_internals_proxy.cc @@ -122,7 +122,8 @@ void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() { MediaInternals::GetInstance()->AddUpdateCallback(update_callback_); if (GetContentClient()->browser()->GetNetLog()) { net::NetLog* net_log = GetContentClient()->browser()->GetNetLog(); - net_log->DeprecatedAddObserver(this, net::NetLog::LOG_ALL_BUT_BYTES); + net_log->DeprecatedAddObserver( + this, net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } } diff --git a/extensions/browser/api/web_request/web_request_api_helpers.cc b/extensions/browser/api/web_request/web_request_api_helpers.cc index 160462a..73a8dd8 100644 --- a/extensions/browser/api/web_request/web_request_api_helpers.cc +++ b/extensions/browser/api/web_request/web_request_api_helpers.cc @@ -218,9 +218,8 @@ net::NetLog::ParametersCallback CreateNetLogExtensionIdCallback( // Creates NetLog parameters to indicate that an extension modified a request. // Caller takes ownership of returned value. -base::Value* NetLogModificationCallback( - const EventResponseDelta* delta, - net::NetLog::LogLevel log_level) { +base::Value* NetLogModificationCallback(const EventResponseDelta* delta, + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("extension_id", delta->extension_id); diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index 69aac65..0f464c5 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -359,7 +359,8 @@ void MCSProbe::InitializeNetworkState() { } if (log_file.get()) { logger_.reset(new net::WriteToFileNetLogObserver()); - logger_->set_log_level(net::NetLog::LOG_ALL_BUT_BYTES); + logger_->set_capture_mode( + net::NetLogCaptureMode::IncludeCookiesAndCredentials()); logger_->StartObserving(&net_log_, log_file.Pass(), nullptr, nullptr); } diff --git a/net/base/address_list.cc b/net/base/address_list.cc index 02a762b..a62b5d0 100644 --- a/net/base/address_list.cc +++ b/net/base/address_list.cc @@ -15,7 +15,7 @@ namespace net { namespace { base::Value* NetLogAddressListCallback(const AddressList* address_list, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* list = new base::ListValue(); diff --git a/net/base/sdch_net_log_params.cc b/net/base/sdch_net_log_params.cc index 02e0ad7..a89117e 100644 --- a/net/base/sdch_net_log_params.cc +++ b/net/base/sdch_net_log_params.cc @@ -11,7 +11,7 @@ namespace net { base::Value* NetLogSdchResourceProblemCallback(SdchProblemCode problem, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("sdch_problem_code", problem); dict->SetInteger("net_error", ERR_FAILED); @@ -22,7 +22,7 @@ base::Value* NetLogSdchDictionaryFetchProblemCallback( SdchProblemCode problem, const GURL& url, bool is_error, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("sdch_problem_code", problem); dict->SetString("dictionary_url", url.spec()); diff --git a/net/base/sdch_net_log_params.h b/net/base/sdch_net_log_params.h index 1849f96..a13d9de 100644 --- a/net/base/sdch_net_log_params.h +++ b/net/base/sdch_net_log_params.h @@ -17,7 +17,7 @@ namespace net { NET_EXPORT base::Value* NetLogSdchResourceProblemCallback( SdchProblemCode problem, - NetLog::LogLevel log_level); + NetLogCaptureMode capture_mode); // If |is_error| is false, "net_error" field won't be added to the JSON and the // event won't be painted red in the netlog. @@ -25,7 +25,7 @@ NET_EXPORT base::Value* NetLogSdchDictionaryFetchProblemCallback( SdchProblemCode problem, const GURL& url, bool is_error, - NetLog::LogLevel log_level); + NetLogCaptureMode capture_mode); } // namespace net diff --git a/net/cert/cert_policy_enforcer.cc b/net/cert/cert_policy_enforcer.cc index d4bae50..4c6d38d 100644 --- a/net/cert/cert_policy_enforcer.cc +++ b/net/cert/cert_policy_enforcer.cc @@ -185,11 +185,12 @@ struct ComplianceDetails { base::Version whitelist_version; }; -base::Value* NetLogComplianceCheckResultCallback(X509Certificate* cert, - ComplianceDetails* details, - NetLog::LogLevel log_level) { +base::Value* NetLogComplianceCheckResultCallback( + X509Certificate* cert, + ComplianceDetails* details, + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); - dict->Set("certificate", NetLogX509CertificateCallback(cert, log_level)); + dict->Set("certificate", NetLogX509CertificateCallback(cert, capture_mode)); dict->SetBoolean("policy_enforcement_required", details->ct_presence_required); if (details->ct_presence_required) { diff --git a/net/cert/ct_signed_certificate_timestamp_log_param.cc b/net/cert/ct_signed_certificate_timestamp_log_param.cc index e7bb97c..71c8469 100644 --- a/net/cert/ct_signed_certificate_timestamp_log_param.cc +++ b/net/cert/ct_signed_certificate_timestamp_log_param.cc @@ -129,7 +129,8 @@ base::ListValue* SCTListToPrintableValues( } // namespace base::Value* NetLogSignedCertificateTimestampCallback( - const ct::CTVerifyResult* ct_result, NetLog::LogLevel log_level) { + const ct::CTVerifyResult* ct_result, + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->Set("verified_scts", @@ -148,7 +149,7 @@ base::Value* NetLogRawSignedCertificateTimestampCallback( const std::string* embedded_scts, const std::string* sct_list_from_ocsp, const std::string* sct_list_from_tls_extension, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); SetBinaryData("embedded_scts", *embedded_scts, dict); diff --git a/net/cert/ct_signed_certificate_timestamp_log_param.h b/net/cert/ct_signed_certificate_timestamp_log_param.h index 5c4db19..25e1fb5 100644 --- a/net/cert/ct_signed_certificate_timestamp_log_param.h +++ b/net/cert/ct_signed_certificate_timestamp_log_param.h @@ -18,7 +18,8 @@ struct CTVerifyResult; // See the documentation for SIGNED_CERTIFICATE_TIMESTAMPS_CHECKED // in net/log/net_log_event_type_list.h base::Value* NetLogSignedCertificateTimestampCallback( - const ct::CTVerifyResult* ct_result, NetLog::LogLevel log_level); + const ct::CTVerifyResult* ct_result, + NetLogCaptureMode capture_mode); // Creates a dictionary of raw Signed Certificate Timestamps to be logged // in the NetLog. @@ -28,7 +29,7 @@ base::Value* NetLogRawSignedCertificateTimestampCallback( const std::string* embedded_scts, const std::string* sct_list_from_ocsp, const std::string* sct_list_from_tls_extension, - NetLog::LogLevel log_level); + NetLogCaptureMode capture_mode); } // namespace net diff --git a/net/cert/multi_threaded_cert_verifier.cc b/net/cert/multi_threaded_cert_verifier.cc index 9e78abb..128987f 100644 --- a/net/cert/multi_threaded_cert_verifier.cc +++ b/net/cert/multi_threaded_cert_verifier.cc @@ -82,7 +82,7 @@ const unsigned kMaxCacheEntries = 256; const unsigned kTTLSecs = 1800; // 30 minutes. base::Value* CertVerifyResultCallback(const CertVerifyResult& verify_result, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* results = new base::DictionaryValue(); results->SetBoolean("has_md5", verify_result.has_md5); results->SetBoolean("has_md2", verify_result.has_md2); @@ -96,7 +96,7 @@ base::Value* CertVerifyResultCallback(const CertVerifyResult& verify_result, results->SetInteger("cert_status", verify_result.cert_status); results->Set("verified_cert", NetLogX509CertificateCallback(verify_result.verified_cert.get(), - log_level)); + capture_mode)); base::ListValue* hashes = new base::ListValue(); for (std::vector<HashValue>::const_iterator it = diff --git a/net/cert/x509_certificate_net_log_param.cc b/net/cert/x509_certificate_net_log_param.cc index 3c52b96..a9445c6 100644 --- a/net/cert/x509_certificate_net_log_param.cc +++ b/net/cert/x509_certificate_net_log_param.cc @@ -13,7 +13,7 @@ namespace net { base::Value* NetLogX509CertificateCallback(const X509Certificate* certificate, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* certs = new base::ListValue(); std::vector<std::string> encoded_chain; diff --git a/net/cert/x509_certificate_net_log_param.h b/net/cert/x509_certificate_net_log_param.h index 822cb53..9e3e3a9 100644 --- a/net/cert/x509_certificate_net_log_param.h +++ b/net/cert/x509_certificate_net_log_param.h @@ -12,9 +12,8 @@ namespace net { class X509Certificate; // Creates NetLog parameter to describe an X509Certificate. -base::Value* NetLogX509CertificateCallback( - const X509Certificate* certificate, - NetLog::LogLevel log_level); +base::Value* NetLogX509CertificateCallback(const X509Certificate* certificate, + NetLogCaptureMode capture_mode); } // namespace net diff --git a/net/disk_cache/blockfile/entry_impl.cc b/net/disk_cache/blockfile/entry_impl.cc index 76bf7c7..add38de 100644 --- a/net/disk_cache/blockfile/entry_impl.cc +++ b/net/disk_cache/blockfile/entry_impl.cc @@ -62,7 +62,7 @@ class SyncCallback: public disk_cache::FileIOCallback { void SyncCallback::OnFileIOComplete(int bytes_copied) { entry_->DecrementIoCount(); if (!callback_.is_null()) { - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().EndEvent( end_event_type_, disk_cache::CreateNetLogReadWriteCompleteCallback(bytes_copied)); @@ -315,7 +315,7 @@ void EntryImpl::DoomImpl() { int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -323,7 +323,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len, callback); - if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { + if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -334,7 +334,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -343,7 +343,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, callback, truncate); - if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { + if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); diff --git a/net/disk_cache/blockfile/entry_impl_v3.cc b/net/disk_cache/blockfile/entry_impl_v3.cc index 04e9ad9..78ef1b8 100644 --- a/net/disk_cache/blockfile/entry_impl_v3.cc +++ b/net/disk_cache/blockfile/entry_impl_v3.cc @@ -547,7 +547,7 @@ int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -555,7 +555,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len, callback); - if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { + if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -586,7 +586,7 @@ int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -595,7 +595,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, callback, truncate); - if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { + if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); diff --git a/net/disk_cache/blockfile/sparse_control.cc b/net/disk_cache/blockfile/sparse_control.cc index e5096dc..8ce659da0 100644 --- a/net/disk_cache/blockfile/sparse_control.cc +++ b/net/disk_cache/blockfile/sparse_control.cc @@ -161,7 +161,7 @@ net::NetLog::EventType GetSparseEventType( void LogChildOperationEnd(const net::BoundNetLog& net_log, disk_cache::SparseControl::SparseOperation operation, int result) { - if (net_log.IsLogging()) { + if (net_log.GetCaptureMode().enabled()) { net::NetLog::EventType event_type; switch (operation) { case disk_cache::SparseControl::kReadOperation: @@ -275,7 +275,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( GetSparseEventType(operation_), CreateNetLogSparseOperationCallback(offset_, buf_len_)); @@ -679,14 +679,14 @@ void SparseControl::DoChildrenIO() { // Range operations are finished synchronously, often without setting // |finished_| to true. if (kGetRangeOperation == operation_ && - entry_->net_log().IsLogging()) { + entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().EndEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); } if (finished_) { if (kGetRangeOperation != operation_ && - entry_->net_log().IsLogging()) { + entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().EndEvent(GetSparseEventType(operation_)); } if (pending_) @@ -716,7 +716,7 @@ bool SparseControl::DoChildIO() { int rv = 0; switch (operation_) { case kReadOperation: - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -726,7 +726,7 @@ bool SparseControl::DoChildIO() { child_len_, callback); break; case kWriteOperation: - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -856,7 +856,7 @@ void SparseControl::OnChildIOCompleted(int result) { // We'll return the current result of the operation, which may be less than // the bytes to read or write, but the user cancelled the operation. abort_ = false; - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); entry_->net_log().EndEvent(GetSparseEventType(operation_)); } diff --git a/net/disk_cache/blockfile/sparse_control_v3.cc b/net/disk_cache/blockfile/sparse_control_v3.cc index cba0ed5..742009f 100644 --- a/net/disk_cache/blockfile/sparse_control_v3.cc +++ b/net/disk_cache/blockfile/sparse_control_v3.cc @@ -163,7 +163,7 @@ net::NetLog::EventType GetSparseEventType( void LogChildOperationEnd(const net::BoundNetLog& net_log, disk_cache::SparseControl::SparseOperation operation, int result) { - if (net_log.IsLogging()) { + if (net_log.GetCaptureMode().enabled()) { net::NetLog::EventType event_type; switch (operation) { case disk_cache::SparseControl::kReadOperation: @@ -254,7 +254,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( GetSparseEventType(operation_), CreateNetLogSparseOperationCallback(offset_, buf_len_)); @@ -563,7 +563,7 @@ bool SparseControl::DoChildIO() { int rv = 0; switch (operation_) { case kReadOperation: - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -573,7 +573,7 @@ bool SparseControl::DoChildIO() { child_len_, callback); break; case kWriteOperation: - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -846,7 +846,7 @@ void SparseControl::OnChildIOCompleted(int result) { // We'll return the current result of the operation, which may be less than // the bytes to read or write, but the user cancelled the operation. abort_ = false; - if (entry_->net_log().IsLogging()) { + if (entry_->net_log().GetCaptureMode().enabled()) { entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); entry_->net_log().EndEvent(GetSparseEventType(operation_)); } diff --git a/net/disk_cache/memory/mem_entry_impl.cc b/net/disk_cache/memory/mem_entry_impl.cc index 7c6199b..c1dc8cf 100644 --- a/net/disk_cache/memory/mem_entry_impl.cc +++ b/net/disk_cache/memory/mem_entry_impl.cc @@ -48,7 +48,7 @@ std::string GenerateChildName(const std::string& base_name, int child_id) { base::Value* NetLogChildEntryCreationCallback( const disk_cache::MemEntryImpl* parent, int child_id, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("key", GenerateChildName(parent->GetKey(), child_id)); dict->SetBoolean("created", true); @@ -185,7 +185,7 @@ int32 MemEntryImpl::GetDataSize(int index) const { int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -193,7 +193,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -203,7 +203,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -211,7 +211,7 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, truncate); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -221,39 +221,39 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int MemEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_READ, CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalReadSparseData(offset, buf, buf_len); - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ); return result; } int MemEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_WRITE, CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalWriteSparseData(offset, buf, buf_len); - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE); return result; } int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, const CompletionCallback& callback) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogSparseOperationCallback(offset, len)); } int result = GetAvailableRange(offset, len, start); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogGetAvailableRangeResultCallback(*start, result)); @@ -373,7 +373,7 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, IOBuffer* buf, // we should stop. if (child_offset < child->child_first_pos_) break; - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child->net_log().source(), @@ -381,7 +381,7 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, IOBuffer* buf, } int ret = child->ReadData(kSparseData, child_offset, io_buf.get(), io_buf->BytesRemaining(), CompletionCallback()); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret); } @@ -430,7 +430,7 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, IOBuffer* buf, // Keep a record of the last byte position (exclusive) in the child. int data_size = child->GetDataSize(kSparseData); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child->net_log().source(), @@ -443,7 +443,7 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, IOBuffer* buf, // continuous we may want to discard this write. int ret = child->WriteData(kSparseData, child_offset, io_buf.get(), write_len, CompletionCallback(), true); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret); } diff --git a/net/disk_cache/net_log_parameters.cc b/net/disk_cache/net_log_parameters.cc index 5d7e50f..b13f916 100644 --- a/net/disk_cache/net_log_parameters.cc +++ b/net/disk_cache/net_log_parameters.cc @@ -16,7 +16,7 @@ namespace { base::Value* NetLogEntryCreationCallback( const disk_cache::Entry* entry, bool created, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("key", entry->GetKey()); dict->SetBoolean("created", created); @@ -28,7 +28,7 @@ base::Value* NetLogReadWriteDataCallback( int offset, int buf_len, bool truncate, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("index", index); dict->SetInteger("offset", offset); @@ -40,7 +40,7 @@ base::Value* NetLogReadWriteDataCallback( base::Value* NetLogReadWriteCompleteCallback( int bytes_copied, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { DCHECK_NE(bytes_copied, net::ERR_IO_PENDING); base::DictionaryValue* dict = new base::DictionaryValue(); if (bytes_copied < 0) { @@ -54,7 +54,7 @@ base::Value* NetLogReadWriteCompleteCallback( base::Value* NetLogSparseOperationCallback( int64 offset, int buff_len, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); // Values can only be created with at most 32-bit integers. Using a string // instead circumvents that restriction. @@ -66,7 +66,7 @@ base::Value* NetLogSparseOperationCallback( base::Value* NetLogSparseReadWriteCallback( const net::NetLog::Source& source, int child_len, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); source.AddToEventParameters(dict); dict->SetInteger("child_len", child_len); @@ -76,7 +76,7 @@ base::Value* NetLogSparseReadWriteCallback( base::Value* NetLogGetAvailableRangeResultCallback( int64 start, int result, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); if (result > 0) { dict->SetInteger("length", result); diff --git a/net/disk_cache/simple/simple_entry_impl.cc b/net/disk_cache/simple/simple_entry_impl.cc index f8f1b85..a062dc2 100644 --- a/net/disk_cache/simple/simple_entry_impl.cc +++ b/net/disk_cache/simple/simple_entry_impl.cc @@ -347,7 +347,7 @@ int SimpleEntryImpl::ReadData(int stream_index, const CompletionCallback& callback) { DCHECK(io_thread_checker_.CalledOnValidThread()); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_CALL, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, false)); @@ -355,7 +355,7 @@ int SimpleEntryImpl::ReadData(int stream_index, if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || buf_len < 0) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); } @@ -365,7 +365,7 @@ int SimpleEntryImpl::ReadData(int stream_index, } if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len)) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(0)); } @@ -394,7 +394,7 @@ int SimpleEntryImpl::WriteData(int stream_index, bool truncate) { DCHECK(io_thread_checker_.CalledOnValidThread()); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_CALL, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -403,7 +403,7 @@ int SimpleEntryImpl::WriteData(int stream_index, if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || offset < 0 || buf_len < 0) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); @@ -412,7 +412,7 @@ int SimpleEntryImpl::WriteData(int stream_index, return net::ERR_INVALID_ARGUMENT; } if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -454,7 +454,7 @@ int SimpleEntryImpl::WriteData(int stream_index, } op_callback = CompletionCallback(); ret_value = buf_len; - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC, CreateNetLogReadWriteCompleteCallback(buf_len)); @@ -809,7 +809,7 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index, DCHECK(io_thread_checker_.CalledOnValidThread()); ScopedOperationRunner operation_runner(this); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_BEGIN, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -825,7 +825,7 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index, base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(callback, net::ERR_FAILED)); } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -892,7 +892,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, DCHECK(io_thread_checker_.CalledOnValidThread()); ScopedOperationRunner operation_runner(this); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_BEGIN, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -901,7 +901,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -1230,7 +1230,7 @@ void SimpleEntryImpl::ReadOperationComplete( crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE; } } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(*result)); @@ -1248,7 +1248,7 @@ void SimpleEntryImpl::WriteOperationComplete( RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); else RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(*result)); } @@ -1319,7 +1319,7 @@ void SimpleEntryImpl::ChecksumOperationComplete( DCHECK_EQ(STATE_IO_PENDING, state_); DCHECK(result); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEventWithNetErrorCode( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, *result); @@ -1334,7 +1334,7 @@ void SimpleEntryImpl::ChecksumOperationComplete( } else { RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE); } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(*result)); } diff --git a/net/disk_cache/simple/simple_net_log_parameters.cc b/net/disk_cache/simple/simple_net_log_parameters.cc index 4756c83..f3d9fe5 100644 --- a/net/disk_cache/simple/simple_net_log_parameters.cc +++ b/net/disk_cache/simple/simple_net_log_parameters.cc @@ -17,7 +17,7 @@ namespace { base::Value* NetLogSimpleEntryConstructionCallback( const disk_cache::SimpleEntryImpl* entry, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("entry_hash", base::StringPrintf("%#016" PRIx64, entry->entry_hash())); @@ -27,7 +27,7 @@ base::Value* NetLogSimpleEntryConstructionCallback( base::Value* NetLogSimpleEntryCreationCallback( const disk_cache::SimpleEntryImpl* entry, int net_error, - net::NetLog::LogLevel /* log_level */) { + net::NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); if (net_error == net::OK) diff --git a/net/dns/dns_transaction.cc b/net/dns/dns_transaction.cc index 8c0b28b..0147092 100644 --- a/net/dns/dns_transaction.cc +++ b/net/dns/dns_transaction.cc @@ -59,8 +59,8 @@ bool IsIPLiteral(const std::string& hostname) { } base::Value* NetLogStartCallback(const std::string* hostname, - uint16 qtype, - NetLog::LogLevel /* log_level */) { + uint16 qtype, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("hostname", *hostname); dict->SetInteger("query_type", qtype); @@ -98,7 +98,7 @@ class DnsAttempt { // Returns a Value representing the received response, along with a reference // to the NetLog source source of the UDP socket used. The request must have // completed before this is called. - base::Value* NetLogResponseCallback(NetLog::LogLevel log_level) const { + base::Value* NetLogResponseCallback(NetLogCaptureMode capture_mode) const { DCHECK(GetResponse()->IsValid()); base::DictionaryValue* dict = new base::DictionaryValue(); diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc index 35ea2fa..5e050c6 100644 --- a/net/dns/host_resolver_impl.cc +++ b/net/dns/host_resolver_impl.cc @@ -297,10 +297,11 @@ bool IsAllIPv4Loopback(const AddressList& addresses) { } // Creates NetLog parameters when the resolve failed. -base::Value* NetLogProcTaskFailedCallback(uint32 attempt_number, - int net_error, - int os_error, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogProcTaskFailedCallback( + uint32 attempt_number, + int net_error, + int os_error, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); if (attempt_number) dict->SetInteger("attempt_number", attempt_number); @@ -332,7 +333,7 @@ base::Value* NetLogProcTaskFailedCallback(uint32 attempt_number, // Creates NetLog parameters when the DnsTask failed. base::Value* NetLogDnsTaskFailedCallback(int net_error, int dns_error, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); if (dns_error) @@ -343,7 +344,7 @@ base::Value* NetLogDnsTaskFailedCallback(int net_error, // Creates NetLog parameters containing the information in a RequestInfo object, // along with the associated NetLog::Source. base::Value* NetLogRequestInfoCallback(const HostResolver::RequestInfo* info, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host", info->host_port_pair().ToString()); @@ -357,7 +358,7 @@ base::Value* NetLogRequestInfoCallback(const HostResolver::RequestInfo* info, // Creates NetLog parameters for the creation of a HostResolverImpl::Job. base::Value* NetLogJobCreationCallback(const NetLog::Source& source, const std::string* host, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); source.AddToEventParameters(dict); dict->SetString("host", *host); @@ -367,7 +368,7 @@ base::Value* NetLogJobCreationCallback(const NetLog::Source& source, // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events. base::Value* NetLogJobAttachCallback(const NetLog::Source& source, RequestPriority priority, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); source.AddToEventParameters(dict); dict->SetString("priority", RequestPriorityToString(priority)); @@ -376,7 +377,7 @@ base::Value* NetLogJobAttachCallback(const NetLog::Source& source, // Creates NetLog parameters for the DNS_CONFIG_CHANGED event. base::Value* NetLogDnsConfigCallback(const DnsConfig* config, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { return config->ToValue(); } diff --git a/net/filter/sdch_filter.cc b/net/filter/sdch_filter.cc index 6b52d8f..858e101 100644 --- a/net/filter/sdch_filter.cc +++ b/net/filter/sdch_filter.cc @@ -93,7 +93,7 @@ const char* ResponseCorruptionDetectionCauseToString( base::Value* NetLogSdchResponseCorruptionDetectionCallback( ResponseCorruptionDetectionCause cause, bool cached, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("cause", ResponseCorruptionDetectionCauseToString(cause)); dict->SetBoolean("cached", cached); diff --git a/net/ftp/ftp_ctrl_response_buffer.cc b/net/ftp/ftp_ctrl_response_buffer.cc index f7b1467..36486b7 100644 --- a/net/ftp/ftp_ctrl_response_buffer.cc +++ b/net/ftp/ftp_ctrl_response_buffer.cc @@ -80,7 +80,7 @@ int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { namespace { base::Value* NetLogFtpCtrlResponseCallback(const FtpCtrlResponse* response, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::ListValue* lines = new base::ListValue(); lines->AppendStrings(response->lines); diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index 5d6dc4d..cebecda 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -228,7 +228,7 @@ void RecordNoStoreHeaderHistogram(int load_flags, base::Value* NetLogAsyncRevalidationInfoCallback( const net::NetLog::Source& source, const net::HttpRequestInfo* request, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); source.AddToEventParameters(dict); @@ -1645,7 +1645,7 @@ int HttpCache::Transaction::DoTruncateCachedData() { next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; if (!entry_) return OK; - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); // Truncate the stream. return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); @@ -1653,7 +1653,7 @@ int HttpCache::Transaction::DoTruncateCachedData() { int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { if (entry_) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result); } @@ -1668,14 +1668,14 @@ int HttpCache::Transaction::DoTruncateCachedMetadata() { if (!entry_) return OK; - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); } int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { if (entry_) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result); } @@ -1812,7 +1812,7 @@ int HttpCache::Transaction::DoCacheWriteResponse() { "422516 HttpCache::Transaction::DoCacheWriteResponse")); if (entry_) { - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); } return WriteResponseInfoToEntry(false); @@ -1820,7 +1820,7 @@ int HttpCache::Transaction::DoCacheWriteResponse() { int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { if (entry_) { - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); } return WriteResponseInfoToEntry(true); @@ -1831,7 +1831,7 @@ int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { target_state_ = STATE_NONE; if (!entry_) return OK; - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result); } @@ -1883,7 +1883,7 @@ int HttpCache::Transaction::DoCacheReadData() { DCHECK(entry_); next_state_ = STATE_CACHE_READ_DATA_COMPLETE; - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); if (partial_.get()) { return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, @@ -1896,7 +1896,7 @@ int HttpCache::Transaction::DoCacheReadData() { } int HttpCache::Transaction::DoCacheReadDataComplete(int result) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, result); } @@ -1927,7 +1927,7 @@ int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; write_len_ = num_bytes; if (entry_) { - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); } @@ -1936,7 +1936,7 @@ int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { if (entry_) { - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result); } @@ -2758,7 +2758,7 @@ int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { if ((response_.headers->HasHeaderValue("cache-control", "no-store")) || net::IsCertStatusError(response_.ssl_info.cert_status)) { DoneWritingToEntry(false); - if (net_log_.IsLogging()) + if (net_log_.GetCaptureMode().enabled()) net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); return OK; } diff --git a/net/http/http_log_util.cc b/net/http/http_log_util.cc index 7e93911..0467fb6 100644 --- a/net/http/http_log_util.cc +++ b/net/http/http_log_util.cc @@ -34,15 +34,14 @@ bool ShouldRedactChallenge(HttpAuthChallengeTokenizer* challenge) { } // namespace -std::string ElideHeaderValueForNetLog(NetLog::LogLevel log_level, +std::string ElideHeaderValueForNetLog(NetLogCaptureMode capture_mode, const std::string& header, const std::string& value) { std::string::const_iterator redact_begin = value.begin(); std::string::const_iterator redact_end = value.begin(); if (redact_begin == redact_end && - log_level >= NetLog::LOG_STRIP_PRIVATE_DATA) { - + !capture_mode.include_cookies_and_credentials()) { // Note: this logic should be kept in sync with stripCookiesAndLoginInfo in // chrome/browser/resources/net_internals/log_view_painter.js. diff --git a/net/http/http_log_util.h b/net/http/http_log_util.h index 6894809..7758943 100644 --- a/net/http/http_log_util.h +++ b/net/http/http_log_util.h @@ -15,7 +15,7 @@ namespace net { // Given an HTTP header |header| with value |value|, returns the elided version // of the header value at |log_level|. NET_EXPORT_PRIVATE std::string ElideHeaderValueForNetLog( - NetLog::LogLevel log_level, + NetLogCaptureMode capture_mode, const std::string& header, const std::string& value); diff --git a/net/http/http_log_util_unittest.cc b/net/http/http_log_util_unittest.cc index dd6af69..bd9c79f 100644 --- a/net/http/http_log_util_unittest.cc +++ b/net/http/http_log_util_unittest.cc @@ -9,50 +9,63 @@ namespace net { TEST(HttpLogUtilTest, ElideHeaderValueForNetLog) { // Only elide for appropriate log level. - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Cookie", "name=value")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), "Cookie", + "name=value")); EXPECT_EQ("name=value", ElideHeaderValueForNetLog( - NetLog::LOG_ALL_BUT_BYTES, "Cookie", "name=value")); + NetLogCaptureMode::IncludeCookiesAndCredentials(), + "Cookie", "name=value")); // Headers are compared case insensitively. - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "cOoKiE", "name=value")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), "cOoKiE", + "name=value")); // These headers should be completely elided. - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie", "name=value")); - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie2", "name=value")); - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Authorization", "Basic 1234")); - EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authorization", "Basic 1234")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Set-Cookie", "name=value")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Set-Cookie2", "name=value")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Authorization", "Basic 1234")); + EXPECT_EQ("[10 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Proxy-Authorization", "Basic 1234")); // Unknown headers should pass through. - EXPECT_EQ("value", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Boring", "value")); + EXPECT_EQ("value", ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Boring", "value")); // Basic and Digest auth challenges are public. + EXPECT_EQ("Basic realm=test", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "WWW-Authenticate", "Basic realm=test")); + EXPECT_EQ("Digest realm=test", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "WWW-Authenticate", "Digest realm=test")); EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Basic realm=test")); - EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Digest realm=test")); - EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, - "Proxy-Authenticate", "Basic realm=test")); - EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, - "Proxy-Authenticate", "Digest realm=test")); + NetLogCaptureMode::Default(), + "Proxy-Authenticate", "Basic realm=test")); + EXPECT_EQ( + "Digest realm=test", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Proxy-Authenticate", "Digest realm=test")); // Multi-round mechanisms partially elided. - EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM 1234")); - EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authenticate", "NTLM 1234")); + EXPECT_EQ("NTLM [4 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "WWW-Authenticate", "NTLM 1234")); + EXPECT_EQ("NTLM [4 bytes were stripped]", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "Proxy-Authenticate", "NTLM 1234")); // Leave whitespace intact. - EXPECT_EQ("NTLM [4 bytes were stripped] ", ElideHeaderValueForNetLog( - NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM 1234 ")); + EXPECT_EQ("NTLM [4 bytes were stripped] ", + ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), + "WWW-Authenticate", "NTLM 1234 ")); } } // namspace net diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index b5e5d5c..3e9074ac 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -97,7 +97,7 @@ base::Value* NetLogSSLVersionFallbackCallback( int net_error, uint16 version_before, uint16 version_after, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host_and_port", GetHostAndPort(*url)); dict->SetInteger("net_error", net_error); @@ -106,9 +106,10 @@ base::Value* NetLogSSLVersionFallbackCallback( return dict; } -base::Value* NetLogSSLCipherFallbackCallback(const GURL* url, - int net_error, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogSSLCipherFallbackCallback( + const GURL* url, + int net_error, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host_and_port", GetHostAndPort(*url)); dict->SetInteger("net_error", net_error); diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 1c677db..a1bba94e 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -329,7 +329,7 @@ class HttpNetworkTransactionTest TestCompletionCallback callback; - EXPECT_TRUE(log.bound().IsLogging()); + EXPECT_TRUE(log.bound().GetCaptureMode().enabled()); int rv = trans->Start(&request, callback.callback(), log.bound()); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/http/http_request_headers.cc b/net/http/http_request_headers.cc index f0b7cfb..eaeec0d 100644 --- a/net/http/http_request_headers.cc +++ b/net/http/http_request_headers.cc @@ -190,14 +190,14 @@ std::string HttpRequestHeaders::ToString() const { base::Value* HttpRequestHeaders::NetLogCallback( const std::string* request_line, - NetLog::LogLevel log_level) const { + NetLogCaptureMode capture_mode) const { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("line", *request_line); base::ListValue* headers = new base::ListValue(); for (HeaderVector::const_iterator it = headers_.begin(); it != headers_.end(); ++it) { - std::string log_value = ElideHeaderValueForNetLog( - log_level, it->key, it->value); + std::string log_value = + ElideHeaderValueForNetLog(capture_mode, it->key, it->value); headers->Append(new base::StringValue( base::StringPrintf("%s: %s", it->key.c_str(), log_value.c_str()))); diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h index d8d52a0..d0666de 100644 --- a/net/http/http_request_headers.h +++ b/net/http/http_request_headers.h @@ -148,7 +148,7 @@ class NET_EXPORT HttpRequestHeaders { // Takes in the request line and returns a Value for use with the NetLog // containing both the request line and all headers fields. base::Value* NetLogCallback(const std::string* request_line, - NetLog::LogLevel log_level) const; + NetLogCaptureMode capture_mode) const; // Takes in a Value created by the above function, and attempts to extract the // request line and create a copy of the original headers. Returns true on diff --git a/net/http/http_request_headers_unittest.cc b/net/http/http_request_headers_unittest.cc index d33b473..7c00c6e 100644 --- a/net/http/http_request_headers_unittest.cc +++ b/net/http/http_request_headers_unittest.cc @@ -171,8 +171,8 @@ TEST(HttpRequestHeaders, ToNetLogParamAndBackAgain) { headers.SetHeader("A", "a"); std::string request_line("GET /stuff"); - scoped_ptr<base::Value> event_param( - headers.NetLogCallback(&request_line, NetLog::LOG_ALL_BUT_BYTES)); + scoped_ptr<base::Value> event_param(headers.NetLogCallback( + &request_line, NetLogCaptureMode::IncludeCookiesAndCredentials())); HttpRequestHeaders headers2; std::string request_line2; diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 3aef42a..69a0aa8 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -1392,7 +1392,7 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, } base::Value* HttpResponseHeaders::NetLogCallback( - NetLog::LogLevel log_level) const { + NetLogCaptureMode capture_mode) const { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* headers = new base::ListValue(); headers->Append(new base::StringValue(GetStatusLine())); @@ -1400,7 +1400,8 @@ base::Value* HttpResponseHeaders::NetLogCallback( std::string name; std::string value; while (EnumerateHeaderLines(&iterator, &name, &value)) { - std::string log_value = ElideHeaderValueForNetLog(log_level, name, value); + std::string log_value = + ElideHeaderValueForNetLog(capture_mode, name, value); std::string escaped_name = EscapeNonASCII(name); std::string escaped_value = EscapeNonASCII(log_value); headers->Append( diff --git a/net/http/http_response_headers.h b/net/http/http_response_headers.h index a87a5f5..dd3d9cb 100644 --- a/net/http/http_response_headers.h +++ b/net/http/http_response_headers.h @@ -286,7 +286,7 @@ class NET_EXPORT HttpResponseHeaders bool IsChunkEncoded() const; // Creates a Value for use with the NetLog containing the response headers. - base::Value* NetLogCallback(NetLog::LogLevel log_level) const; + base::Value* NetLogCallback(NetLogCaptureMode capture_mode) const; // Takes in a Value created by the above function, and attempts to create a // copy of the original headers. Returns true on success. On failure, diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index 3557423..81bd5a3 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -2266,8 +2266,8 @@ TEST(HttpResponseHeadersTest, ToNetLogParamAndBackAgain) { scoped_refptr<net::HttpResponseHeaders> parsed( new net::HttpResponseHeaders(headers)); - scoped_ptr<base::Value> event_param( - parsed->NetLogCallback(net::NetLog::LOG_ALL_BUT_BYTES)); + scoped_ptr<base::Value> event_param(parsed->NetLogCallback( + net::NetLogCaptureMode::IncludeCookiesAndCredentials())); scoped_refptr<net::HttpResponseHeaders> recreated; ASSERT_TRUE(net::HttpResponseHeaders::FromNetLogParam(event_param.get(), diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc index 4ce799e..5843d4c 100644 --- a/net/http/http_stream_factory_impl_job.cc +++ b/net/http/http_stream_factory_impl_job.cc @@ -49,7 +49,7 @@ base::Value* NetLogHttpStreamJobCallback( const GURL* url, const AlternativeService* alternative_service, RequestPriority priority, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("original_url", original_url->GetOrigin().spec()); dict->SetString("url", url->GetOrigin().spec()); @@ -63,7 +63,7 @@ base::Value* NetLogHttpStreamJobCallback( base::Value* NetLogHttpStreamProtoCallback( const SSLClientSocket::NextProtoStatus status, const std::string* proto, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("next_proto_status", diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index 5aeafa1..30a6301 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -74,10 +74,11 @@ bool HeadersContainMultipleCopiesOfField(const HttpResponseHeaders& headers, return false; } -base::Value* NetLogSendRequestBodyCallback(uint64 length, - bool is_chunked, - bool did_merge, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogSendRequestBodyCallback( + uint64 length, + bool is_chunked, + bool did_merge, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("length", static_cast<int>(length)); dict->SetBoolean("is_chunked", is_chunked); diff --git a/net/log/net_log.cc b/net/log/net_log.cc index 7f1d6e9..e112c2c 100644 --- a/net/log/net_log.cc +++ b/net/log/net_log.cc @@ -17,22 +17,23 @@ namespace net { namespace { -// Returns parameters for logging data transferred events. Includes number of -// bytes transferred and, if the log level indicates bytes should be logged and -// |byte_count| > 0, the bytes themselves. The bytes are hex-encoded, since -// base::StringValue only supports UTF-8. +// Returns parameters for logging data transferred events. At a minum includes +// the number of bytes transferred. If the capture mode allows logging byte +// contents and |byte_count| > 0, then will include the actual bytes. The +// bytes are hex-encoded, since base::StringValue only supports UTF-8. base::Value* BytesTransferredCallback(int byte_count, const char* bytes, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("byte_count", byte_count); - if (NetLog::IsLoggingBytes(log_level) && byte_count > 0) + if (capture_mode.include_socket_bytes() && byte_count > 0) dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); return dict; } -base::Value* SourceEventParametersCallback(const NetLog::Source source, - NetLog::LogLevel /* log_level */) { +base::Value* SourceEventParametersCallback( + const NetLog::Source source, + NetLogCaptureMode /* capture_mode */) { if (!source.IsValid()) return NULL; base::DictionaryValue* event_params = new base::DictionaryValue(); @@ -42,7 +43,7 @@ base::Value* SourceEventParametersCallback(const NetLog::Source source, base::Value* NetLogIntegerCallback(const char* name, int value, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* event_params = new base::DictionaryValue(); event_params->SetInteger(name, value); return event_params; @@ -50,7 +51,7 @@ base::Value* NetLogIntegerCallback(const char* name, base::Value* NetLogInt64Callback(const char* name, int64 value, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* event_params = new base::DictionaryValue(); event_params->SetString(name, base::Int64ToString(value)); return event_params; @@ -58,7 +59,7 @@ base::Value* NetLogInt64Callback(const char* name, base::Value* NetLogStringCallback(const char* name, const std::string* value, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* event_params = new base::DictionaryValue(); event_params->SetString(name, *value); return event_params; @@ -66,7 +67,7 @@ base::Value* NetLogStringCallback(const char* name, base::Value* NetLogString16Callback(const char* name, const base::string16* value, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* event_params = new base::DictionaryValue(); event_params->SetString(name, *value); return event_params; @@ -137,7 +138,7 @@ base::Value* NetLog::Entry::ToValue() const { // Set the event-specific parameters. if (data_->parameters_callback) { - base::Value* value = data_->parameters_callback->Run(log_level_); + base::Value* value = data_->parameters_callback->Run(capture_mode_); if (value) entry_dict->Set("params", value); } @@ -147,7 +148,7 @@ base::Value* NetLog::Entry::ToValue() const { base::Value* NetLog::Entry::ParametersToValue() const { if (data_->parameters_callback) - return data_->parameters_callback->Run(log_level_); + return data_->parameters_callback->Run(capture_mode_); return NULL; } @@ -166,15 +167,14 @@ NetLog::EntryData::EntryData(EventType type, NetLog::EntryData::~EntryData() { } -NetLog::Entry::Entry(const EntryData* data, LogLevel log_level) - : data_(data), log_level_(log_level) { +NetLog::Entry::Entry(const EntryData* data, NetLogCaptureMode capture_mode) + : data_(data), capture_mode_(capture_mode) { } NetLog::Entry::~Entry() { } -NetLog::ThreadSafeObserver::ThreadSafeObserver() - : log_level_(LOG_NONE), net_log_(NULL) { +NetLog::ThreadSafeObserver::ThreadSafeObserver() : net_log_(NULL) { } NetLog::ThreadSafeObserver::~ThreadSafeObserver() { @@ -184,9 +184,9 @@ NetLog::ThreadSafeObserver::~ThreadSafeObserver() { DCHECK(!net_log_); } -NetLog::LogLevel NetLog::ThreadSafeObserver::log_level() const { +NetLogCaptureMode NetLog::ThreadSafeObserver::capture_mode() const { DCHECK(net_log_); - return log_level_; + return capture_mode_; } NetLog* NetLog::ThreadSafeObserver::net_log() const { @@ -194,10 +194,13 @@ NetLog* NetLog::ThreadSafeObserver::net_log() const { } void NetLog::ThreadSafeObserver::OnAddEntryData(const EntryData& entry_data) { - OnAddEntry(Entry(&entry_data, log_level())); + OnAddEntry(Entry(&entry_data, capture_mode())); } -NetLog::NetLog() : last_id_(0), effective_log_level_(LOG_NONE) { +NetLog::NetLog() + : last_id_(0), + effective_capture_mode_int32_( + NetLogCaptureMode::None().ToInternalValue()) { } NetLog::~NetLog() { @@ -219,35 +222,36 @@ uint32 NetLog::NextID() { return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1); } -NetLog::LogLevel NetLog::GetLogLevel() const { - base::subtle::Atomic32 log_level = - base::subtle::NoBarrier_Load(&effective_log_level_); - return static_cast<net::NetLog::LogLevel>(log_level); +NetLogCaptureMode NetLog::GetCaptureMode() const { + base::subtle::Atomic32 capture_mode = + base::subtle::NoBarrier_Load(&effective_capture_mode_int32_); + return NetLogCaptureMode::FromInternalValue(capture_mode); } void NetLog::DeprecatedAddObserver(net::NetLog::ThreadSafeObserver* observer, - LogLevel log_level) { - DCHECK_NE(LOG_NONE, log_level); + NetLogCaptureMode capture_mode) { + DCHECK(capture_mode.enabled()); + base::AutoLock lock(lock_); DCHECK(!observer->net_log_); - DCHECK_EQ(LOG_NONE, observer->log_level_); + DCHECK(!observer->capture_mode_.enabled()); observers_.AddObserver(observer); observer->net_log_ = this; - observer->log_level_ = log_level; - UpdateLogLevel(); + observer->capture_mode_ = capture_mode; + UpdateCaptureMode(); } -void NetLog::SetObserverLogLevel(net::NetLog::ThreadSafeObserver* observer, - LogLevel log_level) { - DCHECK_NE(LOG_NONE, log_level); +void NetLog::SetObserverCaptureMode(net::NetLog::ThreadSafeObserver* observer, + NetLogCaptureMode capture_mode) { + DCHECK(capture_mode.enabled()); base::AutoLock lock(lock_); DCHECK(observers_.HasObserver(observer)); DCHECK_EQ(this, observer->net_log_); - DCHECK_NE(LOG_NONE, observer->log_level_); - observer->log_level_ = log_level; - UpdateLogLevel(); + DCHECK(observer->capture_mode_.enabled()); + observer->capture_mode_ = capture_mode; + UpdateCaptureMode(); } void NetLog::DeprecatedRemoveObserver( @@ -256,26 +260,26 @@ void NetLog::DeprecatedRemoveObserver( DCHECK(observers_.HasObserver(observer)); DCHECK_EQ(this, observer->net_log_); - DCHECK_NE(LOG_NONE, observer->log_level_); + DCHECK(observer->capture_mode_.enabled()); observers_.RemoveObserver(observer); observer->net_log_ = NULL; - observer->log_level_ = LOG_NONE; - UpdateLogLevel(); + observer->capture_mode_ = NetLogCaptureMode(); + UpdateCaptureMode(); } -void NetLog::UpdateLogLevel() { +void NetLog::UpdateCaptureMode() { 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_effective_log_level = LOG_NONE; + // Accumulate the capture mode of all the observers to find the maximum level. + NetLogCaptureMode new_capture_mode = NetLogCaptureMode::None(); ObserverListBase<ThreadSafeObserver>::Iterator it(&observers_); ThreadSafeObserver* observer; while ((observer = it.GetNext()) != NULL) { - new_effective_log_level = - std::min(new_effective_log_level, observer->log_level()); + new_capture_mode = + NetLogCaptureMode::Max(new_capture_mode, observer->capture_mode()); } - base::subtle::NoBarrier_Store(&effective_log_level_, new_effective_log_level); + base::subtle::NoBarrier_Store(&effective_capture_mode_int32_, + new_capture_mode.ToInternalValue()); } // static @@ -345,16 +349,6 @@ const char* NetLog::EventPhaseToString(EventPhase phase) { } // static -bool NetLog::IsLoggingBytes(LogLevel log_level) { - return log_level == NetLog::LOG_ALL; -} - -// static -bool NetLog::IsLogging(LogLevel log_level) { - return log_level < NetLog::LOG_NONE; -} - -// static NetLog::ParametersCallback NetLog::IntegerCallback(const char* name, int value) { return base::Bind(&NetLogIntegerCallback, name, value); @@ -384,7 +378,7 @@ void NetLog::AddEntry(EventType type, const Source& source, EventPhase phase, const NetLog::ParametersCallback* parameters_callback) { - if (GetLogLevel() == LOG_NONE) + if (!GetCaptureMode().enabled()) return; EntryData entry_data(type, source, phase, base::TimeTicks::Now(), parameters_callback); @@ -474,20 +468,12 @@ void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); } -NetLog::LogLevel BoundNetLog::GetLogLevel() const { +NetLogCaptureMode BoundNetLog::GetCaptureMode() const { CrashIfInvalid(); if (net_log_) - return net_log_->GetLogLevel(); - return NetLog::LOG_NONE; -} - -bool BoundNetLog::IsLoggingBytes() const { - return NetLog::IsLoggingBytes(GetLogLevel()); -} - -bool BoundNetLog::IsLogging() const { - return NetLog::IsLogging(GetLogLevel()); + return net_log_->GetCaptureMode(); + return NetLogCaptureMode(); } // static diff --git a/net/log/net_log.h b/net/log/net_log.h index dd22d5e..7d32e1c 100644 --- a/net/log/net_log.h +++ b/net/log/net_log.h @@ -18,6 +18,7 @@ #include "base/synchronization/lock.h" #include "base/time/time.h" #include "net/base/net_export.h" +#include "net/log/net_log_capture_mode.h" namespace base { class DictionaryValue; @@ -66,33 +67,11 @@ class NET_EXPORT NetLog { SOURCE_COUNT }; - // Specifies the granularity of events that should be emitted to the log. - // - // Since the LogLevel may be read and set on any thread without locking, it - // may be possible for an Observer to receive an event or parameters that - // normally wouldn't be logged at the currently active log level. - enum LogLevel { - // Log everything possible, even if it is slow and memory expensive. - // Includes logging of transferred bytes. - LOG_ALL, - - // Log all events, but do not include the actual transferred bytes as - // parameters for bytes sent/received events. - LOG_ALL_BUT_BYTES, - - // Log all events, but do not include the actual transferred bytes and - // remove cookies and HTTP credentials. - LOG_STRIP_PRIVATE_DATA, - - // Don't log any events. - LOG_NONE, - }; - // A callback function that return a Value representation of the parameters // associated with an event. If called, it will be called synchonously, // so it need not have owning references. May be called more than once, or // not at all. May return NULL. - typedef base::Callback<base::Value*(LogLevel)> ParametersCallback; + typedef base::Callback<base::Value*(NetLogCaptureMode)> ParametersCallback; // Identifies the entity that generated this log. The |id| field should // uniquely identify the source, and is used by log observers to infer @@ -137,12 +116,12 @@ class NET_EXPORT NetLog { const ParametersCallback* const parameters_callback; }; - // An Entry pre-binds EntryData to a LogLevel, so observers will observe the - // output of ToValue() and ParametersToValue() at their log level rather than - // current maximum. + // An Entry pre-binds EntryData to a capture mode, so observers will observe + // the output of ToValue() and ParametersToValue() at their log capture mode + // rather than the current maximum. class NET_EXPORT Entry { public: - Entry(const EntryData* data, LogLevel log_level); + Entry(const EntryData* data, NetLogCaptureMode capture_mode); ~Entry(); EventType type() const { return data_->type; } @@ -161,8 +140,8 @@ class NET_EXPORT NetLog { private: const EntryData* const data_; - // Log level when the event occurred. - const LogLevel log_level_; + // Log capture mode when the event occurred. + const NetLogCaptureMode capture_mode_; // It is not safe to copy this class, since |parameters_callback_| may // include pointers that become stale immediately after the event is added, @@ -185,9 +164,9 @@ class NET_EXPORT NetLog { // NetLog is destroyed. ThreadSafeObserver(); - // Returns the minimum log level for events this observer wants to + // Returns the capture mode for events this observer wants to // receive. Must not be called when not watching a NetLog. - LogLevel log_level() const; + NetLogCaptureMode capture_mode() const; // Returns the NetLog we are currently watching, if any. Returns NULL // otherwise. @@ -210,7 +189,7 @@ class NET_EXPORT NetLog { void OnAddEntryData(const EntryData& entry_data); // Both of these values are only modified by the NetLog. - LogLevel log_level_; + NetLogCaptureMode capture_mode_; NetLog* net_log_; DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver); @@ -228,11 +207,11 @@ class NET_EXPORT NetLog { // will be unique and greater than 0. uint32 NextID(); - // Returns the logging level for this NetLog. This is used to avoid computing + // Returns the capture mode for this NetLog. This is used to avoid computing // and saving expensive log entries. - LogLevel GetLogLevel() const; + NetLogCaptureMode GetCaptureMode() const; - // Adds an observer and sets its log level. The observer must not be + // Adds an observer and sets its log capture mode. The observer must not be // watching any NetLog, including this one, when this is called. // // NetLog implementations must call NetLog::OnAddObserver to update the @@ -241,12 +220,14 @@ class NET_EXPORT NetLog { // DEPRECATED: The ability to watch the netlog stream is being phased out // (crbug.com/472693) as it can be misused in production code. Please consult // with a net/log OWNER before introducing a new dependency on this. - void DeprecatedAddObserver(ThreadSafeObserver* observer, LogLevel log_level); + void DeprecatedAddObserver(ThreadSafeObserver* observer, + NetLogCaptureMode capture_mode); - // Sets the log level of |observer| to |log_level|. |observer| must be - // watching |this|. NetLog implementations must call - // NetLog::OnSetObserverLogLevel to update the observer's internal state. - void SetObserverLogLevel(ThreadSafeObserver* observer, LogLevel log_level); + // Sets the log capture mode of |observer| to |capture_mode|. |observer| must + // be watching |this|. NetLog implementations must call + // NetLog::OnSetObserverCaptureMode to update the observer's internal state. + void SetObserverCaptureMode(ThreadSafeObserver* observer, + NetLogCaptureMode capture_mode); // Removes an observer. NetLog implementations must call // NetLog::OnAddObserver to update the observer's internal state. @@ -280,14 +261,6 @@ class NET_EXPORT NetLog { // Returns a C-String symbolic name for |event_phase|. static const char* EventPhaseToString(EventPhase event_phase); - // Returns true if |log_level| indicates the actual bytes transferred should - // be logged. This is only the case when |log_level| is LOG_ALL. - static bool IsLoggingBytes(LogLevel log_level); - - // Returns true if |log_level| indicates that events should be logged. This is - // the case when |log_level| is anything other than LOG_NONE. - static bool IsLogging(LogLevel log_level); - // Creates a ParametersCallback that encapsulates a single integer. // Warning: |name| must remain valid for the life of the callback. // TODO(mmenke): Rename this to be consistent with Int64Callback. @@ -318,9 +291,9 @@ class NET_EXPORT NetLog { EventPhase phase, const NetLog::ParametersCallback* parameters_callback); - // Called whenever an observer is added or removed, or has its log level - // changed. Must have acquired |lock_| prior to calling. - void UpdateLogLevel(); + // Called whenever an observer is added or removed, or has its log + // capture mode changed. Must have acquired |lock_| prior to calling. + void UpdateCaptureMode(); // |lock_| protects access to |observers_|. base::Lock lock_; @@ -328,8 +301,10 @@ class NET_EXPORT NetLog { // Last assigned source ID. Incremented to get the next one. base::subtle::Atomic32 last_id_; - // The current log level. - base::subtle::Atomic32 effective_log_level_; + // The current capture mode. Note that the capture mode is stored as an + // integer rather than a NetLogCaptureMode so that it can be easily + // read/written without a lock using Atomic32. + base::subtle::Atomic32 effective_capture_mode_int32_; // |lock_| must be acquired whenever reading or writing to this. ObserverList<ThreadSafeObserver, true> observers_; @@ -384,13 +359,7 @@ class NET_EXPORT BoundNetLog { int byte_count, const char* bytes) const; - NetLog::LogLevel GetLogLevel() const; - - // Shortcut for NetLog::IsLoggingBytes(this->GetLogLevel()). - bool IsLoggingBytes() const; - - // Shortcut for NetLog::IsLogging(this->GetLogLevel()). - bool IsLogging() const; + NetLogCaptureMode GetCaptureMode() const; // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care // of creating a unique source ID, and handles the case of NULL net_log. diff --git a/net/log/net_log_capture_mode.cc b/net/log/net_log_capture_mode.cc new file mode 100644 index 0000000..501911e --- /dev/null +++ b/net/log/net_log_capture_mode.cc @@ -0,0 +1,95 @@ +// Copyright 2015 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. + +#include "net/log/net_log_capture_mode.h" + +#include <algorithm> + +namespace net { + +namespace { + +// Integer representation for the capture mode. The numeric value is depended on +// for method of NetLogCaptureMode, which expect that higher values imply more +// capabilities. +enum InternalValue { + // Don't log any events. + NONE, + + // Log all events, but do not include the actual transferred bytes and + // remove cookies and HTTP credentials. + DEFAULT, + + // Log all events, but do not include the actual transferred bytes as + // parameters for bytes sent/received events. + INCLUDE_COOKIES_AND_CREDENTIALS, + + // Log everything possible, even if it is slow and memory expensive. + // Includes logging of transferred bytes. + INCLUDE_SOCKET_BYTES, +}; + +} // namespace + +// Default constructor creates an empty capture mode. +NetLogCaptureMode::NetLogCaptureMode() : NetLogCaptureMode(NONE) { +} + +NetLogCaptureMode NetLogCaptureMode::None() { + return NetLogCaptureMode(NONE); +} + +NetLogCaptureMode NetLogCaptureMode::Default() { + return NetLogCaptureMode(DEFAULT); +} + +NetLogCaptureMode NetLogCaptureMode::IncludeCookiesAndCredentials() { + return NetLogCaptureMode(INCLUDE_COOKIES_AND_CREDENTIALS); +} + +NetLogCaptureMode NetLogCaptureMode::IncludeSocketBytes() { + return NetLogCaptureMode(INCLUDE_SOCKET_BYTES); +} + +NetLogCaptureMode NetLogCaptureMode::Max(NetLogCaptureMode mode1, + NetLogCaptureMode mode2) { + return NetLogCaptureMode(std::max(mode1.value_, mode2.value_)); +} + +bool NetLogCaptureMode::enabled() const { + return value_ != NONE; +} + +bool NetLogCaptureMode::include_cookies_and_credentials() const { + return value_ >= INCLUDE_COOKIES_AND_CREDENTIALS; +} + +bool NetLogCaptureMode::include_socket_bytes() const { + return value_ >= INCLUDE_SOCKET_BYTES; +} + +bool NetLogCaptureMode::operator==(NetLogCaptureMode mode) const { + return value_ == mode.value_; +} + +bool NetLogCaptureMode::operator!=(NetLogCaptureMode mode) const { + return !(*this == mode); +} + +int32_t NetLogCaptureMode::ToInternalValueForTesting() const { + return ToInternalValue(); +} + +NetLogCaptureMode::NetLogCaptureMode(uint32_t value) : value_(value) { +} + +NetLogCaptureMode NetLogCaptureMode::FromInternalValue(int32_t value) { + return NetLogCaptureMode(value); +} + +int32_t NetLogCaptureMode::ToInternalValue() const { + return value_; +} + +} // namespace net diff --git a/net/log/net_log_capture_mode.h b/net/log/net_log_capture_mode.h new file mode 100644 index 0000000..e4f26a3 --- /dev/null +++ b/net/log/net_log_capture_mode.h @@ -0,0 +1,87 @@ +// Copyright 2015 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. + +#ifndef NET_LOG_NET_LOG_CAPTURE_MODE_H_ +#define NET_LOG_NET_LOG_CAPTURE_MODE_H_ + +#include <stdint.h> +#include <string> + +#include "net/base/net_export.h" + +namespace net { + +// NetLogCaptureMode specifies the granularity of events that should be emitted +// to the log. It is a simple wrapper around an integer, so it should be passed +// to functions by value rather than by reference. +class NET_EXPORT NetLogCaptureMode { + public: + // NOTE: Default assignment and copy constructor are OK. + + // The default constructor creates an empty capture mode (equivalent to + // None()). + NetLogCaptureMode(); + + // Constructs a capture mode which logs NOTHING. + // enabled() --> false + // include_cookies_and_credentials() --> false + // include_socket_bytes() --> false + static NetLogCaptureMode None(); + + // Constructs a capture mode which logs basic events and event parameters. + // enabled() --> true + // include_cookies_and_credentials() --> false + // include_socket_bytes() --> false + static NetLogCaptureMode Default(); + + // Constructs a capture mode which logs basic events, and additionally makes + // no effort to strip cookies and credentials. + // enabled() --> true + // include_cookies_and_credentials() --> true + // include_socket_bytes() --> false + static NetLogCaptureMode IncludeCookiesAndCredentials(); + + // Constructs a capture mode which logs the data sent/received from sockets. + // enabled() --> true + // include_cookies_and_credentials() --> true + // include_socket_bytes() --> true + static NetLogCaptureMode IncludeSocketBytes(); + + // Returns a capture mode that contains the maximal set of capabilities + // between |mode1| and |mode2|. + static NetLogCaptureMode Max(NetLogCaptureMode mode1, + NetLogCaptureMode mode2); + + // If enabled() is true, then _something_ is being captured. + bool enabled() const; + + // If include_cookies_and_credentials() is true , then it is OK to log + // events which contain cookies, credentials or other privacy sensitive data. + bool include_cookies_and_credentials() const; + + // If include_socket_bytes() is true, then it is OK to output the actual + // bytes read/written from the network, even if it contains private data. + bool include_socket_bytes() const; + + bool operator==(NetLogCaptureMode mode) const; + bool operator!=(NetLogCaptureMode mode) const; + + int32_t ToInternalValueForTesting() const; + + private: + // NetLog relies on the internal value of NetLogCaptureMode being an integer, + // so it can be read/written atomically across thread. + friend class NetLog; + + explicit NetLogCaptureMode(uint32_t value); + + static NetLogCaptureMode FromInternalValue(int32_t value); + int32_t ToInternalValue() const; + + int32_t value_; +}; + +} // namespace net + +#endif // NET_LOG_NET_LOG_CAPTURE_MODE_H_ diff --git a/net/log/net_log_capture_mode_unittest.cc b/net/log/net_log_capture_mode_unittest.cc new file mode 100644 index 0000000..b32beb9 --- /dev/null +++ b/net/log/net_log_capture_mode_unittest.cc @@ -0,0 +1,93 @@ +// Copyright 2015 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. + +#include "net/log/net_log_capture_mode.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +namespace { + +TEST(NetLogCaptureMode, None) { + NetLogCaptureMode mode = NetLogCaptureMode::None(); + + EXPECT_FALSE(mode.enabled()); + EXPECT_FALSE(mode.include_cookies_and_credentials()); + EXPECT_FALSE(mode.include_socket_bytes()); + + EXPECT_EQ(mode, NetLogCaptureMode::None()); + EXPECT_NE(mode, NetLogCaptureMode::Default()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); + EXPECT_EQ(mode.ToInternalValueForTesting(), + NetLogCaptureMode::None().ToInternalValueForTesting()); +} + +TEST(NetLogCaptureMode, Default) { + NetLogCaptureMode mode = NetLogCaptureMode::Default(); + + EXPECT_TRUE(mode.enabled()); + EXPECT_FALSE(mode.include_cookies_and_credentials()); + EXPECT_FALSE(mode.include_socket_bytes()); + + EXPECT_NE(mode, NetLogCaptureMode::None()); + EXPECT_EQ(mode, NetLogCaptureMode::Default()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); + EXPECT_EQ(mode.ToInternalValueForTesting(), + NetLogCaptureMode::Default().ToInternalValueForTesting()); +} + +TEST(NetLogCaptureMode, IncludeCookiesAndCredentials) { + NetLogCaptureMode mode = NetLogCaptureMode::IncludeCookiesAndCredentials(); + + EXPECT_TRUE(mode.enabled()); + EXPECT_TRUE(mode.include_cookies_and_credentials()); + EXPECT_FALSE(mode.include_socket_bytes()); + + EXPECT_NE(mode, NetLogCaptureMode::None()); + EXPECT_NE(mode, NetLogCaptureMode::Default()); + EXPECT_EQ(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); + EXPECT_EQ(mode.ToInternalValueForTesting(), + NetLogCaptureMode::IncludeCookiesAndCredentials() + .ToInternalValueForTesting()); +} + +TEST(NetLogCaptureMode, IncludeSocketBytes) { + NetLogCaptureMode mode = NetLogCaptureMode::IncludeSocketBytes(); + + EXPECT_TRUE(mode.enabled()); + EXPECT_TRUE(mode.include_cookies_and_credentials()); + EXPECT_TRUE(mode.include_socket_bytes()); + + EXPECT_NE(mode, NetLogCaptureMode::None()); + EXPECT_NE(mode, NetLogCaptureMode::Default()); + EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); + EXPECT_EQ(mode, NetLogCaptureMode::IncludeSocketBytes()); + EXPECT_EQ( + mode.ToInternalValueForTesting(), + NetLogCaptureMode::IncludeSocketBytes().ToInternalValueForTesting()); +} + +TEST(NetLogCaptureMode, Max) { + NetLogCaptureMode none = NetLogCaptureMode::None(); + NetLogCaptureMode all = NetLogCaptureMode::IncludeSocketBytes(); + NetLogCaptureMode cookies = NetLogCaptureMode::IncludeCookiesAndCredentials(); + NetLogCaptureMode def = NetLogCaptureMode::Default(); + + EXPECT_EQ(all, NetLogCaptureMode::Max(none, all)); + EXPECT_EQ(all, NetLogCaptureMode::Max(all, none)); + + EXPECT_EQ(cookies, NetLogCaptureMode::Max(def, cookies)); + EXPECT_EQ(cookies, NetLogCaptureMode::Max(cookies, def)); + + EXPECT_EQ(all, NetLogCaptureMode::Max(def, all)); + EXPECT_EQ(all, NetLogCaptureMode::Max(all, def)); +} + +} // namespace + +} // namespace net diff --git a/net/log/net_log_unittest.cc b/net/log/net_log_unittest.cc index 73e4e30..9fad152 100644 --- a/net/log/net_log_unittest.cc +++ b/net/log/net_log_unittest.cc @@ -18,9 +18,13 @@ namespace { const int kThreads = 10; const int kEvents = 100; -base::Value* NetLogLevelCallback(NetLog::LogLevel log_level) { +base::Value* CaptureModeToValue(NetLogCaptureMode capture_mode) { + return new base::FundamentalValue(capture_mode.ToInternalValueForTesting()); +} + +base::Value* NetCaptureModeCallback(NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); - dict->SetInteger("log_level", log_level); + dict->Set("capture_mode", CaptureModeToValue(capture_mode)); return dict; } @@ -42,16 +46,22 @@ TEST(NetLogTest, Basic) { EXPECT_FALSE(entries[0].params); } -// Check that the correct LogLevel is sent to NetLog Value callbacks. -TEST(NetLogTest, LogLevels) { +// Check that the correct CaptureMode is sent to NetLog Value callbacks. +TEST(NetLogTest, CaptureModes) { + NetLogCaptureMode kModes[] = { + NetLogCaptureMode::Default(), + NetLogCaptureMode::IncludeCookiesAndCredentials(), + NetLogCaptureMode::IncludeSocketBytes(), + }; + TestNetLog net_log; - for (int log_level = NetLog::LOG_ALL; log_level < NetLog::LOG_NONE; - ++log_level) { - net_log.SetLogLevel(static_cast<NetLog::LogLevel>(log_level)); - EXPECT_EQ(log_level, net_log.GetLogLevel()); + + for (NetLogCaptureMode mode : kModes) { + net_log.SetCaptureMode(mode); + EXPECT_EQ(mode, net_log.GetCaptureMode()); net_log.AddGlobalEntry(NetLog::TYPE_SOCKET_ALIVE, - base::Bind(NetLogLevelCallback)); + base::Bind(NetCaptureModeCallback)); TestNetLog::CapturedEntryList entries; net_log.GetEntries(&entries); @@ -63,9 +73,10 @@ TEST(NetLogTest, LogLevels) { EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase); EXPECT_GE(base::TimeTicks::Now(), entries[0].time); - int logged_log_level; - ASSERT_TRUE(entries[0].GetIntegerValue("log_level", &logged_log_level)); - EXPECT_EQ(log_level, logged_log_level); + int logged_capture_mode; + ASSERT_TRUE( + entries[0].GetIntegerValue("capture_mode", &logged_capture_mode)); + EXPECT_EQ(mode.ToInternalValueForTesting(), logged_capture_mode); net_log.Clear(); } @@ -111,12 +122,9 @@ class LoggingObserver : public NetLog::ThreadSafeObserver { ScopedVector<base::DictionaryValue> values_; }; -base::Value* LogLevelToValue(NetLog::LogLevel log_level) { - return new base::FundamentalValue(log_level); -} - void AddEvent(NetLog* net_log) { - net_log->AddGlobalEntry(NetLog::TYPE_CANCELLED, base::Bind(LogLevelToValue)); + net_log->AddGlobalEntry(NetLog::TYPE_CANCELLED, + base::Bind(CaptureModeToValue)); } // A thread that waits until an event has been signalled before calling @@ -180,15 +188,17 @@ class AddRemoveObserverTestThread : public NetLogTestThread { for (int i = 0; i < kEvents; ++i) { ASSERT_FALSE(observer_.net_log()); - net_log_->DeprecatedAddObserver(&observer_, NetLog::LOG_ALL_BUT_BYTES); + net_log_->DeprecatedAddObserver( + &observer_, NetLogCaptureMode::IncludeCookiesAndCredentials()); ASSERT_EQ(net_log_, observer_.net_log()); - ASSERT_EQ(NetLog::LOG_ALL_BUT_BYTES, observer_.log_level()); - ASSERT_LE(net_log_->GetLogLevel(), NetLog::LOG_ALL_BUT_BYTES); + ASSERT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + observer_.capture_mode()); - net_log_->SetObserverLogLevel(&observer_, NetLog::LOG_ALL); + net_log_->SetObserverCaptureMode(&observer_, + NetLogCaptureMode::IncludeSocketBytes()); ASSERT_EQ(net_log_, observer_.net_log()); - ASSERT_EQ(NetLog::LOG_ALL, observer_.log_level()); - ASSERT_LE(net_log_->GetLogLevel(), NetLog::LOG_ALL); + ASSERT_EQ(NetLogCaptureMode::IncludeSocketBytes(), + observer_.capture_mode()); net_log_->DeprecatedRemoveObserver(&observer_); ASSERT_TRUE(!observer_.net_log()); @@ -225,8 +235,10 @@ TEST(NetLogTest, NetLogEventThreads) { // Attach some observers. Since they're created after |net_log|, they'll // safely detach themselves on destruction. CountingObserver observers[3]; - for (size_t i = 0; i < arraysize(observers); ++i) - net_log.DeprecatedAddObserver(&observers[i], NetLog::LOG_ALL); + for (size_t i = 0; i < arraysize(observers); ++i) { + net_log.DeprecatedAddObserver(&observers[i], + NetLogCaptureMode::IncludeSocketBytes()); + } // Run a bunch of threads to completion, each of which will emit events to // |net_log|. @@ -246,22 +258,26 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { AddEvent(&net_log); EXPECT_EQ(0, observer.count()); EXPECT_EQ(NULL, observer.net_log()); - EXPECT_EQ(NetLog::LOG_NONE, net_log.GetLogLevel()); + EXPECT_FALSE(net_log.GetCaptureMode().enabled()); // Add the observer and add an event. - net_log.DeprecatedAddObserver(&observer, NetLog::LOG_ALL_BUT_BYTES); + net_log.DeprecatedAddObserver( + &observer, NetLogCaptureMode::IncludeCookiesAndCredentials()); EXPECT_EQ(&net_log, observer.net_log()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, observer.log_level()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + observer.capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + net_log.GetCaptureMode()); AddEvent(&net_log); EXPECT_EQ(1, observer.count()); // Change the observer's logging level and add an event. - net_log.SetObserverLogLevel(&observer, NetLog::LOG_ALL); + net_log.SetObserverCaptureMode(&observer, + NetLogCaptureMode::IncludeSocketBytes()); EXPECT_EQ(&net_log, observer.net_log()); - EXPECT_EQ(NetLog::LOG_ALL, observer.log_level()); - EXPECT_EQ(NetLog::LOG_ALL, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), observer.capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); AddEvent(&net_log); EXPECT_EQ(2, observer.count()); @@ -269,16 +285,17 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { // Remove observer and add an event. net_log.DeprecatedRemoveObserver(&observer); EXPECT_EQ(NULL, observer.net_log()); - EXPECT_EQ(NetLog::LOG_NONE, net_log.GetLogLevel()); + EXPECT_FALSE(net_log.GetCaptureMode().enabled()); AddEvent(&net_log); EXPECT_EQ(2, observer.count()); // Add the observer a final time, and add an event. - net_log.DeprecatedAddObserver(&observer, NetLog::LOG_ALL); + net_log.DeprecatedAddObserver(&observer, + NetLogCaptureMode::IncludeSocketBytes()); EXPECT_EQ(&net_log, observer.net_log()); - EXPECT_EQ(NetLog::LOG_ALL, observer.log_level()); - EXPECT_EQ(NetLog::LOG_ALL, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), observer.capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); AddEvent(&net_log); EXPECT_EQ(3, observer.count()); @@ -290,19 +307,25 @@ TEST(NetLogTest, NetLogTwoObservers) { LoggingObserver observer[2]; // Add first observer. - net_log.DeprecatedAddObserver(&observer[0], NetLog::LOG_ALL_BUT_BYTES); + net_log.DeprecatedAddObserver( + &observer[0], NetLogCaptureMode::IncludeCookiesAndCredentials()); EXPECT_EQ(&net_log, observer[0].net_log()); EXPECT_EQ(NULL, observer[1].net_log()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, observer[0].log_level()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + observer[0].capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + net_log.GetCaptureMode()); // Add second observer observer. - net_log.DeprecatedAddObserver(&observer[1], NetLog::LOG_ALL); + net_log.DeprecatedAddObserver(&observer[1], + NetLogCaptureMode::IncludeSocketBytes()); EXPECT_EQ(&net_log, observer[0].net_log()); EXPECT_EQ(&net_log, observer[1].net_log()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, observer[0].log_level()); - EXPECT_EQ(NetLog::LOG_ALL, observer[1].log_level()); - EXPECT_EQ(NetLog::LOG_ALL, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + observer[0].capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), + observer[1].capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); // Add event and make sure both observers receive it at their respective log // levels. @@ -310,17 +333,19 @@ TEST(NetLogTest, NetLogTwoObservers) { AddEvent(&net_log); ASSERT_EQ(1U, observer[0].GetNumValues()); ASSERT_TRUE(observer[0].GetValue(0)->GetInteger("params", ¶m)); - EXPECT_EQ(observer[0].log_level(), param); + EXPECT_EQ(observer[0].capture_mode().ToInternalValueForTesting(), param); ASSERT_EQ(1U, observer[1].GetNumValues()); ASSERT_TRUE(observer[1].GetValue(0)->GetInteger("params", ¶m)); - EXPECT_EQ(observer[1].log_level(), param); + EXPECT_EQ(observer[1].capture_mode().ToInternalValueForTesting(), param); // Remove second observer. net_log.DeprecatedRemoveObserver(&observer[1]); EXPECT_EQ(&net_log, observer[0].net_log()); EXPECT_EQ(NULL, observer[1].net_log()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, observer[0].log_level()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + observer[0].capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + net_log.GetCaptureMode()); // Add event and make sure only second observer gets it. AddEvent(&net_log); @@ -331,7 +356,7 @@ TEST(NetLogTest, NetLogTwoObservers) { net_log.DeprecatedRemoveObserver(&observer[0]); EXPECT_EQ(NULL, observer[0].net_log()); EXPECT_EQ(NULL, observer[1].net_log()); - EXPECT_EQ(NetLog::LOG_NONE, net_log.GetLogLevel()); + EXPECT_FALSE(net_log.GetCaptureMode().enabled()); // Add event and make sure neither observer gets it. AddEvent(&net_log); diff --git a/net/log/net_log_util.cc b/net/log/net_log_util.cc index 3ce6f62..d178a32 100644 --- a/net/log/net_log_util.cc +++ b/net/log/net_log_util.cc @@ -129,7 +129,7 @@ bool RequestCreatedBefore(const net::URLRequest* request1, // Returns a Value representing the state of a pre-existing URLRequest when // net-internals was opened. base::Value* GetRequestStateAsValue(const net::URLRequest* request, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { return request->GetStateAsValue(); } @@ -255,18 +255,10 @@ scoped_ptr<base::DictionaryValue> GetNetConstants() { // their symbolic names. constants_dict->Set("logSourceType", net::NetLog::GetSourceTypesAsValue()); - // Information about the relationship between LogLevel enums and their - // symbolic names. - { - base::DictionaryValue* dict = new base::DictionaryValue(); - - dict->SetInteger("LOG_ALL", net::NetLog::LOG_ALL); - dict->SetInteger("LOG_ALL_BUT_BYTES", net::NetLog::LOG_ALL_BUT_BYTES); - dict->SetInteger("LOG_STRIP_PRIVATE_DATA", - net::NetLog::LOG_STRIP_PRIVATE_DATA); - - constants_dict->Set("logLevelType", dict); - } + // TODO(eroman): This is here for compatibility in loading new log files with + // older builds of Chrome. Safe to remove this once M45 is on the stable + // channel. + constants_dict->Set("logLevelType", new base::DictionaryValue()); // Information about the relationship between address family enums and // their symbolic names. @@ -538,7 +530,7 @@ NET_EXPORT void CreateNetLogEntriesForActiveObjects( net::NetLog::EntryData entry_data( net::NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(), net::NetLog::PHASE_BEGIN, request->creation_time(), &callback); - NetLog::Entry entry(&entry_data, request->net_log().GetLogLevel()); + NetLog::Entry entry(&entry_data, request->net_log().GetCaptureMode()); observer->OnAddEntry(entry); } } diff --git a/net/log/test_net_log.cc b/net/log/test_net_log.cc index 695eacc..d98ffc3 100644 --- a/net/log/test_net_log.cc +++ b/net/log/test_net_log.cc @@ -7,15 +7,16 @@ namespace net { TestNetLog::TestNetLog() { - DeprecatedAddObserver(&capturing_net_log_observer_, LOG_ALL_BUT_BYTES); + DeprecatedAddObserver(&capturing_net_log_observer_, + NetLogCaptureMode::IncludeCookiesAndCredentials()); } TestNetLog::~TestNetLog() { DeprecatedRemoveObserver(&capturing_net_log_observer_); } -void TestNetLog::SetLogLevel(NetLog::LogLevel log_level) { - SetObserverLogLevel(&capturing_net_log_observer_, log_level); +void TestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) { + SetObserverCaptureMode(&capturing_net_log_observer_, capture_mode); } void TestNetLog::GetEntries(TestNetLog::CapturedEntryList* entry_list) const { @@ -62,8 +63,8 @@ void BoundTestNetLog::Clear() { capturing_net_log_.Clear(); } -void BoundTestNetLog::SetLogLevel(NetLog::LogLevel log_level) { - capturing_net_log_.SetLogLevel(log_level); +void BoundTestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) { + capturing_net_log_.SetCaptureMode(capture_mode); } } // namespace net diff --git a/net/log/test_net_log.h b/net/log/test_net_log.h index 174f715..1526d82 100644 --- a/net/log/test_net_log.h +++ b/net/log/test_net_log.h @@ -28,7 +28,7 @@ class TestNetLog : public NetLog { TestNetLog(); ~TestNetLog() override; - void SetLogLevel(LogLevel log_level); + void SetCaptureMode(NetLogCaptureMode capture_mode); // Below methods are forwarded to capturing_net_log_observer_. void GetEntries(CapturedEntryList* entry_list) const; @@ -67,8 +67,8 @@ class BoundTestNetLog { void Clear(); - // Sets the log level of the underlying TestNetLog. - void SetLogLevel(NetLog::LogLevel log_level); + // Sets the capture mode of the underlying TestNetLog. + void SetCaptureMode(NetLogCaptureMode capture_mode); private: TestNetLog capturing_net_log_; diff --git a/net/log/trace_net_log_observer.cc b/net/log/trace_net_log_observer.cc index a283ea5..2ce8bc0 100644 --- a/net/log/trace_net_log_observer.cc +++ b/net/log/trace_net_log_observer.cc @@ -100,8 +100,7 @@ void TraceNetLogObserver::StopWatchForTraceStart() { } void TraceNetLogObserver::OnTraceLogEnabled() { - net_log_to_watch_->DeprecatedAddObserver(this, - NetLog::LOG_STRIP_PRIVATE_DATA); + net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); } void TraceNetLogObserver::OnTraceLogDisabled() { diff --git a/net/log/write_to_file_net_log_observer.cc b/net/log/write_to_file_net_log_observer.cc index 668b866..9df765eb 100644 --- a/net/log/write_to_file_net_log_observer.cc +++ b/net/log/write_to_file_net_log_observer.cc @@ -18,15 +18,16 @@ namespace net { WriteToFileNetLogObserver::WriteToFileNetLogObserver() - : log_level_(NetLog::LOG_STRIP_PRIVATE_DATA), added_events_(false) { + : capture_mode_(NetLogCaptureMode::Default()), added_events_(false) { } WriteToFileNetLogObserver::~WriteToFileNetLogObserver() { } -void WriteToFileNetLogObserver::set_log_level(net::NetLog::LogLevel log_level) { +void WriteToFileNetLogObserver::set_capture_mode( + net::NetLogCaptureMode capture_mode) { DCHECK(!net_log()); - log_level_ = log_level; + capture_mode_ = capture_mode; } void WriteToFileNetLogObserver::StartObserving( @@ -62,7 +63,7 @@ void WriteToFileNetLogObserver::StartObserving( CreateNetLogEntriesForActiveObjects(contexts, this); } - net_log->DeprecatedAddObserver(this, log_level_); + net_log->DeprecatedAddObserver(this, capture_mode_); } void WriteToFileNetLogObserver::StopObserving( diff --git a/net/log/write_to_file_net_log_observer.h b/net/log/write_to_file_net_log_observer.h index bd147e3..8ef0115 100644 --- a/net/log/write_to_file_net_log_observer.h +++ b/net/log/write_to_file_net_log_observer.h @@ -31,8 +31,8 @@ class NET_EXPORT WriteToFileNetLogObserver : public NetLog::ThreadSafeObserver { WriteToFileNetLogObserver(); ~WriteToFileNetLogObserver() override; - // Sets the log level to log at. Must be called before StartObserving. - void set_log_level(NetLog::LogLevel log_level); + // Sets the capture mode to log at. Must be called before StartObserving. + void set_capture_mode(NetLogCaptureMode capture_mode); // Starts observing |net_log| and writes output to |file|. Must not already // be watching a NetLog. Separate from constructor to enforce thread safety. @@ -65,8 +65,8 @@ class NET_EXPORT WriteToFileNetLogObserver : public NetLog::ThreadSafeObserver { private: base::ScopedFILE file_; - // The LogLevel to log at. - NetLog::LogLevel log_level_; + // The capture mode to log at. + NetLogCaptureMode capture_mode_; // True if OnAddEntry() has been called at least once. bool added_events_; diff --git a/net/log/write_to_file_net_log_observer_unittest.cc b/net/log/write_to_file_net_log_observer_unittest.cc index 4c12cf3d..4cabfe8c 100644 --- a/net/log/write_to_file_net_log_observer_unittest.cc +++ b/net/log/write_to_file_net_log_observer_unittest.cc @@ -61,21 +61,23 @@ TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONForNoEvents) { ASSERT_TRUE(dict->GetDictionary("constants", &constants)); } -TEST_F(WriteToFileNetLogObserverTest, LogLevel) { +TEST_F(WriteToFileNetLogObserverTest, CaptureMode) { base::ScopedFILE file(base::OpenFile(log_path_, "w")); ASSERT_TRUE(file); WriteToFileNetLogObserver logger; logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); - EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, logger.log_level()); - EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, net_log_.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::Default(), logger.capture_mode()); + EXPECT_EQ(NetLogCaptureMode::Default(), net_log_.GetCaptureMode()); logger.StopObserving(nullptr); file.reset(base::OpenFile(log_path_, "w")); ASSERT_TRUE(file); - logger.set_log_level(NetLog::LOG_ALL_BUT_BYTES); + logger.set_capture_mode(NetLogCaptureMode::IncludeCookiesAndCredentials()); logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, logger.log_level()); - EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log_.GetLogLevel()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + logger.capture_mode()); + EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), + net_log_.GetCaptureMode()); logger.StopObserving(nullptr); } @@ -90,7 +92,7 @@ TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, NetLog::PHASE_BEGIN, base::TimeTicks::Now(), NULL); - NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); + NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); logger->OnAddEntry(entry); logger->StopObserving(nullptr); logger.reset(); @@ -120,7 +122,7 @@ TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithMultipleEvents) { NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, NetLog::PHASE_BEGIN, base::TimeTicks::Now(), NULL); - NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); + NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes()); // Add the entry multiple times. logger->OnAddEntry(entry); diff --git a/net/net.gypi b/net/net.gypi index 457cb24..e481231 100644 --- a/net/net.gypi +++ b/net/net.gypi @@ -124,6 +124,8 @@ 'http/transport_security_state.h', 'log/net_log.cc', 'log/net_log.h', + 'log/net_log_capture_mode.cc', + 'log/net_log_capture_mode.h', 'log/net_log_event_type_list.h', 'log/net_log_source_type_list.h', 'socket/client_socket_handle.cc', @@ -1447,8 +1449,9 @@ 'http/transport_security_persister_unittest.cc', 'http/transport_security_state_unittest.cc', 'http/url_security_manager_unittest.cc', - 'log/write_to_file_net_log_observer_unittest.cc', + 'log/net_log_capture_mode_unittest.cc', 'log/net_log_unittest.cc', + 'log/write_to_file_net_log_observer_unittest.cc', 'log/net_log_unittest.h', 'log/net_log_util_unittest.cc', 'log/trace_net_log_observer_unittest.cc', diff --git a/net/proxy/proxy_resolver_v8_tracing.cc b/net/proxy/proxy_resolver_v8_tracing.cc index 230b7ca..3970589 100644 --- a/net/proxy/proxy_resolver_v8_tracing.cc +++ b/net/proxy/proxy_resolver_v8_tracing.cc @@ -56,7 +56,7 @@ const size_t kMaxAlertsAndErrorsBytes = 2048; // Returns event parameters for a PAC error message (line number + message). base::Value* NetLogErrorCallback(int line_number, const base::string16* message, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("line_number", line_number); dict->SetString("message", *message); diff --git a/net/proxy/proxy_script_decider.cc b/net/proxy/proxy_script_decider.cc index b22dc30..e7d8b17 100644 --- a/net/proxy/proxy_script_decider.cc +++ b/net/proxy/proxy_script_decider.cc @@ -56,7 +56,7 @@ const int kQuickCheckDelayMs = 1000; base::Value* ProxyScriptDecider::PacSource::NetLogCallback( const GURL* effective_pac_url, - NetLog::LogLevel /* log_level */) const { + NetLogCaptureMode /* capture_mode */) const { base::DictionaryValue* dict = new base::DictionaryValue(); std::string source; switch (type) { diff --git a/net/proxy/proxy_script_decider.h b/net/proxy/proxy_script_decider.h index 271e43ae..aa37c88 100644 --- a/net/proxy/proxy_script_decider.h +++ b/net/proxy/proxy_script_decider.h @@ -102,7 +102,7 @@ class NET_EXPORT_PRIVATE ProxyScriptDecider { // be non-NULL and point to the URL derived from information contained in // |this|, if Type is not WPAD_DHCP. base::Value* NetLogCallback(const GURL* effective_pac_url, - NetLog::LogLevel log_level) const; + NetLogCaptureMode capture_mode) const; Type type; GURL url; // Empty unless |type == PAC_SOURCE_CUSTOM|. diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index f912d2e..7de5449 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -316,7 +316,7 @@ class ProxyResolverFactoryForPacResult : public ProxyResolverFactory { base::Value* NetLogProxyConfigChangedCallback( const ProxyConfig* old_config, const ProxyConfig* new_config, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); // The "old_config" is optional -- the first notification will not have // any "previous" configuration. @@ -327,7 +327,7 @@ base::Value* NetLogProxyConfigChangedCallback( } base::Value* NetLogBadProxyListCallback(const ProxyRetryInfoMap* retry_info, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* list = new base::ListValue(); @@ -342,7 +342,7 @@ base::Value* NetLogBadProxyListCallback(const ProxyRetryInfoMap* retry_info, // Returns NetLog parameters on a successfuly proxy resolution. base::Value* NetLogFinishedResolvingProxyCallback( const ProxyInfo* result, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("pac_string", result->ToPacString()); return dict; @@ -1389,7 +1389,7 @@ int ProxyService::DidFinishResolvingProxy(const GURL& url, network_delegate->NotifyResolveProxy(url, load_flags, *this, result); // When logging all events is enabled, dump the proxy list. - if (net_log.IsLogging()) { + if (net_log.GetCaptureMode().enabled()) { net_log.AddEvent( NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, base::Bind(&NetLogFinishedResolvingProxyCallback, result)); diff --git a/net/quic/quic_client_session.cc b/net/quic/quic_client_session.cc index 0dfee92..b5f1d98 100644 --- a/net/quic/quic_client_session.cc +++ b/net/quic/quic_client_session.cc @@ -99,7 +99,7 @@ void RecordHandshakeState(HandshakeState state) { base::Value* NetLogQuicClientSessionCallback( const QuicServerId* server_id, bool require_confirmation, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host", server_id->host()); dict->SetInteger("port", server_id->port()); diff --git a/net/quic/quic_connection_logger.cc b/net/quic/quic_connection_logger.cc index 408eb57..fd60d8e 100644 --- a/net/quic/quic_connection_logger.cc +++ b/net/quic/quic_connection_logger.cc @@ -38,7 +38,7 @@ const int kBoundingSampleInCumulativeHistogram = ((2 + 22) * 21) / 2; base::Value* NetLogQuicPacketCallback(const IPEndPoint* self_address, const IPEndPoint* peer_address, size_t packet_size, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("self_address", self_address->ToString()); dict->SetString("peer_address", peer_address->ToString()); @@ -52,7 +52,7 @@ base::Value* NetLogQuicPacketSentCallback( TransmissionType transmission_type, size_t packet_size, QuicTime sent_time, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("encryption_level", level); dict->SetInteger("transmission_type", transmission_type); @@ -67,7 +67,7 @@ base::Value* NetLogQuicPacketSentCallback( base::Value* NetLogQuicPacketRetransmittedCallback( QuicPacketSequenceNumber old_sequence_number, QuicPacketSequenceNumber new_sequence_number, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("old_packet_sequence_number", base::Uint64ToString(old_sequence_number)); @@ -76,8 +76,9 @@ base::Value* NetLogQuicPacketRetransmittedCallback( return dict; } -base::Value* NetLogQuicPacketHeaderCallback(const QuicPacketHeader* header, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogQuicPacketHeaderCallback( + const QuicPacketHeader* header, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("connection_id", base::Uint64ToString(header->public_header.connection_id)); @@ -91,8 +92,9 @@ base::Value* NetLogQuicPacketHeaderCallback(const QuicPacketHeader* header, return dict; } -base::Value* NetLogQuicStreamFrameCallback(const QuicStreamFrame* frame, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogQuicStreamFrameCallback( + const QuicStreamFrame* frame, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", frame->stream_id); dict->SetBoolean("fin", frame->fin); @@ -102,7 +104,7 @@ base::Value* NetLogQuicStreamFrameCallback(const QuicStreamFrame* frame, } base::Value* NetLogQuicAckFrameCallback(const QuicAckFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("largest_observed", base::Uint64ToString(frame->largest_observed)); @@ -146,7 +148,7 @@ base::Value* NetLogQuicAckFrameCallback(const QuicAckFrame* frame, base::Value* NetLogQuicRstStreamFrameCallback( const QuicRstStreamFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", frame->stream_id); dict->SetInteger("quic_rst_stream_error", frame->error_code); @@ -156,7 +158,7 @@ base::Value* NetLogQuicRstStreamFrameCallback( base::Value* NetLogQuicConnectionCloseFrameCallback( const QuicConnectionCloseFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("quic_error", frame->error_code); dict->SetString("details", frame->error_details); @@ -165,7 +167,7 @@ base::Value* NetLogQuicConnectionCloseFrameCallback( base::Value* NetLogQuicWindowUpdateFrameCallback( const QuicWindowUpdateFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", frame->stream_id); dict->SetString("byte_offset", base::Uint64ToString(frame->byte_offset)); @@ -174,7 +176,7 @@ base::Value* NetLogQuicWindowUpdateFrameCallback( base::Value* NetLogQuicBlockedFrameCallback( const QuicBlockedFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", frame->stream_id); return dict; @@ -182,7 +184,7 @@ base::Value* NetLogQuicBlockedFrameCallback( base::Value* NetLogQuicGoAwayFrameCallback( const QuicGoAwayFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("quic_error", frame->error_code); dict->SetInteger("last_good_stream_id", frame->last_good_stream_id); @@ -192,7 +194,7 @@ base::Value* NetLogQuicGoAwayFrameCallback( base::Value* NetLogQuicStopWaitingFrameCallback( const QuicStopWaitingFrame* frame, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); base::DictionaryValue* sent_info = new base::DictionaryValue(); dict->Set("sent_info", sent_info); @@ -203,7 +205,7 @@ base::Value* NetLogQuicStopWaitingFrameCallback( base::Value* NetLogQuicVersionNegotiationPacketCallback( const QuicVersionNegotiationPacket* packet, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* versions = new base::ListValue(); dict->Set("versions", versions); @@ -216,7 +218,7 @@ base::Value* NetLogQuicVersionNegotiationPacketCallback( base::Value* NetLogQuicCryptoHandshakeMessageCallback( const CryptoHandshakeMessage* message, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("quic_crypto_handshake_message", message->DebugString()); return dict; @@ -225,7 +227,7 @@ base::Value* NetLogQuicCryptoHandshakeMessageCallback( base::Value* NetLogQuicOnConnectionClosedCallback( QuicErrorCode error, bool from_peer, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("quic_error", error); dict->SetBoolean("from_peer", from_peer); @@ -234,7 +236,7 @@ base::Value* NetLogQuicOnConnectionClosedCallback( base::Value* NetLogQuicCertificateVerifiedCallback( scoped_refptr<X509Certificate> cert, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { // Only the subjects are logged so that we can investigate connection pooling. // More fields could be logged in the future. std::vector<std::string> dns_names; diff --git a/net/quic/quic_http_utils.cc b/net/quic/quic_http_utils.cc index 2bad8a6..9a1c6bb 100644 --- a/net/quic/quic_http_utils.cc +++ b/net/quic/quic_http_utils.cc @@ -20,13 +20,12 @@ NET_EXPORT_PRIVATE RequestPriority ConvertQuicPriorityToRequestPriority( IDLE : static_cast<RequestPriority>(HIGHEST - priority); } -base::Value* QuicRequestNetLogCallback( - QuicStreamId stream_id, - const SpdyHeaderBlock* headers, - QuicPriority priority, - NetLog::LogLevel log_level) { +base::Value* QuicRequestNetLogCallback(QuicStreamId stream_id, + const SpdyHeaderBlock* headers, + QuicPriority priority, + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = static_cast<base::DictionaryValue*>( - SpdyHeaderBlockNetLogCallback(headers, log_level)); + SpdyHeaderBlockNetLogCallback(headers, capture_mode)); dict->SetInteger("quic_priority", static_cast<int>(priority)); dict->SetInteger("quic_stream_id", static_cast<int>(stream_id)); return dict; diff --git a/net/quic/quic_http_utils.h b/net/quic/quic_http_utils.h index 862b7c6..6eafbc0 100644 --- a/net/quic/quic_http_utils.h +++ b/net/quic/quic_http_utils.h @@ -25,7 +25,7 @@ NET_EXPORT base::Value* QuicRequestNetLogCallback( QuicStreamId stream_id, const SpdyHeaderBlock* headers, QuicPriority priority, - NetLog::LogLevel log_level); + NetLogCaptureMode capture_mode); } // namespace net diff --git a/net/socket/nss_ssl_util.cc b/net/socket/nss_ssl_util.cc index e0a2257..e98193b 100644 --- a/net/socket/nss_ssl_util.cc +++ b/net/socket/nss_ssl_util.cc @@ -81,7 +81,7 @@ size_t CiphersCopy(const uint16* in, uint16* out) { base::Value* NetLogSSLErrorCallback(int net_error, int ssl_lib_error, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); if (ssl_lib_error) @@ -385,7 +385,7 @@ base::Value* NetLogSSLFailedNSSFunctionCallback( const char* function, const char* param, int ssl_lib_error, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("function", function); if (param[0] != '\0') diff --git a/net/socket/socket_net_log_params.cc b/net/socket/socket_net_log_params.cc index bcc12c8..3dd6595 100644 --- a/net/socket/socket_net_log_params.cc +++ b/net/socket/socket_net_log_params.cc @@ -16,7 +16,7 @@ namespace { base::Value* NetLogSocketErrorCallback(int net_error, int os_error, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); dict->SetInteger("os_error", os_error); @@ -24,14 +24,14 @@ base::Value* NetLogSocketErrorCallback(int net_error, } base::Value* NetLogHostPortPairCallback(const HostPortPair* host_and_port, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host_and_port", host_and_port->ToString()); return dict; } base::Value* NetLogIPEndPointCallback(const IPEndPoint* address, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("address", address->ToString()); return dict; @@ -39,7 +39,7 @@ base::Value* NetLogIPEndPointCallback(const IPEndPoint* address, base::Value* NetLogSourceAddressCallback(const struct sockaddr* net_address, socklen_t address_len, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("source_address", NetAddressToStringWithPort(net_address, address_len)); diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index a41903e..9267abd5 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -2106,7 +2106,7 @@ TEST_F(SSLClientSocketTest, Read_FullLogging) { TestCompletionCallback callback; TestNetLog log; - log.SetLogLevel(NetLog::LOG_ALL); + log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); scoped_ptr<StreamSocket> transport( new TCPClientSocket(addr, &log, NetLog::Source())); int rv = transport->Connect(callback.callback()); diff --git a/net/socket/transport_client_socket_pool.cc b/net/socket/transport_client_socket_pool.cc index eac2868..5263e70 100644 --- a/net/socket/transport_client_socket_pool.cc +++ b/net/socket/transport_client_socket_pool.cc @@ -481,7 +481,7 @@ int TransportClientSocketPool::RequestSocket( void TransportClientSocketPool::NetLogTcpClientSocketPoolRequestedSocket( const BoundNetLog& net_log, const scoped_refptr<TransportSocketParams>* casted_params) { - if (net_log.IsLogging()) { + if (net_log.GetCaptureMode().enabled()) { // TODO(eroman): Split out the host and port parameters. net_log.AddEvent( NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, @@ -498,7 +498,7 @@ void TransportClientSocketPool::RequestSockets( const scoped_refptr<TransportSocketParams>* casted_params = static_cast<const scoped_refptr<TransportSocketParams>*>(params); - if (net_log.IsLogging()) { + if (net_log.GetCaptureMode().enabled()) { // TODO(eroman): Split out the host and port parameters. net_log.AddEvent( NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS, diff --git a/net/spdy/spdy_header_block.cc b/net/spdy/spdy_header_block.cc index bbe9c716..92c6234 100644 --- a/net/spdy/spdy_header_block.cc +++ b/net/spdy/spdy_header_block.cc @@ -9,17 +9,15 @@ namespace net { -base::Value* SpdyHeaderBlockNetLogCallback( - const SpdyHeaderBlock* headers, - NetLog::LogLevel log_level) { +base::Value* SpdyHeaderBlockNetLogCallback(const SpdyHeaderBlock* headers, + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); base::DictionaryValue* headers_dict = new base::DictionaryValue(); for (SpdyHeaderBlock::const_iterator it = headers->begin(); it != headers->end(); ++it) { headers_dict->SetWithoutPathExpansion( - it->first, - new base::StringValue( - ElideHeaderValueForNetLog(log_level, it->first, it->second))); + it->first, new base::StringValue(ElideHeaderValueForNetLog( + capture_mode, it->first, it->second))); } dict->Set("headers", headers_dict); return dict; diff --git a/net/spdy/spdy_header_block.h b/net/spdy/spdy_header_block.h index 7d2a075..b496642 100644 --- a/net/spdy/spdy_header_block.h +++ b/net/spdy/spdy_header_block.h @@ -21,7 +21,7 @@ typedef std::map<std::string, std::string> SpdyHeaderBlock; // ownership of returned value. NET_EXPORT base::Value* SpdyHeaderBlockNetLogCallback( const SpdyHeaderBlock* headers, - NetLog::LogLevel log_level); + NetLogCaptureMode capture_mode); // Converts NetLog event parameters into a SPDY header block and writes them // to |headers|. |event_param| must have been created by diff --git a/net/spdy/spdy_header_block_unittest.cc b/net/spdy/spdy_header_block_unittest.cc index b69f37c..99e9ac2 100644 --- a/net/spdy/spdy_header_block_unittest.cc +++ b/net/spdy/spdy_header_block_unittest.cc @@ -18,8 +18,8 @@ TEST(SpdyHeaderBlockTest, ToNetLogParamAndBackAgain) { headers["A"] = "a"; headers["B"] = "b"; - scoped_ptr<base::Value> event_param( - SpdyHeaderBlockNetLogCallback(&headers, NetLog::LOG_ALL_BUT_BYTES)); + scoped_ptr<base::Value> event_param(SpdyHeaderBlockNetLogCallback( + &headers, NetLogCaptureMode::IncludeCookiesAndCredentials())); SpdyHeaderBlock headers2; ASSERT_TRUE(SpdyHeaderBlockFromNetLogParam(event_param.get(), &headers2)); diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 2f8af1e..e25a88c 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -59,13 +59,13 @@ const int kMinPushedStreamLifetimeSeconds = 300; scoped_ptr<base::ListValue> SpdyHeaderBlockToListValue( const SpdyHeaderBlock& headers, - net::NetLog::LogLevel log_level) { + net::NetLogCaptureMode capture_mode) { scoped_ptr<base::ListValue> headers_list(new base::ListValue()); for (SpdyHeaderBlock::const_iterator it = headers.begin(); it != headers.end(); ++it) { headers_list->AppendString( it->first + ": " + - ElideHeaderValueForNetLog(log_level, it->first, it->second)); + ElideHeaderValueForNetLog(capture_mode, it->first, it->second)); } return headers_list.Pass(); } @@ -75,10 +75,10 @@ base::Value* NetLogSpdySynStreamSentCallback(const SpdyHeaderBlock* headers, bool unidirectional, SpdyPriority spdy_priority, SpdyStreamId stream_id, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->Set("headers", - SpdyHeaderBlockToListValue(*headers, log_level).release()); + SpdyHeaderBlockToListValue(*headers, capture_mode).release()); dict->SetBoolean("fin", fin); dict->SetBoolean("unidirectional", unidirectional); dict->SetInteger("priority", static_cast<int>(spdy_priority)); @@ -93,10 +93,10 @@ base::Value* NetLogSpdySynStreamReceivedCallback( SpdyPriority spdy_priority, SpdyStreamId stream_id, SpdyStreamId associated_stream, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->Set("headers", - SpdyHeaderBlockToListValue(*headers, log_level).release()); + SpdyHeaderBlockToListValue(*headers, capture_mode).release()); dict->SetBoolean("fin", fin); dict->SetBoolean("unidirectional", unidirectional); dict->SetInteger("priority", static_cast<int>(spdy_priority)); @@ -109,18 +109,19 @@ base::Value* NetLogSpdySynReplyOrHeadersReceivedCallback( const SpdyHeaderBlock* headers, bool fin, SpdyStreamId stream_id, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->Set("headers", - SpdyHeaderBlockToListValue(*headers, log_level).release()); + SpdyHeaderBlockToListValue(*headers, capture_mode).release()); dict->SetBoolean("fin", fin); dict->SetInteger("stream_id", stream_id); return dict; } -base::Value* NetLogSpdySessionCloseCallback(int net_error, - const std::string* description, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogSpdySessionCloseCallback( + int net_error, + const std::string* description, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); dict->SetString("description", *description); @@ -128,16 +129,17 @@ base::Value* NetLogSpdySessionCloseCallback(int net_error, } base::Value* NetLogSpdySessionCallback(const HostPortProxyPair* host_pair, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host", host_pair->first.ToString()); dict->SetString("proxy", host_pair->second.ToPacString()); return dict; } -base::Value* NetLogSpdyInitializedCallback(NetLog::Source source, - const NextProto protocol_version, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogSpdyInitializedCallback( + NetLog::Source source, + const NextProto protocol_version, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); if (source.IsValid()) { source.AddToEventParameters(dict); @@ -149,7 +151,7 @@ base::Value* NetLogSpdyInitializedCallback(NetLog::Source source, base::Value* NetLogSpdySettingsCallback(const HostPortPair& host_port_pair, bool clear_persisted, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("host", host_port_pair.ToString()); dict->SetBoolean("clear_persisted", clear_persisted); @@ -160,7 +162,7 @@ base::Value* NetLogSpdySettingCallback(SpdySettingsIds id, const SpdyMajorVersion protocol_version, SpdySettingsFlags flags, uint32 value, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("id", SpdyConstants::SerializeSettingId(protocol_version, id)); @@ -172,7 +174,7 @@ base::Value* NetLogSpdySettingCallback(SpdySettingsIds id, base::Value* NetLogSpdySendSettingsCallback( const SettingsMap* settings, const SpdyMajorVersion protocol_version, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); base::ListValue* settings_list = new base::ListValue(); for (SettingsMap::const_iterator it = settings->begin(); @@ -193,7 +195,7 @@ base::Value* NetLogSpdySendSettingsCallback( base::Value* NetLogSpdyWindowUpdateFrameCallback( SpdyStreamId stream_id, uint32 delta, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", static_cast<int>(stream_id)); dict->SetInteger("delta", delta); @@ -203,7 +205,7 @@ base::Value* NetLogSpdyWindowUpdateFrameCallback( base::Value* NetLogSpdySessionWindowUpdateCallback( int32 delta, int32 window_size, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("delta", delta); dict->SetInteger("window_size", window_size); @@ -213,7 +215,7 @@ base::Value* NetLogSpdySessionWindowUpdateCallback( base::Value* NetLogSpdyDataCallback(SpdyStreamId stream_id, int size, bool fin, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", static_cast<int>(stream_id)); dict->SetInteger("size", size); @@ -224,7 +226,7 @@ base::Value* NetLogSpdyDataCallback(SpdyStreamId stream_id, base::Value* NetLogSpdyRstCallback(SpdyStreamId stream_id, int status, const std::string* description, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", static_cast<int>(stream_id)); dict->SetInteger("status", status); @@ -235,7 +237,7 @@ base::Value* NetLogSpdyRstCallback(SpdyStreamId stream_id, base::Value* NetLogSpdyPingCallback(SpdyPingId unique_id, bool is_ack, const char* type, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("unique_id", static_cast<int>(unique_id)); dict->SetString("type", type); @@ -247,7 +249,7 @@ base::Value* NetLogSpdyGoAwayCallback(SpdyStreamId last_stream_id, int active_streams, int unclaimed_streams, SpdyGoAwayStatus status, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("last_accepted_stream_id", static_cast<int>(last_stream_id)); @@ -261,17 +263,19 @@ base::Value* NetLogSpdyPushPromiseReceivedCallback( const SpdyHeaderBlock* headers, SpdyStreamId stream_id, SpdyStreamId promised_stream_id, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->Set("headers", - SpdyHeaderBlockToListValue(*headers, log_level).release()); + SpdyHeaderBlockToListValue(*headers, capture_mode).release()); dict->SetInteger("id", stream_id); dict->SetInteger("promised_stream_id", promised_stream_id); return dict; } base::Value* NetLogSpdyAdoptedPushStreamCallback( - SpdyStreamId stream_id, const GURL* url, NetLog::LogLevel log_level) { + SpdyStreamId stream_id, + const GURL* url, + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", stream_id); dict->SetString("url", url->spec()); @@ -1078,7 +1082,7 @@ scoped_ptr<SpdyFrame> SpdySession::CreateSynStream( streams_initiated_count_++; - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { const NetLog::EventType type = (GetProtocolVersion() <= SPDY3) ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM @@ -1188,7 +1192,7 @@ scoped_ptr<SpdyBuffer> SpdySession::CreateDataBuffer(SpdyStreamId stream_id, if (effective_len < len) flags = static_cast<SpdyDataFlags>(flags & ~DATA_FLAG_FIN); - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SEND_DATA, base::Bind(&NetLogSpdyDataCallback, stream_id, effective_len, (flags & DATA_FLAG_FIN) != 0)); @@ -2042,7 +2046,7 @@ void SpdySession::OnStreamFrameData(SpdyStreamId stream_id, bool fin) { CHECK(in_io_loop_); DCHECK_LT(len, 1u << 24); - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { net_log().AddEvent( NetLog::TYPE_HTTP2_SESSION_RECV_DATA, base::Bind(&NetLogSpdyDataCallback, stream_id, len, fin)); @@ -2115,7 +2119,7 @@ void SpdySession::OnSettings(bool clear_persisted) { if (clear_persisted) http_server_properties_->ClearSpdySettings(host_port_pair()); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_SETTINGS, base::Bind(&NetLogSpdySettingsCallback, host_port_pair(), clear_persisted)); @@ -2228,7 +2232,7 @@ void SpdySession::OnSynStream(SpdyStreamId stream_id, base::Time response_time = base::Time::Now(); base::TimeTicks recv_first_byte_time = time_func_(); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( NetLog::TYPE_HTTP2_SESSION_PUSHED_SYN_STREAM, base::Bind(&NetLogSpdySynStreamReceivedCallback, &headers, fin, @@ -2300,7 +2304,7 @@ void SpdySession::OnSynReply(SpdyStreamId stream_id, base::Time response_time = base::Time::Now(); base::TimeTicks recv_first_byte_time = time_func_(); - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SYN_REPLY, base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, &headers, fin, stream_id)); @@ -2345,7 +2349,7 @@ void SpdySession::OnHeaders(SpdyStreamId stream_id, const SpdyHeaderBlock& headers) { CHECK(in_io_loop_); - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_HEADERS, base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, &headers, fin, stream_id)); @@ -2728,7 +2732,7 @@ void SpdySession::OnPushPromise(SpdyStreamId stream_id, const SpdyHeaderBlock& headers) { CHECK(in_io_loop_); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_PUSH_PROMISE, base::Bind(&NetLogSpdyPushPromiseReceivedCallback, &headers, stream_id, promised_stream_id)); @@ -2922,7 +2926,7 @@ void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { buffered_spdy_framer_->CreatePingFrame(unique_id, is_ack)); EnqueueSessionWrite(HIGHEST, PING, ping_frame.Pass()); - if (net_log().IsLogging()) { + if (net_log().GetCaptureMode().enabled()) { net_log().AddEvent( NetLog::TYPE_HTTP2_SESSION_PING, base::Bind(&NetLogSpdyPingCallback, unique_id, is_ack, "sent")); diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc index 7f29364..f841be1 100644 --- a/net/spdy/spdy_stream.cc +++ b/net/spdy/spdy_stream.cc @@ -20,10 +20,11 @@ namespace net { namespace { -base::Value* NetLogSpdyStreamErrorCallback(SpdyStreamId stream_id, - int status, - const std::string* description, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogSpdyStreamErrorCallback( + SpdyStreamId stream_id, + int status, + const std::string* description, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", static_cast<int>(stream_id)); dict->SetInteger("status", status); @@ -35,7 +36,7 @@ base::Value* NetLogSpdyStreamWindowUpdateCallback( SpdyStreamId stream_id, int32 delta, int32 window_size, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("stream_id", stream_id); dict->SetInteger("delta", delta); diff --git a/net/ssl/openssl_ssl_util.cc b/net/ssl/openssl_ssl_util.cc index f7acd62..54a3400 100644 --- a/net/ssl/openssl_ssl_util.cc +++ b/net/ssl/openssl_ssl_util.cc @@ -155,7 +155,7 @@ int MapOpenSSLErrorSSL(uint32_t error_code) { base::Value* NetLogOpenSSLErrorCallback(int net_error, int ssl_error, const OpenSSLErrorInfo& error_info, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("net_error", net_error); dict->SetInteger("ssl_error", ssl_error); diff --git a/net/tools/gdig/gdig.cc b/net/tools/gdig/gdig.cc index faaffa7..285668b 100644 --- a/net/tools/gdig/gdig.cc +++ b/net/tools/gdig/gdig.cc @@ -296,15 +296,17 @@ bool GDig::ParseCommandLine(int argc, const char* argv[]) { if (parsed_command_line.HasSwitch("net_log")) { std::string log_param = parsed_command_line.GetSwitchValueASCII("net_log"); - NetLog::LogLevel level = NetLog::LOG_ALL_BUT_BYTES; + NetLogCaptureMode capture_mode = + NetLogCaptureMode::IncludeCookiesAndCredentials(); if (log_param.length() > 0) { - std::map<std::string, NetLog::LogLevel> log_levels; - log_levels["all"] = NetLog::LOG_ALL; - log_levels["no_bytes"] = NetLog::LOG_ALL_BUT_BYTES; + std::map<std::string, NetLogCaptureMode> capture_modes; + capture_modes["all"] = NetLogCaptureMode::IncludeSocketBytes(); + capture_modes["no_bytes"] = + NetLogCaptureMode::IncludeCookiesAndCredentials(); - if (log_levels.find(log_param) != log_levels.end()) { - level = log_levels[log_param]; + if (capture_modes.find(log_param) != capture_modes.end()) { + capture_mode = capture_modes[log_param]; } else { fprintf(stderr, "Invalid net_log parameter\n"); return false; @@ -312,7 +314,7 @@ bool GDig::ParseCommandLine(int argc, const char* argv[]) { } log_.reset(new NetLog); log_observer_.reset(new FileNetLogObserver(stderr)); - log_->DeprecatedAddObserver(log_observer_.get(), level); + log_->DeprecatedAddObserver(log_observer_.get(), capture_mode); } print_config_ = parsed_command_line.HasSwitch("print_config"); diff --git a/net/tools/get_server_time/get_server_time.cc b/net/tools/get_server_time/get_server_time.cc index e8d4d76..98a48c1 100644 --- a/net/tools/get_server_time/get_server_time.cc +++ b/net/tools/get_server_time/get_server_time.cc @@ -226,7 +226,8 @@ int main(int argc, char* argv[]) { // printing_log_observer. net::NetLog net_log; PrintingLogObserver printing_log_observer; - net_log.DeprecatedAddObserver(&printing_log_observer, net::NetLog::LOG_ALL); + net_log.DeprecatedAddObserver(&printing_log_observer, + net::NetLogCaptureMode::IncludeSocketBytes()); QuitDelegate delegate; scoped_ptr<net::URLFetcher> fetcher( diff --git a/net/udp/udp_net_log_parameters.cc b/net/udp/udp_net_log_parameters.cc index c258823..fb25b4c 100644 --- a/net/udp/udp_net_log_parameters.cc +++ b/net/udp/udp_net_log_parameters.cc @@ -16,10 +16,10 @@ namespace { base::Value* NetLogUDPDataTranferCallback(int byte_count, const char* bytes, const IPEndPoint* address, - NetLog::LogLevel log_level) { + NetLogCaptureMode capture_mode) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetInteger("byte_count", byte_count); - if (NetLog::IsLoggingBytes(log_level)) + if (capture_mode.include_socket_bytes()) dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); if (address) dict->SetString("address", address->ToString()); @@ -27,7 +27,7 @@ base::Value* NetLogUDPDataTranferCallback(int byte_count, } base::Value* NetLogUDPConnectCallback(const IPEndPoint* address, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("address", address->ToString()); return dict; diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc index 8259777..2fce83f 100644 --- a/net/udp/udp_socket_libevent.cc +++ b/net/udp/udp_socket_libevent.cc @@ -496,7 +496,7 @@ void UDPSocketLibevent::LogRead(int result, return; } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { DCHECK(addr_len > 0); DCHECK(addr); @@ -533,7 +533,7 @@ void UDPSocketLibevent::LogWrite(int result, return; } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, CreateNetLogUDPDataTranferCallback(result, bytes, address)); diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc index b47247a..8c226f9 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -681,7 +681,7 @@ void UDPSocketWin::LogRead(int result, return; } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_RECEIVED, CreateNetLogUDPDataTranferCallback(result, bytes, address)); @@ -698,7 +698,7 @@ void UDPSocketWin::LogWrite(int result, return; } - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, CreateNetLogUDPDataTranferCallback(result, bytes, address)); diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index c539bdf..213307c 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -881,7 +881,7 @@ void URLRequest::OrphanJob() { int URLRequest::Redirect(const RedirectInfo& redirect_info) { // Matches call in NotifyReceivedRedirect. OnCallToDelegateComplete(); - if (net_log_.IsLogging()) { + if (net_log_.GetCaptureMode().enabled()) { net_log_.AddEvent( NetLog::TYPE_URL_REQUEST_REDIRECTED, NetLog::StringCallback("location", diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index ce58e6a..106cb85 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -27,7 +27,7 @@ namespace { // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event. base::Value* FiltersSetCallback(Filter* filter, - NetLog::LogLevel /* log_level */) { + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* event_params = new base::DictionaryValue(); event_params->SetString("filters", filter->OrderedFilterList()); return event_params; @@ -698,7 +698,8 @@ bool URLRequestJob::ReadFilteredData(int* bytes_read) { } // If logging all bytes is enabled, log the filtered bytes read. - if (rv && request() && request()->net_log().IsLoggingBytes() && + if (rv && request() && + request()->net_log().GetCaptureMode().include_socket_bytes() && filtered_data_len > 0) { request()->net_log().AddByteTransferEvent( NetLog::TYPE_URL_REQUEST_JOB_FILTERED_BYTES_READ, @@ -789,7 +790,8 @@ void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { void URLRequestJob::OnRawReadComplete(int bytes_read) { DCHECK(raw_read_buffer_.get()); // If |filter_| is non-NULL, bytes will be logged after it is applied instead. - if (!filter_.get() && request() && request()->net_log().IsLoggingBytes() && + if (!filter_.get() && request() && + request()->net_log().GetCaptureMode().include_socket_bytes() && bytes_read > 0) { request()->net_log().AddByteTransferEvent( NetLog::TYPE_URL_REQUEST_JOB_BYTES_READ, diff --git a/net/url_request/url_request_netlog_params.cc b/net/url_request/url_request_netlog_params.cc index a1e8243..9833fe3 100644 --- a/net/url_request/url_request_netlog_params.cc +++ b/net/url_request/url_request_netlog_params.cc @@ -10,12 +10,13 @@ namespace net { -base::Value* NetLogURLRequestStartCallback(const GURL* url, - const std::string* method, - int load_flags, - RequestPriority priority, - int64 upload_id, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogURLRequestStartCallback( + const GURL* url, + const std::string* method, + int load_flags, + RequestPriority priority, + int64 upload_id, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("url", url->possibly_invalid_spec()); dict->SetString("method", *method); diff --git a/net/url_request/url_request_netlog_params.h b/net/url_request/url_request_netlog_params.h index 9ca36bc..d216105 100644 --- a/net/url_request/url_request_netlog_params.h +++ b/net/url_request/url_request_netlog_params.h @@ -26,7 +26,7 @@ NET_EXPORT base::Value* NetLogURLRequestStartCallback( int load_flags, RequestPriority priority, int64 upload_id, - NetLog::LogLevel /* log_level */); + NetLogCaptureMode /* capture_mode */); // Attempts to extract the load flags from a Value created by the above // function. On success, sets |load_flags| accordingly and returns true. diff --git a/net/url_request/url_request_throttler_entry.cc b/net/url_request/url_request_throttler_entry.cc index 1197f6f..84a9014 100644 --- a/net/url_request/url_request_throttler_entry.cc +++ b/net/url_request/url_request_throttler_entry.cc @@ -52,10 +52,11 @@ const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] = "disable"; // Returns NetLog parameters when a request is rejected by throttling. -base::Value* NetLogRejectedRequestCallback(const std::string* url_id, - int num_failures, - const base::TimeDelta& release_after, - NetLog::LogLevel /* log_level */) { +base::Value* NetLogRejectedRequestCallback( + const std::string* url_id, + int num_failures, + const base::TimeDelta& release_after, + NetLogCaptureMode /* capture_mode */) { base::DictionaryValue* dict = new base::DictionaryValue(); dict->SetString("url", *url_id); dict->SetInteger("num_failures", num_failures); diff --git a/remoting/base/vlog_net_log.cc b/remoting/base/vlog_net_log.cc index db72ad3..39a388a 100644 --- a/remoting/base/vlog_net_log.cc +++ b/remoting/base/vlog_net_log.cc @@ -42,7 +42,8 @@ void VlogNetLog::Observer::OnAddEntry(const net::NetLog::Entry& entry) { VlogNetLog::VlogNetLog() : observer_(new Observer()) { - DeprecatedAddObserver(observer_.get(), LOG_ALL_BUT_BYTES); + DeprecatedAddObserver(observer_.get(), + net::NetLogCaptureMode::IncludeCookiesAndCredentials()); } VlogNetLog::~VlogNetLog() { |