Don't specify URLRequestContext when starting logging

Related CL: https://codereview.chromium.org/2698143004
This commit is contained in:
Tony Ganch 2017-08-24 15:08:05 +02:00 committed by Cheng Zhao
parent 4412836e77
commit 0ad967c9a5
3 changed files with 10 additions and 25 deletions

View file

@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/values.h" #include "base/values.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "net/log/file_net_log_observer.h"
#include "net/log/net_log_util.h" #include "net/log/net_log_util.h"
namespace brightray { namespace brightray {
@ -38,30 +39,20 @@ NetLog::NetLog() {
NetLog::~NetLog() { NetLog::~NetLog() {
} }
void NetLog::StartLogging(net::URLRequestContext* url_request_context) { void NetLog::StartLogging() {
auto command_line = base::CommandLine::ForCurrentProcess(); auto command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kLogNetLog)) if (!command_line->HasSwitch(switches::kLogNetLog))
return; return;
base::FilePath log_path = base::FilePath log_path =
command_line->GetSwitchValuePath(switches::kLogNetLog); command_line->GetSwitchValuePath(switches::kLogNetLog);
#if defined(OS_WIN)
log_file_.reset(_wfopen(log_path.value().c_str(), L"w"));
#elif defined(OS_POSIX)
log_file_.reset(fopen(log_path.value().c_str(), "w"));
#endif
if (!log_file_) {
LOG(ERROR) << "Could not open file: " << log_path.value()
<< "for net logging";
return;
}
std::unique_ptr<base::Value> constants(GetConstants()); std::unique_ptr<base::Value> constants(GetConstants());
write_to_file_observer_.StartObserving(this, net::NetLogCaptureMode capture_mode =
std::move(log_file_), net::NetLogCaptureMode::IncludeCookiesAndCredentials();
constants.get(),
url_request_context); std::unique_ptr<net::FileNetLogObserver> file_net_log_observer_ =
net::FileNetLogObserver::CreateUnbounded(log_path, std::move(constants));
file_net_log_observer_->StartObserving(this, capture_mode);
} }
} // namespace brightray } // namespace brightray

View file

@ -5,10 +5,7 @@
#ifndef BRIGHTRAY_BROWSER_NET_LOG_H_ #ifndef BRIGHTRAY_BROWSER_NET_LOG_H_
#define BRIGHTRAY_BROWSER_NET_LOG_H_ #define BRIGHTRAY_BROWSER_NET_LOG_H_
#include "base/files/scoped_file.h"
#include "net/log/net_log.h" #include "net/log/net_log.h"
#include "net/log/file_net_log_observer.h"
#include "net/url_request/url_request_context.h"
namespace brightray { namespace brightray {
@ -17,12 +14,9 @@ class NetLog : public net::NetLog {
NetLog(); NetLog();
~NetLog() override; ~NetLog() override;
void StartLogging(net::URLRequestContext* url_request_context); void StartLogging();
private: private:
base::ScopedFILE log_file_;
net::FileNetLogObserver write_to_file_observer_;
DISALLOW_COPY_AND_ASSIGN(NetLog); DISALLOW_COPY_AND_ASSIGN(NetLog);
}; };

View file

@ -181,7 +181,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
// --log-net-log // --log-net-log
if (net_log_) { if (net_log_) {
net_log_->StartLogging(url_request_context_.get()); net_log_->StartLogging();
url_request_context_->set_net_log(net_log_); url_request_context_->set_net_log(net_log_);
} }