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,15 +25,18 @@ std::unique_ptr<NetworkService> NetworkService::Create() {
class NetworkServiceImpl::MojoNetLog : public net::NetLog {
public:
MojoNetLog() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
MojoNetLog() {}
// 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 (command_line->HasSwitch(switches::kLogNetLog)) {
void ProcessCommandLine(const base::CommandLine& command_line) {
if (!command_line.HasSwitch(switches::kLogNetLog))
return;
base::FilePath log_path =
command_line->GetSwitchValuePath(switches::kLogNetLog);
command_line.GetSwitchValuePath(switches::kLogNetLog);
// TODO(eroman): Should get capture mode from the command line.
net::NetLogCaptureMode capture_mode =
net::NetLogCaptureMode::IncludeCookiesAndCredentials();
......@@ -41,7 +44,7 @@ class NetworkServiceImpl::MojoNetLog : public net::NetLog {
net::FileNetLogObserver::CreateUnbounded(log_path, nullptr);
file_net_log_observer_->StartObserving(this, capture_mode);
}
}
~MojoNetLog() override {
if (file_net_log_observer_)
file_net_log_observer_->StopObserving(nullptr, base::OnceClosure());
......@@ -62,6 +65,11 @@ NetworkServiceImpl::NetworkServiceImpl(
if (registry_) {
registry_->AddInterface<mojom::NetworkService>(
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