Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: components/policy/core/common/cloud/rate_limiter.h

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_RATE_LIMITER_H_ 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_RATE_LIMITER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_RATE_LIMITER_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_RATE_LIMITER_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/cancelable_callback.h" 12 #include "base/cancelable_callback.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/policy/policy_export.h"
17 18
18 namespace base { 19 namespace base {
19 class SequencedTaskRunner; 20 class SequencedTaskRunner;
20 class TickClock; 21 class TickClock;
21 } 22 }
22 23
23 namespace policy { 24 namespace policy {
24 25
25 // A simple class to limit the rate at which a callback is invoked. 26 // A simple class to limit the rate at which a callback is invoked.
26 class RateLimiter : public base::NonThreadSafe { 27 class POLICY_EXPORT RateLimiter : public base::NonThreadSafe {
27 public: 28 public:
28 // Will limit invocations of |callback| to |max_requests| per |duration|. 29 // Will limit invocations of |callback| to |max_requests| per |duration|.
29 // |task_runner| is used to post delayed tasks, and |clock| is used to 30 // |task_runner| is used to post delayed tasks, and |clock| is used to
30 // measure elapsed time. 31 // measure elapsed time.
31 RateLimiter(size_t max_requests, 32 RateLimiter(size_t max_requests,
32 const base::TimeDelta& duration, 33 const base::TimeDelta& duration,
33 const base::Closure& callback, 34 const base::Closure& callback,
34 scoped_refptr<base::SequencedTaskRunner> task_runner, 35 scoped_refptr<base::SequencedTaskRunner> task_runner,
35 scoped_ptr<base::TickClock> clock); 36 scoped_ptr<base::TickClock> clock);
36 ~RateLimiter(); 37 ~RateLimiter();
(...skipping 12 matching lines...) Expand all
49 scoped_ptr<base::TickClock> clock_; 50 scoped_ptr<base::TickClock> clock_;
50 51
51 std::queue<base::TimeTicks> invocation_times_; 52 std::queue<base::TimeTicks> invocation_times_;
52 base::CancelableClosure delayed_callback_; 53 base::CancelableClosure delayed_callback_;
53 54
54 DISALLOW_COPY_AND_ASSIGN(RateLimiter); 55 DISALLOW_COPY_AND_ASSIGN(RateLimiter);
55 }; 56 };
56 57
57 } // namespace policy 58 } // namespace policy
58 59
59 #endif // CHROME_BROWSER_POLICY_CLOUD_RATE_LIMITER_H_ 60 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_RATE_LIMITER_H_
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/policy_builder.cc ('k') | components/policy/core/common/cloud/rate_limiter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698