1 // Copyright 2022 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/threading/thread_checker.h" 6 7 #if DCHECK_IS_ON() 8 #include <memory> 9 #include <ostream> 10 11 #include "base/check.h" 12 #include "base/debug/stack_trace.h" 13 #endif 14 15 namespace base { 16 17 #if DCHECK_IS_ON() ScopedValidateThreadChecker(const ThreadChecker & checker)18ScopedValidateThreadChecker::ScopedValidateThreadChecker( 19 const ThreadChecker& checker) { 20 std::unique_ptr<debug::StackTrace> bound_at; 21 DCHECK(checker.CalledOnValidThread(&bound_at)) 22 << (bound_at ? "\nWas attached to thread at:\n" + bound_at->ToString() 23 : ""); 24 } 25 ScopedValidateThreadChecker(const ThreadChecker & checker,const StringPiece & msg)26ScopedValidateThreadChecker::ScopedValidateThreadChecker( 27 const ThreadChecker& checker, 28 const StringPiece& msg) { 29 std::unique_ptr<debug::StackTrace> bound_at; 30 DCHECK(checker.CalledOnValidThread(&bound_at)) 31 << msg 32 << (bound_at ? "\nWas attached to thread at:\n" + bound_at->ToString() 33 : ""); 34 } 35 36 ScopedValidateThreadChecker::~ScopedValidateThreadChecker() = default; 37 #endif // DCHECK_IS_ON() 38 39 } // namespace base 40