Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / host / backoff_timer.h
blob2750ebdda03800a67b339e2c59b5b15d06aee91e
1 // Copyright 2015 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 REMOTING_HOST_BACKOFF_TIMER_H_
6 #define REMOTING_HOST_BACKOFF_TIMER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/timer.h"
11 #include "net/base/backoff_entry.h"
13 namespace remoting {
15 // An object similar to a base::Timer with exponential backoff.
16 class BackoffTimer {
17 public:
18 BackoffTimer();
19 ~BackoffTimer();
21 // Invokes |user_task| at intervals specified by |delay|, and
22 // increasing up to |max_delay|. Always invokes |user_task| before
23 // the first scheduled delay.
24 void Start(const tracked_objects::Location& posted_from,
25 base::TimeDelta delay,
26 base::TimeDelta max_delay,
27 const base::Closure& user_task);
29 // Prevents the user task from being invoked again.
30 void Stop();
32 // Returns true if the user task may be invoked in the future.
33 bool IsRunning() const { return backoff_entry_; }
35 void SetTimerForTest(scoped_ptr<base::Timer> timer) { timer_ = timer.Pass(); }
37 private:
38 void StartTimer();
39 void OnTimerFired();
41 scoped_ptr<base::Timer> timer_;
42 base::Closure user_task_;
43 tracked_objects::Location posted_from_;
44 net::BackoffEntry::Policy backoff_policy_ = {};
45 scoped_ptr<net::BackoffEntry> backoff_entry_;
47 DISALLOW_COPY_AND_ASSIGN(BackoffTimer);
50 } // namespace remoting
52 #endif // REMOTING_HOST_BACKOFF_TIMER_H_