| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/sequence_token.h" | 12 #include "base/sequence_token.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/threading/simple_thread.h" | 14 #include "base/threading/simple_thread.h" |
| 15 #include "base/threading/thread_checker.h" |
| 14 #include "base/threading/thread_checker_impl.h" | 16 #include "base/threading/thread_checker_impl.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 23 #if !DCHECK_IS_ON() |
| 24 class ClassWithThreadChecker { |
| 25 BASE_EXPORT size_t SilenceUnusedWarnings() { |
| 26 return x + (y.CalledOnValidThread() ? 1 : 0); |
| 27 } |
| 28 uint32_t x; |
| 29 ThreadChecker y; |
| 30 }; |
| 31 |
| 32 static_assert(sizeof(ClassWithThreadChecker) == sizeof(uint32_t), "ThreadChecker
ShouldHaveZeroSize"); |
| 33 #endif |
| 34 |
| 21 // A thread that runs a callback. | 35 // A thread that runs a callback. |
| 22 class RunCallbackThread : public SimpleThread { | 36 class RunCallbackThread : public SimpleThread { |
| 23 public: | 37 public: |
| 24 explicit RunCallbackThread(const Closure& callback) | 38 explicit RunCallbackThread(const Closure& callback) |
| 25 : SimpleThread("RunCallbackThread"), callback_(callback) {} | 39 : SimpleThread("RunCallbackThread"), callback_(callback) {} |
| 26 | 40 |
| 27 private: | 41 private: |
| 28 // SimpleThread: | 42 // SimpleThread: |
| 29 void Run() override { callback_.Run(); } | 43 void Run() override { callback_.Run(); } |
| 30 | 44 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 200 |
| 187 // Verify that CalledOnValidThread() returns true when called on a different | 201 // Verify that CalledOnValidThread() returns true when called on a different |
| 188 // thread after a call to DetachFromThread(). | 202 // thread after a call to DetachFromThread(). |
| 189 RunCallbackOnNewThreadSynchronously( | 203 RunCallbackOnNewThreadSynchronously( |
| 190 Bind(&ExpectCalledOnValidThread, Unretained(&thread_checker))); | 204 Bind(&ExpectCalledOnValidThread, Unretained(&thread_checker))); |
| 191 | 205 |
| 192 EXPECT_FALSE(thread_checker.CalledOnValidThread()); | 206 EXPECT_FALSE(thread_checker.CalledOnValidThread()); |
| 193 } | 207 } |
| 194 | 208 |
| 195 } // namespace base | 209 } // namespace base |
| OLD | NEW |