Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / timeout_monitor.h
blob9c0729f2c76093f507a898432a02dd88d88b46b9
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"
14 namespace content {
16 // Utility class for handling a timeout callback with periodic starts and stops.
17 class CONTENT_EXPORT TimeoutMonitor {
18 public:
19 typedef base::Closure TimeoutHandler;
21 explicit TimeoutMonitor(const TimeoutHandler& timeout_handler);
22 ~TimeoutMonitor();
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);
30 void Stop();
31 bool IsRunning() const;
33 private:
34 void StartImpl(base::TimeDelta delay);
35 void CheckTimedOut();
37 TimeoutHandler timeout_handler_;
39 // Indicates a time in the future when we would consider the input as
40 // having timed out, if it does not receive an appropriate stop request.
41 base::TimeTicks time_when_considered_timed_out_;
43 // This timer runs to check if |time_when_considered_timed_out_| has past.
44 base::OneShotTimer<TimeoutMonitor> timeout_timer_;
46 DISALLOW_COPY_AND_ASSIGN(TimeoutMonitor);
49 } // namespace content
51 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_