2015-06-05 14:54:38 +00:00
|
|
|
// 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 22:58:12 +00:00
|
|
|
#include "brightray/browser/net_log.h"
|
2015-06-05 14:54:38 +00:00
|
|
|
|
2017-08-12 17:27:48 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2017-11-02 14:00:16 +00:00
|
|
|
#include "base/callback.h"
|
2015-06-05 14:54:38 +00:00
|
|
|
#include "base/command_line.h"
|
2015-08-11 10:29:55 +00:00
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/values.h"
|
2015-06-05 14:54:38 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2017-08-24 13:08:05 +00:00
|
|
|
#include "net/log/file_net_log_observer.h"
|
2015-06-05 14:54:38 +00:00
|
|
|
#include "net/log/net_log_util.h"
|
2015-08-11 10:29:55 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
2015-06-05 14:54:38 +00:00
|
|
|
|
2015-06-06 09:03:07 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> GetConstants() {
|
|
|
|
std::unique_ptr<base::DictionaryValue> constants = net::GetNetConstants();
|
2015-06-06 09:03:07 +00:00
|
|
|
|
|
|
|
// Adding client information to constants dictionary.
|
2018-04-12 12:48:32 +00:00
|
|
|
auto client_info = std::make_unique<base::DictionaryValue>();
|
2015-06-09 01:51:38 +00:00
|
|
|
client_info->SetString(
|
|
|
|
"command_line",
|
2015-06-06 09:03:07 +00:00
|
|
|
base::CommandLine::ForCurrentProcess()->GetCommandLineString());
|
|
|
|
|
2017-08-12 17:27:48 +00:00
|
|
|
constants->Set("clientInfo", std::move(client_info));
|
2015-06-09 01:51:38 +00:00
|
|
|
return constants;
|
2015-06-06 09:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
NetLog::NetLog() {}
|
2015-09-07 17:14:13 +00:00
|
|
|
|
|
|
|
NetLog::~NetLog() {
|
2017-11-02 15:06:18 +00:00
|
|
|
if (file_net_log_observer_) {
|
|
|
|
file_net_log_observer_->StopObserving(nullptr, base::Closure());
|
|
|
|
file_net_log_observer_.reset();
|
|
|
|
}
|
2015-09-07 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 13:08:05 +00:00
|
|
|
void NetLog::StartLogging() {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2015-08-11 10:29:55 +00:00
|
|
|
if (!command_line->HasSwitch(switches::kLogNetLog))
|
|
|
|
return;
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
base::FilePath log_path =
|
|
|
|
command_line->GetSwitchValuePath(switches::kLogNetLog);
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<base::Value> constants(GetConstants());
|
2017-08-24 13:08:05 +00:00
|
|
|
net::NetLogCaptureMode capture_mode =
|
|
|
|
net::NetLogCaptureMode::IncludeCookiesAndCredentials();
|
|
|
|
|
2017-11-02 14:00:16 +00:00
|
|
|
file_net_log_observer_ =
|
2017-08-24 13:08:05 +00:00
|
|
|
net::FileNetLogObserver::CreateUnbounded(log_path, std::move(constants));
|
|
|
|
file_net_log_observer_->StartObserving(this, capture_mode);
|
2015-06-05 14:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace brightray
|