2021-06-17 16:17:25 -05:00
|
|
|
// Copyright (c) 2021 Slack Technologies, Inc.
|
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
2025-05-02 17:27:29 -04:00
|
|
|
#include "base/command_line.h"
|
2021-06-17 16:17:25 -05:00
|
|
|
#include "base/dcheck_is_on.h"
|
|
|
|
|
#include "base/logging.h"
|
2026-02-25 18:53:06 +01:00
|
|
|
#include "content/browser/network_service_instance_impl.h" // nogncheck
|
|
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2025-05-02 17:27:29 -04:00
|
|
|
#include "content/public/common/content_switches.h"
|
2026-02-25 18:53:06 +01:00
|
|
|
#include "shell/common/callback_util.h"
|
2021-06-17 16:17:25 -05:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2026-02-25 18:53:06 +01:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2021-06-17 16:17:25 -05:00
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void Log(int severity, std::string text) {
|
|
|
|
|
switch (severity) {
|
|
|
|
|
case logging::LOGGING_VERBOSE:
|
|
|
|
|
VLOG(1) << text;
|
|
|
|
|
break;
|
|
|
|
|
case logging::LOGGING_INFO:
|
|
|
|
|
LOG(INFO) << text;
|
|
|
|
|
break;
|
|
|
|
|
case logging::LOGGING_WARNING:
|
|
|
|
|
LOG(WARNING) << text;
|
|
|
|
|
break;
|
|
|
|
|
case logging::LOGGING_ERROR:
|
|
|
|
|
LOG(ERROR) << text;
|
|
|
|
|
break;
|
|
|
|
|
case logging::LOGGING_FATAL:
|
|
|
|
|
LOG(FATAL) << text;
|
2024-01-25 12:46:30 -05:00
|
|
|
// break not needed here because LOG(FATAL) is [[noreturn]]
|
2021-06-17 16:17:25 -05:00
|
|
|
default:
|
|
|
|
|
LOG(ERROR) << "Unrecognized severity: " << severity;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 17:27:29 -04:00
|
|
|
std::string GetLoggingDestination() {
|
|
|
|
|
const auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
|
return command_line->GetSwitchValueASCII(switches::kEnableLogging);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 18:53:06 +01:00
|
|
|
v8::Local<v8::Promise> SimulateNetworkServiceCrash(v8::Isolate* isolate) {
|
|
|
|
|
gin_helper::Promise<void> promise(isolate);
|
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
auto subscription = content::RegisterNetworkServiceProcessGoneHandler(
|
|
|
|
|
electron::AdaptCallbackForRepeating(
|
|
|
|
|
base::BindOnce([](gin_helper::Promise<void> promise,
|
|
|
|
|
bool crashed) { promise.Resolve(); },
|
|
|
|
|
std::move(promise))));
|
|
|
|
|
content::RestartNetworkService();
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-17 16:17:25 -05:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
|
void* priv) {
|
2025-07-21 09:34:38 -05:00
|
|
|
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
|
|
|
|
|
gin_helper::Dictionary dict{isolate, exports};
|
2021-06-17 16:17:25 -05:00
|
|
|
dict.SetMethod("log", &Log);
|
2025-05-02 17:27:29 -04:00
|
|
|
dict.SetMethod("getLoggingDestination", &GetLoggingDestination);
|
2026-02-25 18:53:06 +01:00
|
|
|
dict.SetMethod("simulateNetworkServiceCrash", &SimulateNetworkServiceCrash);
|
2021-06-17 16:17:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2023-02-09 02:31:38 +01:00
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_common_testing, Initialize)
|
2021-06-17 16:17:25 -05:00
|
|
|
#endif
|