2020-03-30 01:32:02 +00:00
|
|
|
// Copyright (c) 2020 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
|
|
|
|
|
2020-07-20 19:13:33 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-03-30 01:32:02 +00:00
|
|
|
#include "base/no_destructor.h"
|
|
|
|
|
|
|
|
namespace gin_helper {
|
|
|
|
|
2020-07-20 19:13:33 +00:00
|
|
|
std::vector<CleanedUpAtExit*>& GetDoomed() {
|
|
|
|
static base::NoDestructor<std::vector<CleanedUpAtExit*>> doomed;
|
2020-03-30 01:32:02 +00:00
|
|
|
return *doomed;
|
|
|
|
}
|
|
|
|
CleanedUpAtExit::CleanedUpAtExit() {
|
2020-07-20 19:13:33 +00:00
|
|
|
GetDoomed().emplace_back(this);
|
2020-03-30 01:32:02 +00:00
|
|
|
}
|
|
|
|
CleanedUpAtExit::~CleanedUpAtExit() {
|
2024-04-19 15:55:59 +00:00
|
|
|
std::erase(GetDoomed(), this);
|
2020-03-30 01:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CleanedUpAtExit::DoCleanup() {
|
|
|
|
auto& doomed = GetDoomed();
|
|
|
|
while (!doomed.empty()) {
|
2020-07-20 19:13:33 +00:00
|
|
|
CleanedUpAtExit* next = doomed.back();
|
|
|
|
delete next;
|
2020-03-30 01:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gin_helper
|