electron/brightray/browser/net_log.cc

62 lines
1.7 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 <utility>
#include "base/callback.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/file_net_log_observer.h"
2015-06-05 20:24:38 +05:30
#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.
auto client_info = std::make_unique<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", std::move(client_info));
2015-06-09 09:51:38 +08:00
return constants;
2015-06-06 14:33:07 +05:30
}
} // namespace
2018-04-17 21:56:12 -04:00
NetLog::NetLog() {}
NetLog::~NetLog() {
2017-11-02 20:36:18 +05:30
if (file_net_log_observer_) {
file_net_log_observer_->StopObserving(nullptr, base::Closure());
file_net_log_observer_.reset();
}
}
void NetLog::StartLogging() {
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);
std::unique_ptr<base::Value> constants(GetConstants());
net::NetLogCaptureMode capture_mode =
net::NetLogCaptureMode::IncludeCookiesAndCredentials();
file_net_log_observer_ =
net::FileNetLogObserver::CreateUnbounded(log_path, std::move(constants));
file_net_log_observer_->StartObserving(this, capture_mode);
2015-06-05 20:24:38 +05:30
}
} // namespace brightray