0

Prevent use of base::NoDestructor for trivially-destructible types

base::NoDestructor prevents calling a destructor of the templated
type. It's not needed if there is no destructor call to prevent.

Bug: 1223520
Change-Id: I686ba75ca5407c393e1a717a7063540790a70d81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2986126
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#897506}
This commit is contained in:
Avi Drissman
2021-06-30 19:58:46 +00:00
committed by Chromium LUCI CQ
parent 22e76e725a
commit b961c7632f
133 changed files with 384 additions and 540 deletions
android_webview/browser
ash
accelerometer
public
wm
desks
base
chrome
chromecast/browser
components
content
extensions
fuchsia/engine/browser
media
mojo
net
pdf
remoting/client/input
services
device
public
tracing
public
third_party/blink
ui
url
weblayer

@ -7,7 +7,6 @@
#include "android_webview/browser/gfx/child_frame.h"
#include "android_webview/browser/gfx/display_scheduler_webview.h"
#include "android_webview/browser/gfx/viz_compositor_thread_runner_webview.h"
#include "base/no_destructor.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/surfaces/frame_sink_id_allocator.h"
#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"
@ -18,8 +17,8 @@ namespace android_webview {
namespace {
viz::FrameSinkId AllocateParentSinkId() {
static base::NoDestructor<viz::FrameSinkIdAllocator> allocator(0u);
return allocator->NextFrameSinkId();
static viz::FrameSinkIdAllocator allocator(0u);
return allocator.NextFrameSinkId();
}
} // namespace

@ -5,13 +5,11 @@
#include "android_webview/browser/metrics/visibility_metrics_logger.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/time/time.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
using base::NoDestructor;
using content::BrowserThread;
namespace android_webview {
@ -27,50 +25,45 @@ VisibilityMetricsLogger::CreateHistogramForDurationTracking(const char* name,
}
base::HistogramBase* VisibilityMetricsLogger::GetGlobalVisibilityHistogram() {
static NoDestructor<base::HistogramBase*> histogram(
CreateHistogramForDurationTracking(
"Android.WebView.Visibility.Global",
static_cast<int>(VisibilityMetricsLogger::Visibility::kMaxValue)));
return *histogram;
static base::HistogramBase* histogram(CreateHistogramForDurationTracking(
"Android.WebView.Visibility.Global",
static_cast<int>(VisibilityMetricsLogger::Visibility::kMaxValue)));
return histogram;
}
base::HistogramBase*
VisibilityMetricsLogger::GetPerWebViewVisibilityHistogram() {
static NoDestructor<base::HistogramBase*> histogram(
CreateHistogramForDurationTracking(
"Android.WebView.Visibility.PerWebView",
static_cast<int>(VisibilityMetricsLogger::Visibility::kMaxValue)));
return *histogram;
static base::HistogramBase* histogram(CreateHistogramForDurationTracking(
"Android.WebView.Visibility.PerWebView",
static_cast<int>(VisibilityMetricsLogger::Visibility::kMaxValue)));
return histogram;
}
base::HistogramBase*
VisibilityMetricsLogger::GetGlobalOpenWebVisibilityHistogram() {
static NoDestructor<base::HistogramBase*> histogram(
CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.Global",
static_cast<int>(
VisibilityMetricsLogger::WebViewOpenWebVisibility::kMaxValue)));
return *histogram;
static base::HistogramBase* histogram(CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.Global",
static_cast<int>(
VisibilityMetricsLogger::WebViewOpenWebVisibility::kMaxValue)));
return histogram;
}
base::HistogramBase*
VisibilityMetricsLogger::GetPerWebViewOpenWebVisibilityHistogram() {
static NoDestructor<base::HistogramBase*> histogram(
CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.PerWebView",
static_cast<int>(
VisibilityMetricsLogger::WebViewOpenWebVisibility::kMaxValue)));
return *histogram;
static base::HistogramBase* histogram(CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.PerWebView",
static_cast<int>(
VisibilityMetricsLogger::WebViewOpenWebVisibility::kMaxValue)));
return histogram;
}
base::HistogramBase*
VisibilityMetricsLogger::GetOpenWebVisibileScreenPortionHistogram() {
static NoDestructor<base::HistogramBase*> histogram(
CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.ScreenPortion",
static_cast<int>(VisibilityMetricsLogger::
WebViewOpenWebScreenPortion::kMaxValue)));
return *histogram;
static base::HistogramBase* histogram(CreateHistogramForDurationTracking(
"Android.WebView.WebViewOpenWebVisible.ScreenPortion",
static_cast<int>(
VisibilityMetricsLogger::WebViewOpenWebScreenPortion::kMaxValue)));
return histogram;
}
VisibilityMetricsLogger::VisibilityMetricsLogger() {
@ -318,4 +311,4 @@ void VisibilityMetricsLogger::RecordScreenPortionMetrics() {
}
}
} // namespace android_webview
} // namespace android_webview

@ -10,12 +10,10 @@
#include "ash/public/cpp/tablet_mode_observer.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
namespace base {
template <typename T>
class NoDestructor;
class SequencedTaskRunner;
} // namespace base

@ -7,15 +7,11 @@
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/ash_public_export.h"
#include "base/no_destructor.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace gfx {
class FontList;
}

@ -28,7 +28,6 @@
#include "base/containers/cxx20_erase.h"
#include "base/macros.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/stringprintf.h"
#include "chromeos/ui/base/window_properties.h"
#include "ui/aura/client/aura_constants.h"
@ -132,12 +131,13 @@ void FixWindowStackingAccordingToGlobalMru(aura::Window* window_to_fix) {
// Returns Jan 1, 2010 00:00:00 as a base::Time object in the local timezone.
base::Time GetLocalEpoch() {
static base::NoDestructor<base::Time> local_epoch;
if (local_epoch->is_null()) {
static const base::Time local_epoch = [] {
base::Time local_epoch;
ignore_result(base::Time::FromLocalExploded({2010, 1, 5, 1, 0, 0, 0, 0},
local_epoch.get()));
}
return *local_epoch;
&local_epoch));
return local_epoch;
}();
return local_epoch;
}
// Used to temporarily turn off the automatic window positioning while windows

