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.
|
|
|
|
|
2017-05-18 15:58:12 -07:00
|
|
|
#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 {
|
|
|
|
|
2016-05-23 10:59:07 +09:00
|
|
|
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() {
|
2015-09-07 22:44:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-03-23 15:47:30 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-23 10:59:07 +09:00
|
|
|
std::unique_ptr<base::Value> constants(GetConstants());
|
2015-09-07 22:44:13 +05:30
|
|
|
write_to_file_observer_.StartObserving(this,
|
2016-03-08 20:59:29 +09:00
|
|
|
std::move(log_file_),
|
2015-09-07 22:44:13 +05:30
|
|
|
constants.get(),
|
|
|
|
url_request_context);
|
2015-06-05 20:24:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace brightray
|