Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: base/threading/thread_unittest.cc

Issue 10004001: Add virtual and OVERRIDE to base/ implementation files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback from chromium-dev Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 17 matching lines...) Expand all
28 public: 28 public:
29 SleepInsideInitThread() : Thread("none") { 29 SleepInsideInitThread() : Thread("none") {
30 init_called_ = false; 30 init_called_ = false;
31 ANNOTATE_BENIGN_RACE( 31 ANNOTATE_BENIGN_RACE(
32 this, "Benign test-only data race on vptr - http://crbug.com/98219"); 32 this, "Benign test-only data race on vptr - http://crbug.com/98219");
33 } 33 }
34 virtual ~SleepInsideInitThread() { 34 virtual ~SleepInsideInitThread() {
35 Stop(); 35 Stop();
36 } 36 }
37 37
38 virtual void Init() { 38 virtual void Init() OVERRIDE {
39 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); 39 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500));
40 init_called_ = true; 40 init_called_ = true;
41 } 41 }
42 bool InitCalled() { return init_called_; } 42 bool InitCalled() { return init_called_; }
43 private: 43 private:
44 bool init_called_; 44 bool init_called_;
45 }; 45 };
46 46
47 enum ThreadEvent { 47 enum ThreadEvent {
48 // Thread::Init() was called. 48 // Thread::Init() was called.
(...skipping 10 matching lines...) Expand all
59 }; 59 };
60 60
61 typedef std::vector<ThreadEvent> EventList; 61 typedef std::vector<ThreadEvent> EventList;
62 62
63 class CaptureToEventList : public Thread { 63 class CaptureToEventList : public Thread {
64 public: 64 public:
65 // This Thread pushes events into the vector |event_list| to show 65 // This Thread pushes events into the vector |event_list| to show
66 // the order they occured in. |event_list| must remain valid for the 66 // the order they occured in. |event_list| must remain valid for the
67 // lifetime of this thread. 67 // lifetime of this thread.
68 explicit CaptureToEventList(EventList* event_list) 68 explicit CaptureToEventList(EventList* event_list)
69 : Thread("none"), event_list_(event_list) { 69 : Thread("none"), event_list_(event_list) {
jar (doing other things) 2012/04/05 21:11:30 nit: one init per line.
70 } 70 }
71 71
72 virtual ~CaptureToEventList() { 72 virtual ~CaptureToEventList() {
73 Stop(); 73 Stop();
74 } 74 }
75 75
76 virtual void Init() { 76 virtual void Init() OVERRIDE {
77 event_list_->push_back(THREAD_EVENT_INIT); 77 event_list_->push_back(THREAD_EVENT_INIT);
78 } 78 }
79 79
80 virtual void CleanUp() { 80 virtual void CleanUp() OVERRIDE {
81 event_list_->push_back(THREAD_EVENT_CLEANUP); 81 event_list_->push_back(THREAD_EVENT_CLEANUP);
82 } 82 }
83 83
84 private: 84 private:
85 EventList* event_list_; 85 EventList* event_list_;
86 }; 86 };
87 87
88 // Observer that writes a value into |event_list| when a message loop has been 88 // Observer that writes a value into |event_list| when a message loop has been
89 // destroyed. 89 // destroyed.
90 class CapturingDestructionObserver : public MessageLoop::DestructionObserver { 90 class CapturingDestructionObserver : public MessageLoop::DestructionObserver {
91 public: 91 public:
92 // |event_list| must remain valid throughout the observer's lifetime. 92 // |event_list| must remain valid throughout the observer's lifetime.
93 explicit CapturingDestructionObserver(EventList* event_list) 93 explicit CapturingDestructionObserver(EventList* event_list)
94 : event_list_(event_list) { 94 : event_list_(event_list) {
95 } 95 }
96 96
97 // DestructionObserver implementation: 97 // DestructionObserver implementation:
98 virtual void WillDestroyCurrentMessageLoop() { 98 virtual void WillDestroyCurrentMessageLoop() OVERRIDE {
99 event_list_->push_back(THREAD_EVENT_MESSAGE_LOOP_DESTROYED); 99 event_list_->push_back(THREAD_EVENT_MESSAGE_LOOP_DESTROYED);
100 event_list_ = NULL; 100 event_list_ = NULL;
101 } 101 }
102 102
103 private: 103 private:
104 EventList* event_list_; 104 EventList* event_list_;
105 }; 105 };
106 106
107 // Task that adds a destruction observer to the current message loop. 107 // Task that adds a destruction observer to the current message loop.
108 void RegisterDestructionObserver(MessageLoop::DestructionObserver* observer) { 108 void RegisterDestructionObserver(MessageLoop::DestructionObserver* observer) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 227
228 // Upon leaving this scope, the thread is deleted. 228 // Upon leaving this scope, the thread is deleted.
229 } 229 }
230 230
231 // Check the order of events during shutdown. 231 // Check the order of events during shutdown.
232 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); 232 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size());
233 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); 233 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]);
234 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); 234 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]);
235 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); 235 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]);
236 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698