1 // Copyright 2019 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/copy_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 14 // static 15 int CopyOnlyInt::num_copies_ = 0; 16 ~CopyOnlyInt()17CopyOnlyInt::~CopyOnlyInt() { 18 int old_data = std::exchange(data_, 0); 19 if (GetDestructionCallbackStorage()) { 20 GetDestructionCallbackStorage().Run(old_data); 21 } 22 } 23 GetDestructionCallbackStorage()24RepeatingCallback<void(int)>& CopyOnlyInt::GetDestructionCallbackStorage() { 25 static NoDestructor<RepeatingCallback<void(int)>> callback; 26 return *callback; 27 } 28 29 } // namespace base 30