electron/brightray/browser/net_log.cc

65 lines
1.8 KiB
C++
Raw Normal View History

2015-06-05 20:24:38 +05:30
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "brightray/browser/net_log.h"
2015-06-05 20:24:38 +05:30
#include "base/command_line.h"
2015-08-11 18:29:55 +08:00
#include "base/files/file_path.h"
#include "base/values.h"
2015-06-05 20:24:38 +05:30
#include "content/public/common/content_switches.h"
#include "net/log/net_log_util.h"
2015-08-11 18:29:55 +08:00
namespace brightray {
2015-06-05 20:24:38 +05:30
2015-06-06 14:33:07 +05:30
namespace {
std::unique_ptr<base::DictionaryValue> GetConstants() {
std::unique_ptr<base::DictionaryValue> constants = net::GetNetConstants();
2015-06-06 14:33:07 +05:30
// Adding client information to constants dictionary.
2016-07-10 13:12:33 +02:00
auto* client_info = new base::DictionaryValue();
2015-06-09 09:51:38 +08:00
client_info->SetString(
"command_line",
2015-06-06 14:33:07 +05:30
base::CommandLine::ForCurrentProcess()->GetCommandLineString());
constants->Set("clientInfo", client_info);
2015-06-09 09:51:38 +08:00
return constants;
2015-06-06 14:33:07 +05:30
}
} // namespace
2015-08-11 18:29:55 +08:00
NetLog::NetLog() {
}
NetLog::~NetLog() {
}
void NetLog::StartLogging(net::URLRequestContext* url_request_context) {
2015-06-05 20:24:38 +05:30
auto command_line = base::CommandLine::ForCurrentProcess();
2015-08-11 18:29:55 +08:00
if (!command_line->HasSwitch(switches::kLogNetLog))
return;
base::FilePath log_path =
command_line->GetSwitchValuePath(switches::kLogNetLog);
2015-08-11 18:29:55 +08:00
#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;
2015-06-05 20:24:38 +05:30
}
std::unique_ptr<base::Value> constants(GetConstants());
write_to_file_observer_.StartObserving(this,
2016-03-08 20:59:29 +09:00
std::move(log_file_),
constants.get(),
url_request_context);
2015-06-05 20:24:38 +05:30
}
} // namespace brightray