| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/threading/thread_checker.h" | 8 #include "base/threading/thread_checker.h" |
| 9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 // Calls ThreadCheckerClass::DoStuff on another thread. | 41 // Calls ThreadCheckerClass::DoStuff on another thread. |
| 42 class CallDoStuffOnThread : public base::SimpleThread { | 42 class CallDoStuffOnThread : public base::SimpleThread { |
| 43 public: | 43 public: |
| 44 CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class) | 44 CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class) |
| 45 : SimpleThread("call_do_stuff_on_thread"), | 45 : SimpleThread("call_do_stuff_on_thread"), |
| 46 thread_checker_class_(thread_checker_class) { | 46 thread_checker_class_(thread_checker_class) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void Run() { | 49 virtual void Run() OVERRIDE { |
| 50 thread_checker_class_->DoStuff(); | 50 thread_checker_class_->DoStuff(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 ThreadCheckerClass* thread_checker_class_; | 54 ThreadCheckerClass* thread_checker_class_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(CallDoStuffOnThread); | 56 DISALLOW_COPY_AND_ASSIGN(CallDoStuffOnThread); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Deletes ThreadCheckerClass on a different thread. | 59 // Deletes ThreadCheckerClass on a different thread. |
| 60 class DeleteThreadCheckerClassOnThread : public base::SimpleThread { | 60 class DeleteThreadCheckerClassOnThread : public base::SimpleThread { |
| 61 public: | 61 public: |
| 62 DeleteThreadCheckerClassOnThread(ThreadCheckerClass* thread_checker_class) | 62 DeleteThreadCheckerClassOnThread(ThreadCheckerClass* thread_checker_class) |
| 63 : SimpleThread("delete_thread_checker_class_on_thread"), | 63 : SimpleThread("delete_thread_checker_class_on_thread"), |
| 64 thread_checker_class_(thread_checker_class) { | 64 thread_checker_class_(thread_checker_class) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void Run() { | 67 virtual void Run() OVERRIDE { |
| 68 thread_checker_class_.reset(); | 68 thread_checker_class_.reset(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 scoped_ptr<ThreadCheckerClass> thread_checker_class_; | 72 scoped_ptr<ThreadCheckerClass> thread_checker_class_; |
| 73 | 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(DeleteThreadCheckerClassOnThread); | 74 DISALLOW_COPY_AND_ASSIGN(DeleteThreadCheckerClassOnThread); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 TEST(ThreadCheckerTest, CallsAllowedOnSameThread) { | 77 TEST(ThreadCheckerTest, CallsAllowedOnSameThread) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); | 165 ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); |
| 166 } | 166 } |
| 167 #endif // ENABLE_THREAD_CHECKER | 167 #endif // ENABLE_THREAD_CHECKER |
| 168 | 168 |
| 169 #endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER | 169 #endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER |
| 170 | 170 |
| 171 // Just in case we ever get lumped together with other compilation units. | 171 // Just in case we ever get lumped together with other compilation units. |
| 172 #undef ENABLE_THREAD_CHECKER | 172 #undef ENABLE_THREAD_CHECKER |
| 173 | 173 |
| 174 } // namespace base | 174 } // namespace base |
| OLD | NEW |