diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-03 18:18:14 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-03 18:18:14 +0000 |
commit | 2d31666a58e746b7a1d415c99e5f68ad9256d236 (patch) | |
tree | 144c99d4b80df0f0f9a3ded83f9d21a8b36f17cc /net/disk_cache | |
parent | 90d6958fe2374a00d3c8583cf4d3b8a509ae8e90 (diff) | |
download | chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.zip chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.gz chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.bz2 |
Minor cleanup to OneShotTimer and RepeatingTimer: moves more of the member variables into the Task subclass.
Also included in this change: deprecate MessageLoop::timer_manager(), and change consumers over to use OneShotTimer or RepeatingTimer.
R=beng
BUG=1346553
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 45 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 50 |
2 files changed, 35 insertions, 60 deletions
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 98bd092..d82cbb4 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -96,9 +96,28 @@ void CallbackTest::RunWithParams(const Tuple1<int>& params) { // ----------------------------------------------------------------------- +MessageLoopHelper::MessageLoopHelper() + : num_callbacks_(0), + num_iterations_(0), + last_(0), + completed_(false) { + // Create a recurrent timer of 50 mS. + timer_.Start( + TimeDelta::FromMilliseconds(50), this, &MessageLoopHelper::TimerExpired); +} + +bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) { + if (num_callbacks == g_cache_tests_received) + return true; + + ExpectCallbacks(num_callbacks); + MessageLoop::current()->Run(); + return completed_; +} + // Quits the message loop when all callbacks are called or we've been waiting // too long for them (2 secs without a callback). -void TimerTask::Run() { +void MessageLoopHelper::TimerExpired() { if (g_cache_tests_received > num_callbacks_) { NOTREACHED(); } else if (g_cache_tests_received == num_callbacks_) { @@ -114,27 +133,3 @@ void TimerTask::Run() { MessageLoop::current()->Quit(); } } - -// ----------------------------------------------------------------------- - -MessageLoopHelper::MessageLoopHelper() { - message_loop_ = MessageLoop::current(); - // Create a recurrent timer of 50 mS. - timer_ = message_loop_->timer_manager()->StartTimer(50, &timer_task_, true); -} - -MessageLoopHelper::~MessageLoopHelper() { - message_loop_->timer_manager()->StopTimer(timer_); - delete timer_; -} - -bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) { - if (num_callbacks == g_cache_tests_received) - return true; - - timer_task_.ExpectCallbacks(num_callbacks); - message_loop_->Run(); - return timer_task_.GetSate(); -} - - diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index 3b5c9ef8..4277d02 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H__ -#define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H__ +#ifndef NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ +#define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ #include <string> @@ -46,20 +46,21 @@ class CallbackTest : public CallbackRunner< Tuple1<int> > { private: int id_; int reuse_; - DISALLOW_EVIL_CONSTRUCTORS(CallbackTest); + DISALLOW_COPY_AND_ASSIGN(CallbackTest); }; // ----------------------------------------------------------------------- -// We'll use a timer to fire from time to time to check the number of IO -// operations finished so far. -class TimerTask : public Task { +// Simple helper to deal with the message loop on a test. +class MessageLoopHelper { public: - TimerTask() : num_callbacks_(0), num_iterations_(0) {} - ~TimerTask() {} + MessageLoopHelper(); - virtual void Run(); + // Run the message loop and wait for num_callbacks before returning. Returns + // false if we are waiting to long. + bool WaitUntilCacheIoFinished(int num_callbacks); + private: // Sets the number of callbacks that can be received so far. void ExpectCallbacks(int num_callbacks) { num_callbacks_ = num_callbacks; @@ -67,37 +68,16 @@ class TimerTask : public Task { completed_ = false; } - // Returns true if all callbacks were invoked. - bool GetSate() { - return completed_; - } + // Called periodically to test if WaitUntilCacheIoFinished should return. + void TimerExpired(); - private: + base::RepeatingTimer<MessageLoopHelper> timer_; int num_callbacks_; int num_iterations_; int last_; bool completed_; - DISALLOW_EVIL_CONSTRUCTORS(TimerTask); -}; - -// ----------------------------------------------------------------------- -// Simple helper to deal with the message loop on a test. -class MessageLoopHelper { - public: - MessageLoopHelper(); - ~MessageLoopHelper(); - - // Run the message loop and wait for num_callbacks before returning. Returns - // false if we are waiting to long. - bool WaitUntilCacheIoFinished(int num_callbacks); - - private: - MessageLoop* message_loop_; - Timer* timer_; - TimerTask timer_task_; - DISALLOW_EVIL_CONSTRUCTORS(MessageLoopHelper); + DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); }; -#endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H__ - +#endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |