1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "content/common/content_export.h"
16 // Utility class for handling a timeout callback with periodic starts and stops.
17 class CONTENT_EXPORT TimeoutMonitor
{
19 typedef base::Closure TimeoutHandler
;
21 explicit TimeoutMonitor(const TimeoutHandler
& timeout_handler
);
24 // Schedule the timeout timer to fire at |delay| into the future. If a timeout
25 // has already been scheduled, reschedule only if |delay| is sooner than the
26 // currently scheduled timeout time.
27 void Start(base::TimeDelta delay
);
29 void Restart(base::TimeDelta delay
);
31 bool IsRunning() const;
36 TimeoutHandler timeout_handler_
;
38 // Indicates a time in the future when we would consider the input as
39 // having timed out, if it does not receive an appropriate stop request.
40 base::Time time_when_considered_timed_out_
;
42 // This timer runs to check if |time_when_considered_timed_out_| has past.
43 base::OneShotTimer
<TimeoutMonitor
> timeout_timer_
;
45 DISALLOW_COPY_AND_ASSIGN(TimeoutMonitor
);
48 } // namespace content
50 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_