Commit 4eca3b25 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Don't write to --log-net-log from MojoNetLog when running in-process.

Bug: 745877
Change-Id: I05d3fcdbe55509d808f0ab696b159ca22876a0b8
Reviewed-on: https://chromium-review.googlesource.com/576358Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487621}
parent 994823a0
...@@ -25,23 +25,26 @@ std::unique_ptr<NetworkService> NetworkService::Create() { ...@@ -25,23 +25,26 @@ std::unique_ptr<NetworkService> NetworkService::Create() {
class NetworkServiceImpl::MojoNetLog : public net::NetLog { class NetworkServiceImpl::MojoNetLog : public net::NetLog {
public: public:
MojoNetLog() { MojoNetLog() {}
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess(); // If specified by the command line, stream network events (NetLog) to a
// file on disk. This will last for the duration of the process.
// If specified by the command line, stream network events (NetLog) to a void ProcessCommandLine(const base::CommandLine& command_line) {
// file on disk. This will last for the duration of the process. if (!command_line.HasSwitch(switches::kLogNetLog))
if (command_line->HasSwitch(switches::kLogNetLog)) { return;
base::FilePath log_path =
command_line->GetSwitchValuePath(switches::kLogNetLog); base::FilePath log_path =
net::NetLogCaptureMode capture_mode = command_line.GetSwitchValuePath(switches::kLogNetLog);
net::NetLogCaptureMode::IncludeCookiesAndCredentials();
// TODO(eroman): Should get capture mode from the command line.
file_net_log_observer_ = net::NetLogCaptureMode capture_mode =
net::FileNetLogObserver::CreateUnbounded(log_path, nullptr); net::NetLogCaptureMode::IncludeCookiesAndCredentials();
file_net_log_observer_->StartObserving(this, capture_mode);
} file_net_log_observer_ =
net::FileNetLogObserver::CreateUnbounded(log_path, nullptr);
file_net_log_observer_->StartObserving(this, capture_mode);
} }
~MojoNetLog() override { ~MojoNetLog() override {
if (file_net_log_observer_) if (file_net_log_observer_)
file_net_log_observer_->StopObserving(nullptr, base::OnceClosure()); file_net_log_observer_->StopObserving(nullptr, base::OnceClosure());
...@@ -62,6 +65,11 @@ NetworkServiceImpl::NetworkServiceImpl( ...@@ -62,6 +65,11 @@ NetworkServiceImpl::NetworkServiceImpl(
if (registry_) { if (registry_) {
registry_->AddInterface<mojom::NetworkService>( registry_->AddInterface<mojom::NetworkService>(
base::Bind(&NetworkServiceImpl::Create, base::Unretained(this))); base::Bind(&NetworkServiceImpl::Create, base::Unretained(this)));
// Note: The command line switches are only checked when running out of
// process, since in in-process mode other code may already be writing to
// the destination log file.
net_log_->ProcessCommandLine(*base::CommandLine::ForCurrentProcess());
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment