summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 18:23:02 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 18:23:02 +0000
commitd323a176fa8c2ef474ce41dd8a1cddacb4fc67ff (patch)
tree5a6b91bcea70978cbf9b63000ed5f798d532f9b7 /base
parentb1bb86d4d58f736fb980b8611ccf43d79e7b5b2b (diff)
downloadchromium_src-d323a176fa8c2ef474ce41dd8a1cddacb4fc67ff.zip
chromium_src-d323a176fa8c2ef474ce41dd8a1cddacb4fc67ff.tar.gz
chromium_src-d323a176fa8c2ef474ce41dd8a1cddacb4fc67ff.tar.bz2
Update base/timer.h code to pass through Location from call sites. (reland) original CL w/LGTMs: http://codereview.chromium.org/7812036/
Review URL: http://codereview.chromium.org/7824041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/system_monitor/system_monitor.cc2
-rw-r--r--base/timer.cc2
-rw-r--r--base/timer.h34
-rw-r--r--base/timer_unittest.cc18
4 files changed, 36 insertions, 20 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc
index 7b1349c..2631789 100644
--- a/base/system_monitor/system_monitor.cc
+++ b/base/system_monitor/system_monitor.cc
@@ -27,7 +27,7 @@ SystemMonitor::SystemMonitor()
DCHECK(MessageLoop::current());
#if defined(ENABLE_BATTERY_MONITORING)
- delayed_battery_check_.Start(
+ delayed_battery_check_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
&SystemMonitor::BatteryCheck);
#endif // defined(ENABLE_BATTERY_MONITORING)
diff --git a/base/timer.cc b/base/timer.cc
index ce5fab6..8c06693 100644
--- a/base/timer.cc
+++ b/base/timer.cc
@@ -21,7 +21,7 @@ void BaseTimer_Helper::InitiateDelayedTask(TimerTask* timer_task) {
delayed_task_ = timer_task;
delayed_task_->timer_ = this;
MessageLoop::current()->PostDelayedTask(
- FROM_HERE, timer_task,
+ timer_task->posted_from_, timer_task,
static_cast<int>(timer_task->delay_.InMillisecondsRoundedUp()));
}
diff --git a/base/timer.h b/base/timer.h
index 2e21582..30cb109 100644
--- a/base/timer.h
+++ b/base/timer.h
@@ -87,9 +87,14 @@ class BASE_EXPORT BaseTimer_Helper {
// We have access to the timer_ member so we can orphan this task.
class TimerTask : public Task {
public:
- explicit TimerTask(TimeDelta delay) : timer_(NULL), delay_(delay) {
+ TimerTask(const tracked_objects::Location& posted_from,
+ TimeDelta delay)
+ : posted_from_(posted_from),
+ timer_(NULL),
+ delay_(delay) {
}
virtual ~TimerTask() {}
+ tracked_objects::Location posted_from_;
BaseTimer_Helper* timer_;
TimeDelta delay_;
};
@@ -116,9 +121,12 @@ class BaseTimer : public BaseTimer_Helper {
// Call this method to start the timer. It is an error to call this method
// while the timer is already running.
- void Start(TimeDelta delay, Receiver* receiver, ReceiverMethod method) {
+ void Start(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ Receiver* receiver,
+ ReceiverMethod method) {
DCHECK(!IsRunning());
- InitiateDelayedTask(new TimerTask(delay, receiver, method));
+ InitiateDelayedTask(new TimerTask(posted_from, delay, receiver, method));
}
// Call this method to stop the timer. It is a no-op if the timer is not
@@ -138,8 +146,11 @@ class BaseTimer : public BaseTimer_Helper {
class TimerTask : public BaseTimer_Helper::TimerTask {
public:
- TimerTask(TimeDelta delay, Receiver* receiver, ReceiverMethod method)
- : BaseTimer_Helper::TimerTask(delay),
+ TimerTask(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ Receiver* receiver,
+ ReceiverMethod method)
+ : BaseTimer_Helper::TimerTask(posted_from, delay),
receiver_(receiver),
method_(method) {
}
@@ -162,7 +173,7 @@ class BaseTimer : public BaseTimer_Helper {
}
TimerTask* Clone() const {
- return new TimerTask(delay_, receiver_, method_);
+ return new TimerTask(posted_from_, delay_, receiver_, method_);
}
private:
@@ -221,8 +232,12 @@ class DelayTimer {
public:
typedef void (Receiver::*ReceiverMethod)();
- DelayTimer(TimeDelta delay, Receiver* receiver, ReceiverMethod method)
- : receiver_(receiver),
+ DelayTimer(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ Receiver* receiver,
+ ReceiverMethod method)
+ : posted_from_(posted_from),
+ receiver_(receiver),
method_(method),
delay_(delay) {
}
@@ -242,7 +257,7 @@ class DelayTimer {
// The timer isn't running, or will expire too late, so restart it.
timer_.Stop();
- timer_.Start(delay, this, &DelayTimer<Receiver>::Check);
+ timer_.Start(posted_from_, delay, this, &DelayTimer<Receiver>::Check);
}
void Check() {
@@ -259,6 +274,7 @@ class DelayTimer {
(receiver_->*method_)();
}
+ tracked_objects::Location posted_from_;
Receiver *const receiver_;
const ReceiverMethod method_;
const TimeDelta delay_;
diff --git a/base/timer_unittest.cc b/base/timer_unittest.cc
index bb0eade..0013bcc 100644
--- a/base/timer_unittest.cc
+++ b/base/timer_unittest.cc
@@ -19,7 +19,7 @@ class OneShotTimerTester {
delay_ms_(milliseconds) {
}
void Start() {
- timer_.Start(TimeDelta::FromMilliseconds(delay_ms_), this,
+ timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(delay_ms_), this,
&OneShotTimerTester::Run);
}
private:
@@ -39,7 +39,7 @@ class OneShotSelfDeletingTimerTester {
timer_(new base::OneShotTimer<OneShotSelfDeletingTimerTester>()) {
}
void Start() {
- timer_->Start(TimeDelta::FromMilliseconds(10), this,
+ timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this,
&OneShotSelfDeletingTimerTester::Run);
}
private:
@@ -59,7 +59,7 @@ class RepeatingTimerTester {
}
void Start() {
- timer_.Start(TimeDelta::FromMilliseconds(10), this,
+ timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this,
&RepeatingTimerTester::Run);
}
private:
@@ -176,7 +176,7 @@ void RunTest_DelayTimer_NoCall(MessageLoop::Type message_loop_type) {
// If Delay is never called, the timer shouldn't go off.
DelayTimerTarget target;
- base::DelayTimer<DelayTimerTarget> timer(
+ base::DelayTimer<DelayTimerTarget> timer(FROM_HERE,
TimeDelta::FromMilliseconds(1), &target, &DelayTimerTarget::Signal);
bool did_run = false;
@@ -191,7 +191,7 @@ void RunTest_DelayTimer_OneCall(MessageLoop::Type message_loop_type) {
MessageLoop loop(message_loop_type);
DelayTimerTarget target;
- base::DelayTimer<DelayTimerTarget> timer(
+ base::DelayTimer<DelayTimerTarget> timer(FROM_HERE,
TimeDelta::FromMilliseconds(1), &target, &DelayTimerTarget::Signal);
timer.Reset();
@@ -225,7 +225,7 @@ void RunTest_DelayTimer_Reset(MessageLoop::Type message_loop_type) {
// If Delay is never called, the timer shouldn't go off.
DelayTimerTarget target;
- base::DelayTimer<DelayTimerTarget> timer(
+ base::DelayTimer<DelayTimerTarget> timer(FROM_HERE,
TimeDelta::FromMilliseconds(50), &target, &DelayTimerTarget::Signal);
timer.Reset();
@@ -233,8 +233,8 @@ void RunTest_DelayTimer_Reset(MessageLoop::Type message_loop_type) {
base::OneShotTimer<ResetHelper> timers[20];
for (size_t i = 0; i < arraysize(timers); ++i) {
- timers[i].Start(TimeDelta::FromMilliseconds(i * 10), &reset_helper,
- &ResetHelper::Reset);
+ timers[i].Start(FROM_HERE, TimeDelta::FromMilliseconds(i * 10),
+ &reset_helper, &ResetHelper::Reset);
}
bool did_run = false;
@@ -260,7 +260,7 @@ void RunTest_DelayTimer_Deleted(MessageLoop::Type message_loop_type) {
{
base::DelayTimer<DelayTimerFatalTarget> timer(
- TimeDelta::FromMilliseconds(50), &target,
+ FROM_HERE, TimeDelta::FromMilliseconds(50), &target,
&DelayTimerFatalTarget::Signal);
timer.Reset();
}