electron/atom/app/node_main.cc
Electron Bot d008d217f9 chore: bump chromium to 2a7aff41ce73adc0eeee67d364989 (master) (#18505)
* chore: bump chromium in DEPS to 07463d3cd628b037c11f36022cb4c788db4628e3

* chore: update patches

* fix: Don't leak system network context when nw service is disabled

https://chromium-review.googlesource.com/c/chromium/src/+/1632494
NetworkService is now deleted by using SequnceLocalStorageSlot
on the IO thread when the service is disabled, which expects
all associated NetworkContexts on that sequence to be destroyed.

* chore: bump chromium in DEPS to 7c16850e7e40990e141f47101b737ec1092175a1

* fix: Destroy all network contexts before primary network context

* Simplify out-of-process service registration

https://chromium-review.googlesource.com/c/chromium/src/+/1615882

* [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance

https://chromium-review.googlesource.com/c/chromium/src/+/1634851

* chore: update patches

* fix: -Winconsistent-missing-override warnings

* chore: bump chromium in DEPS to 93ebfaccc12715df1d5426797998eed0932f7ae1

* Change CreateBrowserMainParts to return unique_ptrs

https://chromium-review.googlesource.com/c/chromium/src/+/1632532

* chore: update patches

* chore: bump chromium in DEPS to e656555ffb87bdd05e248d0a3ef9dd9d3433e17b

* chore: bump chromium in DEPS to 111e7a8d2e3ae9d70e535009d6afb066ac906063

* chore: bump chromium in DEPS to 9b6b84670d32a7aff41ce73adc0eeee67d364989

* chore: update patches

* chore: remove ShouldInterceptResourceAsStream as it is removed upstream

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639597

* chore: remove ResourceDispatcherHostCreated as it is removed upstream

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1610892

* chore: CreateWithStrongBinding --> CreateWithSelfOwnedReceiver

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1636722

* chore: rename all blink media enums

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639237

* chore: add accidentally removed patch content back
2019-06-03 20:44:12 -07:00

126 lines
4.1 KiB
C++

// 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 "atom/app/node_main.h"
#include <memory>
#include <utility>
#include "atom/app/uv_task_runner.h"
#include "atom/browser/javascript_environment.h"
#include "atom/browser/node_debugger.h"
#include "atom/common/api/electron_bindings.h"
#include "atom/common/atom_version.h"
#include "atom/common/crash_reporter/crash_reporter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_bindings.h"
#include "atom/common/node_includes.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"
#include "gin/v8_initializer.h"
#include "native_mate/dictionary.h"
namespace atom {
int NodeMain(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
int exit_code = 1;
{
// Feed gin::PerIsolateData with a task runner.
argv = uv_setup_args(argc, argv);
uv_loop_t* loop = uv_default_loop();
scoped_refptr<UvTaskRunner> uv_task_runner(new UvTaskRunner(loop));
base::ThreadTaskRunnerHandle handle(uv_task_runner);
// Initialize feature list.
auto feature_list = std::make_unique<base::FeatureList>();
feature_list->InitializeFromCommandLine("", "");
base::FeatureList::SetInstance(std::move(feature_list));
gin::V8Initializer::LoadV8Snapshot(
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext);
gin::V8Initializer::LoadV8Natives();
// V8 requires a task scheduler apparently
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("Electron");
// Initialize gin::IsolateHolder.
JavascriptEnvironment gin_env(loop);
// Explicitly register electron's builtin modules.
NodeBindings::RegisterBuiltinModules();
int exec_argc;
const char** exec_argv;
node::Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
node::Environment* env = node::CreateEnvironment(
node::CreateIsolateData(gin_env.isolate(), loop, gin_env.platform()),
gin_env.context(), argc, argv, exec_argc, exec_argv);
// Enable support for v8 inspector.
NodeDebugger node_debugger(env);
node_debugger.Start();
mate::Dictionary process(gin_env.isolate(), env->process_object());
#if defined(OS_WIN)
process.SetMethod("log", &ElectronBindings::Log);
#endif
process.SetMethod("crash", &ElectronBindings::Crash);
// Setup process.crashReporter.start in child node processes
auto reporter = mate::Dictionary::CreateEmpty(gin_env.isolate());
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
process.Set("crashReporter", reporter);
mate::Dictionary versions;
if (process.Get("versions", &versions)) {
versions.SetReadOnly(ATOM_PROJECT_NAME, ATOM_VERSION_STRING);
}
node::LoadEnvironment(env);
bool more;
do {
more = uv_run(env->event_loop(), UV_RUN_ONCE);
gin_env.platform()->DrainTasks(env->isolate());
if (more == false) {
node::EmitBeforeExit(env);
// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env->event_loop());
if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0)
more = true;
}
} while (more == true);
node_debugger.Stop();
exit_code = node::EmitExit(env);
node::RunAtExit(env);
gin_env.platform()->DrainTasks(env->isolate());
gin_env.platform()->CancelPendingDelayedTasks(env->isolate());
gin_env.platform()->UnregisterIsolate(env->isolate());
node::FreeEnvironment(env);
}
// According to "src/gin/shell/gin_main.cc":
//
// gin::IsolateHolder waits for tasks running in ThreadPool in its
// destructor and thus must be destroyed before ThreadPool starts skipping
// CONTINUE_ON_SHUTDOWN tasks.
base::ThreadPoolInstance::Get()->Shutdown();
v8::V8::Dispose();
return exit_code;
}
} // namespace atom