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 <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 WaitState old_state; | 110 WaitState old_state; |
111 { | 111 { |
112 base::AutoLock auto_lock(custom_lock_); | 112 base::AutoLock auto_lock(custom_lock_); |
113 old_state = wait_state_; | 113 old_state = wait_state_; |
114 wait_state_ = new_state; | 114 wait_state_ = new_state; |
115 } | 115 } |
116 state_changed_.Broadcast(); | 116 state_changed_.Broadcast(); |
117 return old_state; | 117 return old_state; |
118 } | 118 } |
119 | 119 |
120 void ActivateThreadWatching() { | 120 virtual void ActivateThreadWatching() OVERRIDE { |
121 State old_state = UpdateState(ACTIVATED); | 121 State old_state = UpdateState(ACTIVATED); |
122 EXPECT_EQ(old_state, INITIALIZED); | 122 EXPECT_EQ(old_state, INITIALIZED); |
123 ThreadWatcher::ActivateThreadWatching(); | 123 ThreadWatcher::ActivateThreadWatching(); |
124 } | 124 } |
125 | 125 |
126 void DeActivateThreadWatching() { | 126 virtual void DeActivateThreadWatching() OVERRIDE { |
127 State old_state = UpdateState(DEACTIVATED); | 127 State old_state = UpdateState(DEACTIVATED); |
128 EXPECT_TRUE(old_state == ACTIVATED || old_state == SENT_PING || | 128 EXPECT_TRUE(old_state == ACTIVATED || old_state == SENT_PING || |
129 old_state == RECEIVED_PONG); | 129 old_state == RECEIVED_PONG); |
130 ThreadWatcher::DeActivateThreadWatching(); | 130 ThreadWatcher::DeActivateThreadWatching(); |
131 } | 131 } |
132 | 132 |
133 void PostPingMessage() { | 133 virtual void PostPingMessage() OVERRIDE { |
134 State old_state = UpdateState(SENT_PING); | 134 State old_state = UpdateState(SENT_PING); |
135 EXPECT_TRUE(old_state == ACTIVATED || old_state == RECEIVED_PONG); | 135 EXPECT_TRUE(old_state == ACTIVATED || old_state == RECEIVED_PONG); |
136 ThreadWatcher::PostPingMessage(); | 136 ThreadWatcher::PostPingMessage(); |
137 } | 137 } |
138 | 138 |
139 void OnPongMessage(uint64 ping_sequence_number) { | 139 virtual void OnPongMessage(uint64 ping_sequence_number) OVERRIDE { |
140 State old_state = UpdateState(RECEIVED_PONG); | 140 State old_state = UpdateState(RECEIVED_PONG); |
141 EXPECT_TRUE(old_state == SENT_PING || old_state == DEACTIVATED); | 141 EXPECT_TRUE(old_state == SENT_PING || old_state == DEACTIVATED); |
142 ThreadWatcher::OnPongMessage(ping_sequence_number); | 142 ThreadWatcher::OnPongMessage(ping_sequence_number); |
143 } | 143 } |
144 | 144 |
145 void OnCheckResponsiveness(uint64 ping_sequence_number) { | 145 virtual void OnCheckResponsiveness(uint64 ping_sequence_number) OVERRIDE { |
146 ThreadWatcher::OnCheckResponsiveness(ping_sequence_number); | 146 ThreadWatcher::OnCheckResponsiveness(ping_sequence_number); |
147 { | 147 { |
148 base::AutoLock auto_lock(custom_lock_); | 148 base::AutoLock auto_lock(custom_lock_); |
149 if (responsive_) { | 149 if (responsive_) { |
150 ++success_response_; | 150 ++success_response_; |
151 check_response_state_ = SUCCESSFUL; | 151 check_response_state_ = SUCCESSFUL; |
152 } else { | 152 } else { |
153 ++failed_response_; | 153 ++failed_response_; |
154 check_response_state_ = FAILED; | 154 check_response_state_ = FAILED; |
155 } | 155 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 void WaitForSetUp(TimeDelta wait_time) { | 290 void WaitForSetUp(TimeDelta wait_time) { |
291 DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread()); | 291 DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread()); |
292 TimeTicks end_time = TimeTicks::Now() + wait_time; | 292 TimeTicks end_time = TimeTicks::Now() + wait_time; |
293 { | 293 { |
294 base::AutoLock auto_lock(lock_); | 294 base::AutoLock auto_lock(lock_); |
295 while (!initialized_ && TimeTicks::Now() < end_time) | 295 while (!initialized_ && TimeTicks::Now() < end_time) |
296 setup_complete_.TimedWait(end_time - TimeTicks::Now()); | 296 setup_complete_.TimedWait(end_time - TimeTicks::Now()); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 ~ThreadWatcherTest() { | 300 virtual ~ThreadWatcherTest() { |
301 ThreadWatcherList::DeleteAll(); | 301 ThreadWatcherList::DeleteAll(); |
302 io_watcher_ = NULL; | 302 io_watcher_ = NULL; |
303 webkit_watcher_ = NULL; | 303 webkit_watcher_ = NULL; |
304 io_thread_.reset(); | 304 io_thread_.reset(); |
305 webkit_thread_.reset(); | 305 webkit_thread_.reset(); |
306 watchdog_thread_.reset(); | 306 watchdog_thread_.reset(); |
307 thread_watcher_list_ = NULL; | 307 thread_watcher_list_ = NULL; |
308 } | 308 } |
309 | 309 |
310 private: | 310 private: |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 base::Bind(&ThreadWatcher::DeActivateThreadWatching, | 549 base::Bind(&ThreadWatcher::DeActivateThreadWatching, |
550 base::Unretained(io_watcher_))); | 550 base::Unretained(io_watcher_))); |
551 WatchDogThread::PostTask( | 551 WatchDogThread::PostTask( |
552 FROM_HERE, | 552 FROM_HERE, |
553 base::Bind(&ThreadWatcher::DeActivateThreadWatching, | 553 base::Bind(&ThreadWatcher::DeActivateThreadWatching, |
554 base::Unretained(webkit_watcher_))); | 554 base::Unretained(webkit_watcher_))); |
555 | 555 |
556 // Wait for the io_watcher_'s VeryLongMethod to finish. | 556 // Wait for the io_watcher_'s VeryLongMethod to finish. |
557 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); | 557 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); |
558 } | 558 } |
OLD | NEW |