1 // Copyright 2024 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/test/move_only_int.h" 6 7 #include <utility> 8 9 #include "base/functional/callback.h" 10 #include "base/no_destructor.h" 11 12 namespace base { 13 ~MoveOnlyInt()14MoveOnlyInt::~MoveOnlyInt() { 15 int old_data = std::exchange(data_, 0); 16 if (GetDestructionCallbackStorage()) { 17 GetDestructionCallbackStorage().Run(old_data); 18 } 19 } 20 GetDestructionCallbackStorage()21RepeatingCallback<void(int)>& MoveOnlyInt::GetDestructionCallbackStorage() { 22 static NoDestructor<RepeatingCallback<void(int)>> callback; 23 return *callback; 24 } 25 26 } // namespace base 27