1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/win/resource_exhaustion.h" 6 7 #include <utility> 8 9 #include "base/functional/callback.h" 10 #include "base/no_destructor.h" 11 12 namespace base::win { 13 14 namespace { 15 16 OnResourceExhaustedFunction g_resource_exhausted_function = nullptr; 17 18 } // namespace 19 SetOnResourceExhaustedFunction(OnResourceExhaustedFunction on_resource_exhausted)20void SetOnResourceExhaustedFunction( 21 OnResourceExhaustedFunction on_resource_exhausted) { 22 g_resource_exhausted_function = on_resource_exhausted; 23 } 24 OnResourceExhausted()25void OnResourceExhausted() { 26 // Stop execution here if there is no callback installed. 27 CHECK(g_resource_exhausted_function) << "system resource exhausted."; 28 g_resource_exhausted_function(); 29 } 30 31 } // namespace base::win 32