@ -3661,6 +3661,7 @@ if (enable_nocompile_tests) {
"memory/weak_ptr_unittest.nc",
"metrics/field_trial_params_unittest.nc",
"metrics/histogram_unittest.nc",
"no_destructor_unittest.nc",
"observer_list_unittest.nc",
"sequence_checker_unittest.nc",
"task/task_traits_extension_unittest.nc",

@ -64,8 +64,8 @@ bool AndroidHardwareBufferCompat::IsSupportAvailable() {
// static
AndroidHardwareBufferCompat& AndroidHardwareBufferCompat::GetInstance() {
static base::NoDestructor<AndroidHardwareBufferCompat> compat;
return *compat;
static AndroidHardwareBufferCompat compat;
return compat;
}
void AndroidHardwareBufferCompat::Allocate(const AHardwareBuffer_Desc* desc,

@ -26,8 +26,8 @@ namespace android {
AndroidImageReader& AndroidImageReader::GetInstance() {
// C++11 static local variable initialization is
// thread-safe.
static base::NoDestructor<AndroidImageReader> instance;
return *instance;
static AndroidImageReader instance;
return instance;
}
bool AndroidImageReader::IsSupported() {

@ -7,7 +7,6 @@
#include "base/android/library_loader/anchor_functions.h"
#include "base/android/library_loader/anchor_functions_buildflags.h"
#include "base/check_op.h"
#include "base/no_destructor.h"
namespace base {
namespace android {
@ -25,9 +24,9 @@ std::atomic<uint32_t> g_text_bitfield[kTextBitfieldSize];
// static
ReachedAddressesBitset* ReachedAddressesBitset::GetTextBitset() {
#if BUILDFLAG(SUPPORTS_CODE_ORDERING)
static base::NoDestructor<ReachedAddressesBitset> text_bitset(
kStartOfText, kEndOfText, g_text_bitfield, kTextBitfieldSize);
return text_bitset.get();
static ReachedAddressesBitset text_bitset(kStartOfText, kEndOfText,
g_text_bitfield, kTextBitfieldSize);
return &text_bitset;
#else
return nullptr;
#endif

@ -9,12 +9,10 @@
#include <vector>
#include "base/base_export.h"
#include "base/no_destructor.h"
namespace base {
template <typename T>
class NoDestructor;
namespace android {
// ReachedAddressesBitset is a set that stores addresses for the

@ -19,7 +19,6 @@
#include "base/files/dir_reader_posix.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/no_destructor.h"
#include "base/strings/safe_sprintf.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
@ -123,7 +122,7 @@ std::string GetLinuxDistro() {
#if !BUILDFLAG(IS_CHROMEOS_ASH)
// We do this check only once per process. If it fails, there's
// little reason to believe it will work if we attempt to run it again.
static NoDestructor<DistroNameGetter> distro_name_getter;
static DistroNameGetter distro_name_getter;
#endif
return g_linux_distro;
}

@ -12,6 +12,7 @@
#include "base/allocator/buildflags.h"
#include "base/base_export.h"
#include "base/no_destructor.h"
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#include "base/allocator/partition_allocator/partition_alloc.h"
@ -25,9 +26,6 @@
namespace base {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
template <typename>
class NoDestructor;
namespace internal {
// Represents allocator that contains memory for data-like objects (that don't
@ -53,7 +51,7 @@ class BASE_EXPORT NonScannableAllocator final {
void EnablePCScan();
private:
template <typename>
template <typename, typename>
friend class base::NoDestructor;
NonScannableAllocator();

@ -6,9 +6,15 @@
#define BASE_NO_DESTRUCTOR_H_
#include <new>
#include <type_traits>
#include <utility>
namespace base {
// A tag type used for NoDestructor to allow it to be created for a type that
// has a trivial destructor. Use for cases where the same class might have
// different implementations that vary on destructor triviality or when the
// LSan hiding properties of NoDestructor are needed.
struct AllowForTriviallyDestructibleType;
// A wrapper that makes it easy to create an object of type T with static
// storage duration that:
@ -44,9 +50,20 @@ namespace base {
// Note that since the destructor is never run, this *will* leak memory if used
// as a stack or member variable. Furthermore, a NoDestructor<T> should never
// have global scope as that may require a static initializer.
template <typename T>
template <typename T, typename O = std::nullptr_t>
class NoDestructor {
public:
static_assert(
!std::is_trivially_destructible<T>::value ||
std::is_same<O, AllowForTriviallyDestructibleType>::value,
"base::NoDestructor is not needed because the templated class has a "
"trivial destructor");
static_assert(std::is_same<O, AllowForTriviallyDestructibleType>::value ||
std::is_same<O, std::nullptr_t>::value,
"AllowForTriviallyDestructibleType is the only valid option "
"for the second template parameter of NoDestructor");
// Not constexpr; just write static constexpr T x = ...; if the value should
// be a constexpr.
template <typename... Args>

@ -39,6 +39,7 @@ struct UncopyableUnmovable {
UncopyableUnmovable& operator=(const UncopyableUnmovable&) = delete;
int value = 1;
std::string something_with_a_nontrivial_destructor;
};
struct CopyOnly {
@ -63,6 +64,8 @@ struct MoveOnly {
struct ForwardingTestStruct {
ForwardingTestStruct(const CopyOnly&, MoveOnly&&) {}
std::string something_with_a_nontrivial_destructor;
};
TEST(NoDestructorTest, UncopyableUnmovable) {
@ -89,6 +92,11 @@ TEST(NoDestructorTest, Accessors) {
EXPECT_EQ(0, awesome.get()->compare("awesome"));
}
TEST(NoDestructorTest, AllowForTriviallyDestructibleType) {
static NoDestructor<bool, AllowForTriviallyDestructibleType>
trivially_destructible_type;
}
// Passing initializer list to a NoDestructor like in this test
// is ambiguous in GCC.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84849

@ -0,0 +1,30 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests
#include "base/no_destructor.h"
#include <string>
namespace base {
#if defined(NCTEST_NODESTRUCTOR_REQUIRES_NONTRIVIAL_DESTRUCTOR) // [r"fatal error: static_assert failed due to requirement '!std::is_trivially_destructible<bool>::value || std::is_same<nullptr_t, base::AllowForTriviallyDestructibleType>::value' \"base::NoDestructor is not needed because the templated class has a trivial destructor\""]
// Attempt to make a NoDestructor for a type with a trivial destructor.
void WontCompile() {
NoDestructor<bool> nd;
}
#elif defined(NCTEST_NODESTRUCTOR_PARAMETER) // [r"fatal error: static_assert failed due to requirement 'std::is_same<std::string, base::AllowForTriviallyDestructibleType>::value || std::is_same<std::string, nullptr_t>::value' \"AllowForTriviallyDestructibleType is the only valid option for the second template parameter of NoDestructor\""]
// Attempt to make a NoDestructor for a type with an invalid option.
void WontCompile() {
NoDestructor<std::string, std::string> nd;
}
#endif
} // namespace base

@ -10,15 +10,13 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sampling_heap_profiler/lock_free_address_hash_set.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
namespace base {
template <typename T>
class NoDestructor;
// This singleton class implements Poisson sampling of the incoming allocations
// stream. It hooks onto base::allocator and base::PartitionAlloc.
// An extra custom allocator can be hooked via SetHooksInstallCallback method.

@ -12,6 +12,7 @@
#include "base/base_export.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
@ -19,9 +20,6 @@
namespace base {
template <typename T>
class NoDestructor;
// The class implements sampling profiling of native memory heap.
// It uses PoissonAllocationSampler to aggregate the heap allocations and
// record samples.

@ -14,7 +14,6 @@
#include "base/check_op.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string_util.h"
#include "base/third_party/double_conversion/double-conversion/double-conversion.h"
@ -229,10 +228,10 @@ bool HexStringToIntImpl(T input, VALUE& output) {
static const double_conversion::DoubleToStringConverter*
GetDoubleToStringConverter() {
static NoDestructor<double_conversion::DoubleToStringConverter> converter(
static double_conversion::DoubleToStringConverter converter(
double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN,
nullptr, nullptr, 'e', -6, 12, 0, 0);
return converter.get();
return &converter;
}
// Converts a given (data, size) pair to a desired string type. For
@ -258,14 +257,14 @@ StringT DoubleToStringT(double value) {
template <typename STRING, typename CHAR>
bool StringToDoubleImpl(STRING input, const CHAR* data, double& output) {
static NoDestructor<double_conversion::StringToDoubleConverter> converter(
static double_conversion::StringToDoubleConverter converter(
double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES |
double_conversion::StringToDoubleConverter::ALLOW_TRAILING_JUNK,
0.0, 0, nullptr, nullptr);
int processed_characters_count;
output = converter->StringToDouble(data, input.size(),
&processed_characters_count);
output =
converter.StringToDouble(data, input.size(), &processed_characters_count);
// Cases to return false:
// - If the input string is empty, there was nothing to parse.

@ -11,7 +11,6 @@
#include "base/callback.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/system/sys_info_internal.h"
#include "base/task/post_task.h"
@ -76,10 +75,8 @@ bool DetectLowEndDevice() {
// static
bool SysInfo::IsLowEndDeviceImpl() {
static base::NoDestructor<
internal::LazySysInfoValue<bool, DetectLowEndDevice>>
instance;
return instance->value();
static internal::LazySysInfoValue<bool, DetectLowEndDevice> instance;
return instance.value();
}
#endif

@ -19,7 +19,6 @@
#include "base/debug/activity_tracker.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/threading/platform_thread_internal_posix.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_id_name_manager.h"
@ -195,7 +194,7 @@ PlatformThreadId PlatformThread::CurrentId() {
#if defined(OS_APPLE)
return pthread_mach_thread_np(pthread_self());
#elif defined(OS_LINUX) || defined(OS_CHROMEOS)
static NoDestructor<InitAtFork> init_at_fork;
static InitAtFork init_at_fork;
if (g_thread_id == -1) {
g_thread_id = syscall(__NR_gettid);
} else {

@ -17,7 +17,6 @@
#include <tuple>
#include <utility>
#include "base/no_destructor.h"
#include "base/strings/stringprintf.h"
#include "base/third_party/nspr/prtime.h"
#include "base/time/time_override.h"
@ -334,11 +333,11 @@ TimeTicks TimeTicks::Now() {
// static
TimeTicks TimeTicks::UnixEpoch() {
static const NoDestructor<TimeTicks> epoch([]() {
static const TimeTicks epoch([]() {
return subtle::TimeTicksNowIgnoringOverride() -
(subtle::TimeNowIgnoringOverride() - Time::UnixEpoch());
}());
return *epoch;
return epoch;
}
TimeTicks TimeTicks::SnappedToNextTick(TimeTicks tick_phase,

@ -18,6 +18,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h"
#include "base/time/time_override.h"
#include "base/trace_event/category_registry.h"
@ -36,9 +37,6 @@ class TraceProcessorStorage;
namespace base {
class RefCountedString;
template <typename T>
class NoDestructor;
namespace tracing {
class PerfettoPlatform;
} // namespace tracing

@ -7,7 +7,6 @@
#include <ostream>
#include "base/format_macros.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
namespace base {
@ -21,8 +20,8 @@ UnguessableToken UnguessableToken::Create() {
// static
const UnguessableToken& UnguessableToken::Null() {
static const NoDestructor<UnguessableToken> null_token;
return *null_token;
static const UnguessableToken null_token{};
return null_token;
}
// static

@ -57,12 +57,12 @@ std::pair<int, std::string> GetVersionData() {
}
const _SYSTEM_INFO& GetSystemInfoStorage() {
static const NoDestructor<_SYSTEM_INFO> system_info([] {
static const _SYSTEM_INFO system_info = [] {
_SYSTEM_INFO info = {};
::GetNativeSystemInfo(&info);
return info;
}());
return *system_info;
}();
return system_info;
}
} // namespace

@ -5,14 +5,13 @@
#include "chrome/browser/android/profile_key_startup_accessor.h"
#include "base/check.h"
#include "base/no_destructor.h"
ProfileKeyStartupAccessor::ProfileKeyStartupAccessor() : key_(nullptr) {}
// static
ProfileKeyStartupAccessor* ProfileKeyStartupAccessor::GetInstance() {
static base::NoDestructor<ProfileKeyStartupAccessor> instance;
return instance.get();
static ProfileKeyStartupAccessor instance;
return &instance;
}
void ProfileKeyStartupAccessor::SetProfileKey(ProfileKey* key) {

@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "chrome/browser/ash/account_manager/account_migration_runner.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
@ -16,11 +17,6 @@
class Profile;
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace ash {
class AccountManagerMigrator : public KeyedService {

@ -6,13 +6,9 @@
#define CHROME_BROWSER_ASH_ACCOUNT_MANAGER_ACCOUNT_MANAGER_POLICY_CONTROLLER_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace ash {
class AccountManagerPolicyController;

@ -37,8 +37,8 @@ class MockAutofillPopupController
MOCK_CONST_METHOD0(container_view, gfx::NativeView());
MOCK_CONST_METHOD0(GetWebContents, content::WebContents*());
const gfx::RectF& element_bounds() const override {
static base::NoDestructor<gfx::RectF> bounds({100, 100, 250, 50});
return *bounds;
static const gfx::RectF bounds(100, 100, 250, 50);
return bounds;
}
MOCK_CONST_METHOD0(IsRTL, bool());

@ -8,16 +8,12 @@
#include <memory>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/core/simple_keyed_service_factory.h"
class KeyedService;
class SimpleFactoryKey;
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace download {
class SimpleDownloadManagerCoordinator;
} // namespace download

@ -51,10 +51,9 @@ namespace {
absl::optional<ChromeContentVerifierDelegate::VerifyInfo::Mode>&
GetModeForTesting() {
static base::NoDestructor<
absl::optional<ChromeContentVerifierDelegate::VerifyInfo::Mode>>
static absl::optional<ChromeContentVerifierDelegate::VerifyInfo::Mode>
testing_mode;
return *testing_mode;
return testing_mode;
}
const char kContentVerificationExperimentName[] =

@ -6,13 +6,9 @@
#define CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_MANAGER_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
namespace base {
template <typename T>
class NoDestructor;
}
// A singleton that acts as a rendezvous for dialog observers to register and
// the dialog managers/delegates to post their activities.
// TODO(crbug/953495): Merge this into DesktopMediaPickerFactoryImpl.

@ -6,17 +6,13 @@
#define CHROME_BROWSER_METRICS_PERF_WINDOWED_INCOGNITO_OBSERVER_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/ui/browser_list_observer.h"
class Browser;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace metrics {
class WindowedIncognitoMonitor;

@ -181,15 +181,15 @@ GetNearbyShareTestEncryptedMetadataKey() {
}
base::Time GetNearbyShareTestNotBefore() {
static const base::NoDestructor<base::Time> not_before(
base::Time::FromJavaTime(kTestNotBeforeMillis));
return *not_before;
static const base::Time not_before =
base::Time::FromJavaTime(kTestNotBeforeMillis);
return not_before;
}
base::TimeDelta GetNearbyShareTestValidityOffset() {
static const base::NoDestructor<base::TimeDelta> offset(
base::TimeDelta::FromMilliseconds(kTestValidityOffsetMillis));
return *offset;
static const base::TimeDelta offset =
base::TimeDelta::FromMilliseconds(kTestValidityOffsetMillis);
return offset;
}
const nearbyshare::proto::EncryptedMetadata& GetNearbyShareTestMetadata() {

@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow_impl.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_http_notifier.h"
@ -95,10 +94,10 @@ ListPublicCertificatesRequestToQueryParameters(
// TODO(crbug.com/1103471): Update "chrome_policy" when a Nearby Share
// enterprise policy is created.
const net::PartialNetworkTrafficAnnotationTag& GetUpdateDeviceAnnotation() {
static const base::NoDestructor<net::PartialNetworkTrafficAnnotationTag>
annotation(net::DefinePartialNetworkTrafficAnnotation(
"nearby_share_update_device", "oauth2_api_call_flow",
R"(
static const net::PartialNetworkTrafficAnnotationTag annotation =
net::DefinePartialNetworkTrafficAnnotation("nearby_share_update_device",
"oauth2_api_call_flow",
R"(
semantics {
sender: "Nearby Share"
description:
@ -137,17 +136,17 @@ const net::PartialNetworkTrafficAnnotationTag& GetUpdateDeviceAnnotation() {
SigninAllowed: false
}
}
})"));
return *annotation;
})");
return annotation;
}
// TODO(crbug.com/1103471): Update "chrome_policy" when a Nearby Share
// enterprise policy is created.
const net::PartialNetworkTrafficAnnotationTag& GetContactsAnnotation() {
static const base::NoDestructor<net::PartialNetworkTrafficAnnotationTag>
annotation(net::DefinePartialNetworkTrafficAnnotation(
"nearby_share_contacts", "oauth2_api_call_flow",
R"(
static const net::PartialNetworkTrafficAnnotationTag annotation =
net::DefinePartialNetworkTrafficAnnotation("nearby_share_contacts",
"oauth2_api_call_flow",
R"(
semantics {
sender: "Nearby Share"
description:
@ -173,16 +172,16 @@ const net::PartialNetworkTrafficAnnotationTag& GetContactsAnnotation() {
SigninAllowed: false
}
}
})"));
return *annotation;
})");
return annotation;
}
// TODO(crbug.com/1103471): Update "chrome_policy" when a Nearby Share
// enterprise policy is created.
const net::PartialNetworkTrafficAnnotationTag&
GetListPublicCertificatesAnnotation() {
static const base::NoDestructor<net::PartialNetworkTrafficAnnotationTag>
annotation(net::DefinePartialNetworkTrafficAnnotation(
static const net::PartialNetworkTrafficAnnotationTag annotation =
net::DefinePartialNetworkTrafficAnnotation(
"nearby_share_list_public_certificates", "oauth2_api_call_flow",
R"(
semantics {
@ -213,8 +212,8 @@ GetListPublicCertificatesAnnotation() {
SigninAllowed: false
}
}
})"));
return *annotation;
})");
return annotation;
}
} // namespace

@ -9,7 +9,6 @@
#include "base/feature_list.h"
#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/chromeos/nearby/nearby_process_manager_factory.h"
@ -34,8 +33,8 @@ namespace {
constexpr char kServiceName[] = "NearbySharingService";
absl::optional<bool>& IsSupportedTesting() {
static base::NoDestructor<absl::optional<bool>> is_supported;
return *is_supported;
static absl::optional<bool> is_supported;
return is_supported;
}
} // namespace

@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "chrome/browser/availability/availability_prober.h"
@ -224,13 +223,13 @@ class OriginProbeDelegate : public AvailabilityProber::Delegate {
};
CanaryCheckDelegate* GetCanaryCheckDelegate() {
static base::NoDestructor<CanaryCheckDelegate> delegate;
return delegate.get();
static CanaryCheckDelegate delegate;
return &delegate;
}
OriginProbeDelegate* GetOriginProbeDelegate() {
static base::NoDestructor<OriginProbeDelegate> delegate;
return delegate.get();
static OriginProbeDelegate delegate;
return &delegate;
}
// Allows probing to start after a delay so that browser start isn't slowed.

@ -5,15 +5,11 @@
#ifndef CHROME_BROWSER_SPEECH_CROS_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SPEECH_CROS_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace speech {
class SpeechRecognitionService;
} // namespace speech

@ -5,15 +5,11 @@
#ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_CLIENT_BROWSER_INTERFACE_FACTORY_H_
#define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_CLIENT_BROWSER_INTERFACE_FACTORY_H_
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace speech {
class SpeechRecognitionClientBrowserInterface;
} // namespace speech

@ -5,15 +5,11 @@
#ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace speech {
class SpeechRecognitionService;
} // namespace speech

@ -11,14 +11,10 @@
#include "base/callback.h"
#include "base/component_export.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "components/keyed_service/core/simple_factory_key.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
class Profile;
// FullBrowserTransitionManager allows SimpleKeyedServices to hook into the

@ -4,6 +4,7 @@
#include "ash/public/cpp/app_list/app_list_switches.h"
#include "base/command_line.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/search/cros_action_history/cros_action_recorder.h"
#include "testing/gmock/include/gmock/gmock.h"

@ -13,6 +13,7 @@
#include <vector>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/scoped_observation.h"
#include "extensions/browser/api/automation_internal/automation_event_router.h"
#include "ui/accessibility/ax_action_handler.h"
@ -21,11 +22,6 @@
#include "ui/views/accessibility/ax_event_observer.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace extensions {
class AutomationEventRouterInterface;
} // namespace extensions

@ -5,7 +5,6 @@
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
#include "base/check.h"
#include "base/no_destructor.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@ -54,6 +53,6 @@ void AllTabContentsesList::Iterator::Next() {
}
const AllTabContentsesList& AllTabContentses() {
static const base::NoDestructor<AllTabContentsesList> all_tabs;
return *all_tabs;
static const AllTabContentsesList all_tabs;
return all_tabs;
}

@ -7,14 +7,10 @@
#include <set>
#include "base/no_destructor.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
class ThumbnailImage;
// Records memory metrics across all thumbnails in a browser process.

@ -6,7 +6,6 @@
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
@ -51,7 +50,7 @@ bool HasBuiltInTouchScreen() {
// static
void WebUITabStripFieldTrial::RegisterFieldTrialIfNecessary() {
static base::NoDestructor<WebUITabStripFieldTrial> instance;
static WebUITabStripFieldTrial instance;
}
WebUITabStripFieldTrial::WebUITabStripFieldTrial() {

@ -5,10 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_FIELD_TRIAL_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_FIELD_TRIAL_H_
namespace base {
template <typename T>
class NoDestructor;
}
#include "base/no_destructor.h"
// Manages a synthetic field trial for the WebUI tab strip. The feature
// flag itself is controlled by an external field trial. This synthetic

@ -12,8 +12,8 @@
// static
AddSupervisionMetricsRecorder* AddSupervisionMetricsRecorder::GetInstance() {
static base::NoDestructor<AddSupervisionMetricsRecorder> instance_;
return instance_.get();
static AddSupervisionMetricsRecorder instance_;
return &instance_;
}
void AddSupervisionMetricsRecorder::RecordAddSupervisionEnrollment(

@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_ADD_SUPERVISION_ADD_SUPERVISION_METRICS_RECORDER_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/time/time.h"
namespace base {
@ -47,8 +46,6 @@ class AddSupervisionMetricsRecorder {
void SetClockForTesting(const base::TickClock* tick_clock);
private:
friend class base::NoDestructor<AddSupervisionMetricsRecorder>;
AddSupervisionMetricsRecorder();
// Records UMA metric of how long the user spends in the Add Supervision

@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/upgrade_detector/build_state_observer.h"
@ -17,8 +18,6 @@
class PrefRegistrySimple;
namespace base {
class Clock;
template <typename T>
class NoDestructor;
class TickClock;
} // namespace base

@ -8,6 +8,7 @@
#include <array>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "base/timer/timer.h"
#include "base/version.h"
@ -19,8 +20,6 @@
namespace base {
class Clock;
template <typename T>
class NoDestructor;
class TickClock;
} // namespace base

@ -5,7 +5,6 @@
#include "chrome/browser/web_applications/components/install_bounce_metric.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
@ -16,8 +15,8 @@
namespace {
absl::optional<base::Time>& GetTimeOverride() {
static base::NoDestructor<absl::optional<base::Time>> g_time_override;
return *g_time_override;
static absl::optional<base::Time> time_override;
return time_override;
}
base::Time GetTime() {

@ -95,7 +95,7 @@ ChannelState& GetChannelState() {
bool SideBySideCapable() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
static const base::NoDestructor<bool> capable([] {
static const bool capable([] {
// Use the main Chrome application bundle and not the framework bundle.
// Keystone keys don't live in the framework.
NSBundle* bundle = base::mac::OuterBundle();

@ -282,8 +282,7 @@ void ThreadProfiler::SetAuxUnwinderFactory(
void ThreadProfiler::StartOnChildThread(CallStackProfileParams::Thread thread) {
// The profiler object is stored in a SequenceLocalStorageSlot on child
// threads to give it the same lifetime as the threads.
static base::NoDestructor<
base::SequenceLocalStorageSlot<std::unique_ptr<ThreadProfiler>>>
static base::SequenceLocalStorageSlot<std::unique_ptr<ThreadProfiler>>
child_thread_profiler_sequence_local_storage;
if (!ThreadProfilerConfiguration::Get()
@ -291,7 +290,7 @@ void ThreadProfiler::StartOnChildThread(CallStackProfileParams::Thread thread) {
return;
}
child_thread_profiler_sequence_local_storage->emplace(
child_thread_profiler_sequence_local_storage.emplace(
new ThreadProfiler(thread, base::ThreadTaskRunnerHandle::Get()));
}

@ -8,6 +8,7 @@
#include <initializer_list>
#include <string>
#include "base/no_destructor.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "components/metrics/call_stack_profile_params.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
@ -15,8 +16,6 @@
namespace base {
class CommandLine;
template <typename>
class NoDestructor;
} // namespace base
class ThreadProfilerPlatformConfiguration;

@ -8,13 +8,9 @@
#include <memory>
#include <string>
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace crashpad {
class CrashReportDatabase;
} // namespace crashpad

@ -4,7 +4,6 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/no_destructor.h"
#include "chrome/updater/updater_scope.h"
#include "chrome/updater/win/update_service_internal_proxy.h"
#include "chrome/updater/win/update_service_proxy.h"
@ -22,8 +21,8 @@ class WRLModuleInitializer {
}
static const WRLModuleInitializer& Get() {
static const base::NoDestructor<WRLModuleInitializer> module;
return *module;
static const WRLModuleInitializer module;
return module;
}
};

@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
@ -171,10 +170,8 @@ void CastContentBrowserClient::CreateMediaService(
mojo_media_client->SetVideoGeometrySetterService(
video_geometry_setter_service_.get());
static base::NoDestructor<
base::SequenceLocalStorageSlot<::media::MediaService>>
service;
service->emplace(std::move(mojo_media_client), std::move(receiver));
static base::SequenceLocalStorageSlot<::media::MediaService> service;
service.emplace(std::move(mojo_media_client), std::move(receiver));
}
void CastContentBrowserClient::CreateVideoGeometrySetterServiceOnMediaThread() {

@ -5,7 +5,6 @@
#include "chromecast/browser/system_connector.h"
#include "base/check_op.h"
#include "base/no_destructor.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
@ -18,10 +17,8 @@ namespace {
base::SequenceLocalStorageSlot<service_manager::Connector>&
GetConnectorStorage() {
static base::NoDestructor<
base::SequenceLocalStorageSlot<service_manager::Connector>>
storage;
return *storage;
static base::SequenceLocalStorageSlot<service_manager::Connector> storage;
return storage;
}
void BindReceiverOnMainThread(

@ -13,6 +13,7 @@
#include <vector>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "chromecast/browser/ui/aura/accessibility/ax_tree_source_aura.h"
#include "ui/accessibility/ax_action_handler.h"
#include "ui/accessibility/ax_tree_serializer.h"
@ -22,11 +23,6 @@
class AXRootObjWrapper;
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace extensions {
class AutomationEventRouterInterface;
}

@ -8,7 +8,6 @@
#include "base/containers/flat_map.h"
#include "base/json/json_reader.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "components/autofill_assistant/browser/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
@ -81,7 +80,7 @@ void AutofillAssistantOnboardingFetcher::FetchOnboardingDefinition(
void AutofillAssistantOnboardingFetcher::StartFetch(const std::string& locale,
int timeout_ms) {
static const base::NoDestructor<base::TimeDelta> kFetchTimeout(
static const base::TimeDelta kFetchTimeout(
base::TimeDelta::FromMilliseconds(timeout_ms));
if (url_loader_) {
return;
@ -96,7 +95,7 @@ void AutofillAssistantOnboardingFetcher::StartFetch(const std::string& locale,
kTrafficAnnotationDefinition);
url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation);
url_loader_->SetTimeoutDuration(*kFetchTimeout);
url_loader_->SetTimeoutDuration(kFetchTimeout);
url_loader_->DownloadToString(
url_loader_factory_.get(),
base::BindOnce(&AutofillAssistantOnboardingFetcher::OnFetchComplete,

@ -156,12 +156,11 @@ google_breakpad::CustomClientInfo* GetCustomInfo(
}
}
static base::NoDestructor<google_breakpad::CustomClientInfo>
custom_client_info;
custom_client_info->entries = &custom_entries->front();
custom_client_info->count = custom_entries->size();
static google_breakpad::CustomClientInfo custom_client_info;
custom_client_info.entries = &custom_entries->front();
custom_client_info.count = custom_entries->size();
return custom_client_info.get();
return &custom_client_info;
}
} // namespace

@ -4,7 +4,6 @@
#include "components/infobars/core/infobar_delegate.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_manager.h"
@ -33,8 +32,8 @@ int InfoBarDelegate::GetIconId() const {
}
const gfx::VectorIcon& InfoBarDelegate::GetVectorIcon() const {
static base::NoDestructor<gfx::VectorIcon> empty_icon;
return *empty_icon;
static gfx::VectorIcon empty_icon;
return empty_icon;
}
gfx::Image InfoBarDelegate::GetIcon() const {

@ -9,14 +9,10 @@
#include "base/callback_list.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/core/dependency_manager.h"
#include "components/keyed_service/core/keyed_service_export.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace content {
class BrowserContext;
}

@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "components/metrics/metrics_pref_names.h"
@ -23,14 +22,15 @@ namespace {
const int kMaxLowEntropySize = 8000;
// Generates a new non-identifying entropy source used to seed persistent
// activities. Using a NoDestructor so that the new low entropy source value
// will only be generated on first access. And thus, even though we may write
// the new low entropy source value to prefs multiple times, it stays the same
// activities. Make it static so that the new low entropy source value will
// only be generated on first access. And thus, even though we may write the
// new low entropy source value to prefs multiple times, it stays the same
// value.
int GenerateLowEntropySource() {
static const base::NoDestructor<int> low_entropy_source(
[] { return base::RandInt(0, kMaxLowEntropySize - 1); }());
return *low_entropy_source;
static const int low_entropy_source =
base::RandInt(0, kMaxLowEntropySize - 1);
;
return low_entropy_source;
}
// Generates a new non-identifying low entropy source using the same method
@ -38,9 +38,10 @@ int GenerateLowEntropySource() {
// used for statistical validation, and *not* for randomization or experiment
// assignment.
int GeneratePseudoLowEntropySource() {
static const base::NoDestructor<int> pseudo_low_entropy_source(
[] { return base::RandInt(0, kMaxLowEntropySize - 1); }());
return *pseudo_low_entropy_source;
static const int pseudo_low_entropy_source =
base::RandInt(0, kMaxLowEntropySize - 1);
;
return pseudo_low_entropy_source;
}
} // namespace

@ -5,7 +5,6 @@
#include "components/mirroring/service/video_capture_client.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "media/base/bind_to_current_loop.h"
@ -21,16 +20,16 @@ namespace {
// Required by mojom::VideoCaptureHost interface. Can be any nonzero value.
const base::UnguessableToken& DeviceId() {
static const base::NoDestructor<base::UnguessableToken> device_id(
static const base::UnguessableToken device_id(
base::UnguessableToken::Deserialize(1, 1));
return *device_id;
return device_id;
}
// Required by mojom::VideoCaptureHost interface. Can be any nonzero value.
const base::UnguessableToken& SessionId() {
static const base::NoDestructor<base::UnguessableToken> session_id(
static const base::UnguessableToken session_id(
base::UnguessableToken::Deserialize(1, 1));
return *session_id;
return session_id;
}
} // namespace

@ -32,7 +32,7 @@ namespace {
std::string GenerateFakeHashedString(size_t sym_count) {
static constexpr char kSyms[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,/=+?#";
static base::NoDestructor<std::mt19937> engine;
static std::mt19937 engine;
std::uniform_int_distribution<size_t> index_distribution(
0, base::size(kSyms) - 2 /* trailing \0 */);
@ -40,7 +40,7 @@ std::string GenerateFakeHashedString(size_t sym_count) {
res.reserve(sym_count);
std::generate_n(std::back_inserter(res), sym_count, [&index_distribution] {
return kSyms[index_distribution(*engine)];
return kSyms[index_distribution(engine)];
});
return res;

@ -9,7 +9,6 @@
#include "base/json/json_reader.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/version.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
@ -165,7 +164,7 @@ bool PasswordScriptsFetcherImpl::IsScriptAvailable(
}
void PasswordScriptsFetcherImpl::StartFetch() {
static const base::NoDestructor<base::TimeDelta> kFetchTimeout(
static const base::TimeDelta kFetchTimeout(
base::TimeDelta::FromSeconds(kFetchTimeoutInSeconds));
if (url_loader_)
return;
@ -195,7 +194,7 @@ void PasswordScriptsFetcherImpl::StartFetch() {
})");
url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation);
url_loader_->SetTimeoutDuration(*kFetchTimeout);
url_loader_->SetTimeoutDuration(kFetchTimeout);
url_loader_->DownloadToString(
url_loader_factory_.get(),
base::BindOnce(&PasswordScriptsFetcherImpl::OnFetchComplete,
@ -268,10 +267,10 @@ base::flat_set<ParsingResult> PasswordScriptsFetcherImpl::ParseResponse(
}
bool PasswordScriptsFetcherImpl::IsCacheStale() const {
static const base::NoDestructor<base::TimeDelta> kCacheTimeout(
static const base::TimeDelta kCacheTimeout(
base::TimeDelta::FromMinutes(kCacheTimeoutInMinutes));
return last_fetch_timestamp_.is_null() ||
base::TimeTicks::Now() - last_fetch_timestamp_ >= *kCacheTimeout;
base::TimeTicks::Now() - last_fetch_timestamp_ >= kCacheTimeout;
}
void PasswordScriptsFetcherImpl::RunResponseCallback(

@ -32,8 +32,8 @@ GraphCreatedCallback* GetAdditionalGraphCreatedCallback() {
}
absl::optional<Decorators>* GetDecoratorsOverride() {
static base::NoDestructor<absl::optional<Decorators>> decorators_override;
return decorators_override.get();
static absl::optional<Decorators> decorators_override;
return &decorators_override;
}
void OnGraphCreated(Decorators decorators,

@ -5,6 +5,7 @@
#include "components/site_isolation/site_isolation_policy.h"
#include "base/base_switches.h"
#include "base/no_destructor.h"
#include "base/system/sys_info.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_entropy_provider.h"

@ -15,6 +15,7 @@
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"

@ -14,7 +14,6 @@
#include <string>
#include "base/android/build_info.h"
#include "base/no_destructor.h"
#endif
namespace viz {
@ -37,7 +36,8 @@ bool AlwaysUseWideColorGamut() {
if (command_line.HasSwitch(kDisableWCGForTest))
return false;
auto compute_always_use_wide_color_gamut = []() {
// As it takes some work to compute this, cache the result.
static bool is_always_use_wide_color_gamut_enabled = [] {
const char* current_model =
base::android::BuildInfo::GetInstance()->model();
const std::array<std::string, 2> enabled_models = {
@ -48,12 +48,9 @@ bool AlwaysUseWideColorGamut() {
}
return false;
};
}();
// As it takes some work to compute this, cache the result.
static base::NoDestructor<bool> is_always_use_wide_color_gamut_enabled(
compute_always_use_wide_color_gamut());
return *is_always_use_wide_color_gamut_enabled;
return is_always_use_wide_color_gamut_enabled;
}
#endif

@ -7,7 +7,6 @@
#include "base/command_line.h"
#include "base/deferred_sequenced_task_runner.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/time/time.h"
@ -109,10 +108,10 @@ void LaunchAudioServiceInProcess(
base::BindOnce(
[](media::AudioManager* audio_manager,
mojo::PendingReceiver<audio::mojom::AudioService> receiver) {
static base::NoDestructor<
base::SequenceLocalStorageSlot<std::unique_ptr<audio::Service>>>
static base::SequenceLocalStorageSlot<
std::unique_ptr<audio::Service>>
service;
service->GetOrCreateValue() = audio::CreateEmbeddedService(
service.GetOrCreateValue() = audio::CreateEmbeddedService(
audio_manager, std::move(receiver));
},
BrowserMainLoop::GetAudioManager(), std::move(receiver)));
@ -162,10 +161,10 @@ audio::mojom::AudioService& GetAudioService() {
// any sequence, but to limit the lifetime of this Remote to the lifetime of
// UI-thread sequence. This is to support re-creation after task environment
// shutdown and reinitialization e.g. between unit tests.
static base::NoDestructor<
base::SequenceLocalStorageSlot<mojo::Remote<audio::mojom::AudioService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<audio::mojom::AudioService>>
remote_slot;
auto& remote = remote_slot->GetOrCreateValue();
auto& remote = remote_slot.GetOrCreateValue();
if (!remote)
LaunchAudioService(&remote);
return *remote.get();

@ -5,7 +5,6 @@
#include "content/public/browser/device_service.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/sequence_local_storage_slot.h"
@ -80,10 +79,9 @@ void BindDeviceServiceReceiver(
mojo::PendingReceiver<device::mojom::DeviceService> receiver) {
// Bind the lifetime of the service instance to that of the sequence it's
// running on.
static base::NoDestructor<
base::SequenceLocalStorageSlot<std::unique_ptr<device::DeviceService>>>
static base::SequenceLocalStorageSlot<std::unique_ptr<device::DeviceService>>
service_slot;
auto& service = service_slot->GetOrCreateValue();
auto& service = service_slot.GetOrCreateValue();
if (service) {
service->AddReceiver(std::move(receiver));
@ -128,11 +126,11 @@ void BindDeviceServiceReceiver(
} // namespace
device::mojom::DeviceService& GetDeviceService() {
static base::NoDestructor<base::SequenceLocalStorageSlot<
mojo::Remote<device::mojom::DeviceService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<device::mojom::DeviceService>>
remote_slot;
mojo::Remote<device::mojom::DeviceService>& remote =
remote_slot->GetOrCreateValue();
remote_slot.GetOrCreateValue();
if (!remote) {
// This may be called very early in startup, too early for some Device
// Service initialization steps (for example, in browser test environments,

@ -5,16 +5,12 @@
#ifndef CONTENT_BROWSER_FONT_ACCESS_FONT_ENUMERATION_CACHE_FONTCONFIG_H_
#define CONTENT_BROWSER_FONT_ACCESS_FONT_ENUMERATION_CACHE_FONTCONFIG_H_
#include "base/no_destructor.h"
#include "content/browser/font_access/font_enumeration_cache.h"
#include "content/common/content_export.h"
using blink::mojom::FontEnumerationStatus;
namespace base {
template <typename T>
class NoDestructor;
}
namespace content {
// ChromeOS and Linux implementation of FontEnumerationCache.

@ -6,17 +6,13 @@
#define CONTENT_BROWSER_FONT_ACCESS_FONT_ENUMERATION_CACHE_MAC_H_
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/task_runner.h"
#include "content/browser/font_access/font_enumeration_cache.h"
#include "content/common/content_export.h"
using blink::mojom::FontEnumerationStatus;
namespace base {
template <typename T>
class NoDestructor;
}
namespace content {
// Mac implementation of FontEnumerationCache.

@ -10,6 +10,7 @@
#include "base/deferred_sequenced_task_runner.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/no_destructor.h"
#include "base/synchronization/atomic_flag.h"
#include "content/browser/font_access/font_enumeration_cache.h"
#include "content/common/content_export.h"
@ -18,9 +19,6 @@
using blink::mojom::FontEnumerationStatus;
namespace base {
template <typename T>
class NoDestructor;
class ElapsedTimer;
}

@ -54,10 +54,10 @@ media::mojom::MediaService& GetMediaService() {
// that of the UI-thread sequence. This ensures that the Remote is destroyed
// when the task environment is torn down and reinitialized, e.g. between unit
// tests.
static base::NoDestructor<
base::SequenceLocalStorageSlot<mojo::Remote<media::mojom::MediaService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<media::mojom::MediaService>>
remote_slot;
auto& remote = remote_slot->GetOrCreateValue();
auto& remote = remote_slot.GetOrCreateValue();
if (!remote) {
auto receiver = remote.BindNewPipeAndPassReceiver();
remote.reset_on_disconnect();

@ -11,7 +11,6 @@
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/time/time.h"
#include "content/browser/service_sandbox_type.h"
@ -154,8 +153,8 @@ ServiceMap<T>& GetServiceMap() {
// objects to that of the UI-thread sequence. This ensures the Remotes are
// destroyed when the task environment is torn down and reinitialized, e.g.,
// between unit tests.
static base::NoDestructor<base::SequenceLocalStorageSlot<ServiceMap<T>>> slot;
return slot->GetOrCreateValue();
static base::SequenceLocalStorageSlot<ServiceMap<T>> slot;
return slot.GetOrCreateValue();
}
// Erases the service instance identified by `key`.

@ -5,7 +5,6 @@
#include "content/browser/media/session/audio_focus_delegate.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "content/browser/media/session/media_session_impl.h"
@ -32,9 +31,8 @@ base::UnguessableToken GetAudioFocusGroupId(MediaSessionImpl* session) {
// Use a shared audio focus group id for the whole browser. This will means
// that tabs will share audio focus if the enforcement mode is set to
// kSingleGroup.
static const base::NoDestructor<base::UnguessableToken> token(
base::UnguessableToken::Create());
return *token;
static const base::UnguessableToken token(base::UnguessableToken::Create());
return token;
}
// AudioFocusDelegateDefault is the default implementation of

@ -79,10 +79,10 @@ bool g_network_service_is_responding = false;
base::Time g_last_network_service_crash;
std::unique_ptr<network::NetworkService>& GetLocalNetworkService() {
static base::NoDestructor<
base::SequenceLocalStorageSlot<std::unique_ptr<network::NetworkService>>>
static base::SequenceLocalStorageSlot<
std::unique_ptr<network::NetworkService>>
service;
return service->GetOrCreateValue();
return service.GetOrCreateValue();
}
// If this feature is enabled, the Network Service will run on its own thread
@ -575,10 +575,10 @@ void RunInProcessCertVerifierServiceFactory(
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
#endif
static base::NoDestructor<base::SequenceLocalStorageSlot<
std::unique_ptr<cert_verifier::CertVerifierServiceFactoryImpl>>>
static base::SequenceLocalStorageSlot<
std::unique_ptr<cert_verifier::CertVerifierServiceFactoryImpl>>
service_factory_slot;
service_factory_slot->GetOrCreateValue() =
service_factory_slot.GetOrCreateValue() =
std::make_unique<cert_verifier::CertVerifierServiceFactoryImpl>(
std::move(receiver));
}
@ -587,10 +587,10 @@ void RunInProcessCertVerifierServiceFactory(
// Lives on the UI thread.
mojo::Remote<cert_verifier::mojom::CertVerifierServiceFactory>&
GetCertVerifierServiceFactoryRemoteStorage() {
static base::NoDestructor<base::SequenceLocalStorageSlot<
mojo::Remote<cert_verifier::mojom::CertVerifierServiceFactory>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<cert_verifier::mojom::CertVerifierServiceFactory>>
cert_verifier_service_factory_remote;
return cert_verifier_service_factory_remote->GetOrCreateValue();
return cert_verifier_service_factory_remote.GetOrCreateValue();
}
// Returns a pointer to a CertVerifierServiceFactory usable on the UI thread.

@ -19,6 +19,7 @@
#include "base/macros.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "base/synchronization/atomic_flag.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
@ -26,11 +27,6 @@
#include "third_party/blink/public/common/font_unique_name_lookup/font_unique_name_table.pb.h"
#include "third_party/blink/public/mojom/dwrite_font_proxy/dwrite_font_proxy.mojom.h"
namespace base {
template <typename T>
class NoDestructor;
}
namespace content {
// Singleton class which encapsulates building the font unique name table lookup

@ -17,7 +17,6 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h"
@ -41,10 +40,10 @@ void LogVideoCaptureError(media::VideoCaptureError error) {
}
const base::UnguessableToken& FakeSessionId() {
static const base::NoDestructor<base::UnguessableToken> fake_session_id(
static const base::UnguessableToken fake_session_id(
base::UnguessableToken::Deserialize(0xFFFFFFFFFFFFFFFFU,
0xFFFFFFFFFFFFFFFFU));
return *fake_session_id;
return fake_session_id;
}
} // namespace

@ -13,7 +13,6 @@
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
@ -70,9 +69,9 @@ void VideoInputDevicesEnumerated(base::OnceClosure quit_closure,
// Id used to identify the capture session between renderer and
// video_capture_host. This is an arbitrary value.
const base::UnguessableToken& DeviceId() {
static const base::NoDestructor<base::UnguessableToken> device_id(
static const base::UnguessableToken device_id(
base::UnguessableToken::Deserialize(555, 555));
return *device_id;
return device_id;
}
} // namespace

@ -9,15 +9,11 @@
#include "base/check.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/threading/simple_thread.h"
#include "content/browser/sandbox_ipc_linux.h"
#include "content/common/content_export.h"
namespace base {
template <typename T>
class NoDestructor;
}
namespace content {
// This is a singleton object which handles sandbox requests from the

@ -154,19 +154,19 @@ mojo::Remote<storage::mojom::StorageService>& GetStorageServiceRemoteStorage() {
// NOTE: This use of sequence-local storage is only to ensure that the Remote
// only lives as long as the UI-thread sequence, since the UI-thread sequence
// may be torn down and reinitialized e.g. between unit tests.
static base::NoDestructor<base::SequenceLocalStorageSlot<
mojo::Remote<storage::mojom::StorageService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<storage::mojom::StorageService>>
remote_slot;
return remote_slot->GetOrCreateValue();
return remote_slot.GetOrCreateValue();
}
void RunInProcessStorageService(
mojo::PendingReceiver<storage::mojom::StorageService> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
static base::NoDestructor<base::SequenceLocalStorageSlot<
std::unique_ptr<storage::StorageServiceImpl>>>
static base::SequenceLocalStorageSlot<
std::unique_ptr<storage::StorageServiceImpl>>
service_storage_slot;
service_storage_slot->GetOrCreateValue() =
service_storage_slot.GetOrCreateValue() =
std::make_unique<storage::StorageServiceImpl>(std::move(receiver),
/*io_task_runner=*/nullptr);
}

@ -12,17 +12,13 @@
#include <vector>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "content/browser/tracing/background_tracing_config_impl.h"
#include "content/public/browser/background_tracing_manager.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"
#include "services/tracing/public/mojom/background_tracing_agent.mojom.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace tracing {
namespace mojom {
class BackgroundTracingAgent;

@ -45,10 +45,10 @@ mojo::Remote<video_capture::mojom::VideoCaptureService>& GetUIThreadRemote() {
// NOTE: This use of sequence-local storage is only to ensure that the Remote
// only lives as long as the UI-thread sequence, since the UI-thread sequence
// may be torn down and reinitialized e.g. between unit tests.
static base::NoDestructor<base::SequenceLocalStorageSlot<
mojo::Remote<video_capture::mojom::VideoCaptureService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<video_capture::mojom::VideoCaptureService>>
remote_slot;
return remote_slot->GetOrCreateValue();
return remote_slot.GetOrCreateValue();
}
// This is a custom traits type we use in conjunction with mojo::ReceiverSetBase
@ -79,10 +79,10 @@ void BindProxyRemoteOnUIThread(
video_capture::mojom::VideoCaptureService& GetVideoCaptureService() {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
static base::NoDestructor<base::SequenceLocalStorageSlot<
mojo::Remote<video_capture::mojom::VideoCaptureService>>>
static base::SequenceLocalStorageSlot<
mojo::Remote<video_capture::mojom::VideoCaptureService>>
storage;
auto& remote = storage->GetOrCreateValue();
auto& remote = storage.GetOrCreateValue();
if (!remote.is_bound()) {
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&BindProxyRemoteOnUIThread,

@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@ -254,9 +253,9 @@ int MakeRequestID() {
// uninitialized variables.) This way, we no longer have the unlikely (but
// observed in the real world!) event where we have two requests with the same
// request_id_.
static base::NoDestructor<std::atomic_int> request_id(-1);
static std::atomic_int request_id(-1);
return --*request_id;
return --request_id;
}
base::Time GetVerificationTime() {

@ -5,7 +5,6 @@
#include "content/public/browser/renderer_preferences_util.h"
#include "base/command_line.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "content/public/common/content_switches.h"
@ -16,14 +15,14 @@ namespace content {
void UpdateFontRendererPreferencesFromSystemSettings(
blink::RendererPreferences* prefs) {
static const base::NoDestructor<gfx::FontRenderParams> params(
static const gfx::FontRenderParams params(
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr));
prefs->should_antialias_text = params->antialiasing;
prefs->use_subpixel_positioning = params->subpixel_positioning;
prefs->hinting = params->hinting;
prefs->use_autohinter = params->autohinter;
prefs->use_bitmaps = params->use_bitmaps;
prefs->subpixel_rendering = params->subpixel_rendering;
prefs->should_antialias_text = params.antialiasing;
prefs->use_subpixel_positioning = params.subpixel_positioning;
prefs->hinting = params.hinting;
prefs->use_autohinter = params.autohinter;
prefs->use_bitmaps = params.use_bitmaps;
prefs->subpixel_rendering = params.subpixel_rendering;
}
} // namespace content

@ -14,7 +14,6 @@
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
@ -402,10 +401,9 @@ mojo::Remote<::media::mojom::MediaService>
ShellContentBrowserClient::RunSecondaryMediaService() {
mojo::Remote<::media::mojom::MediaService> remote;
#if BUILDFLAG(ENABLE_CAST_RENDERER)
static base::NoDestructor<
base::SequenceLocalStorageSlot<std::unique_ptr<::media::MediaService>>>
static base::SequenceLocalStorageSlot<std::unique_ptr<::media::MediaService>>
service;
service->emplace(::media::CreateMediaServiceForTesting(
service.emplace(::media::CreateMediaServiceForTesting(
remote.BindNewPipeAndPassReceiver()));
#endif
return remote;

@ -16,6 +16,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/memory_allocator_dump.h"

@ -8,6 +8,7 @@
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"

@ -176,8 +176,8 @@ using FrameImplMap =
base::small_map<std::map<content::WebContents*, FrameImpl*>>;
FrameImplMap& WebContentsToFrameImplMap() {
static base::NoDestructor<FrameImplMap> frame_impl_map;
return *frame_impl_map;
static FrameImplMap frame_impl_map;
return frame_impl_map;
}
content::PermissionType FidlPermissionTypeToContentPermissionType(

@ -1479,18 +1479,17 @@ VaapiWrapper::InternalFormats VaapiWrapper::GetDecodeSupportedInternalFormats(
bool VaapiWrapper::IsDecodingSupportedForInternalFormat(
VAProfile va_profile,
unsigned int rt_format) {
static const base::NoDestructor<VaapiWrapper::InternalFormats>
supported_internal_formats(
VaapiWrapper::GetDecodeSupportedInternalFormats(va_profile));
static const VaapiWrapper::InternalFormats supported_internal_formats(
VaapiWrapper::GetDecodeSupportedInternalFormats(va_profile));
switch (rt_format) {
case VA_RT_FORMAT_YUV420:
return supported_internal_formats->yuv420;
return supported_internal_formats.yuv420;
case VA_RT_FORMAT_YUV420_10:
return supported_internal_formats->yuv420_10;
return supported_internal_formats.yuv420_10;
case VA_RT_FORMAT_YUV422:
return supported_internal_formats->yuv422;
return supported_internal_formats.yuv422;
case VA_RT_FORMAT_YUV444:
return supported_internal_formats->yuv444;
return supported_internal_formats.yuv444;
}
return false;
}

@ -14,7 +14,6 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/sequenced_task_runner.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
@ -39,8 +38,8 @@ namespace media {
namespace {
// Number of functional instances of MojoVideoDecoder in the current process.
std::atomic<int>& get_mojo_instance_counter() {
static base::NoDestructor<std::atomic<int>> gInstanceCounter(0);
return *gInstanceCounter;
static std::atomic<int> instance_counter(0);
return instance_counter;
}
} // namespace

@ -75,8 +75,8 @@ FakeGpuMemoryBuffer::FakeGpuMemoryBuffer(const gfx::Size& size,
handle_.type = gfx::NATIVE_PIXMAP;
static base::NoDestructor<base::AtomicSequenceNumber> buffer_id_generator;
handle_.id = gfx::GpuMemoryBufferId(buffer_id_generator->GetNext());
static base::AtomicSequenceNumber buffer_id_generator;
handle_.id = gfx::GpuMemoryBufferId(buffer_id_generator.GetNext());
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
for (size_t i = 0; i < VideoFrame::NumPlanes(video_pixel_format_); i++) {

@ -13,7 +13,6 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_pump_type.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
@ -146,9 +145,9 @@ MojoResult InitializeImpl(const struct MojoInitializeOptions* options) {
argv = options->argv;
}
static base::NoDestructor<GlobalStateInitializer> global_state_initializer;
static GlobalStateInitializer global_state_initializer;
const bool was_global_state_already_initialized =
!global_state_initializer->Initialize(argc, argv);
!global_state_initializer.Initialize(argc, argv);
if (!should_initialize_ipc_support) {
if (was_global_state_already_initialized)

@ -5,7 +5,6 @@
#include <stdint.h>
#include "base/containers/span.h"
#include "base/no_destructor.h"
#include "mojo/core/entrypoints.h"
#include "mojo/core/node_controller.h"
@ -16,7 +15,7 @@ struct Environment {
};
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
static base::NoDestructor<Environment> environment;
static Environment environment;
// Try using the fuzz as the full contents of a port event.
mojo::core::NodeController::DeserializeRawBytesAsEventForFuzzer(

@ -5,7 +5,6 @@
#include <stdint.h>
#include "base/containers/span.h"
#include "base/no_destructor.h"
#include "mojo/core/entrypoints.h"
#include "mojo/core/node_controller.h"
#include "mojo/core/user_message_impl.h"
@ -17,7 +16,7 @@ struct Environment {
};
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
static base::NoDestructor<Environment> environment;
static Environment environment;
// Try using our fuzz input as the payload of an otherwise well-formed user
// message event.

@ -142,7 +142,9 @@ class CoreLibraryInitializer {
extern "C" {
MojoResult MojoInitialize(const struct MojoInitializeOptions* options) {
static base::NoDestructor<mojo::CoreLibraryInitializer> initializer;
static base::NoDestructor<mojo::CoreLibraryInitializer,
base::AllowForTriviallyDestructibleType>
initializer;
base::StringPiece library_path_utf8;
if (options) {

Some files were not shown because too many files have changed in this diff Show More