• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_
7 
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"
13 
14 namespace content {
15 
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;
20 
21   explicit TimeoutMonitor(const TimeoutHandler& timeout_handler);
22   ~TimeoutMonitor();
23 
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);
28 
29   void Restart(base::TimeDelta delay);
30   void Stop();
31   bool IsRunning() const;
32 
33  private:
34   void CheckTimedOut();
35 
36   TimeoutHandler timeout_handler_;
37 
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_;
41 
42   // This timer runs to check if |time_when_considered_timed_out_| has past.
43   base::OneShotTimer<TimeoutMonitor> timeout_timer_;
44 
45   DISALLOW_COPY_AND_ASSIGN(TimeoutMonitor);
46 };
47 
48 }  // namespace content
49 
50 #endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_TIMEOUT_MONITOR_H_
51