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

Unified Diff: chrome/browser/policy/cloud/rate_limiter.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/cloud/rate_limiter.h ('k') | chrome/browser/policy/cloud/rate_limiter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/cloud/rate_limiter.cc
diff --git a/chrome/browser/policy/cloud/rate_limiter.cc b/chrome/browser/policy/cloud/rate_limiter.cc
deleted file mode 100644
index b0992a61923b6d75f07b51280e9a305e5ad22f6e..0000000000000000000000000000000000000000
--- a/chrome/browser/policy/cloud/rate_limiter.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/policy/cloud/rate_limiter.h"
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/sequenced_task_runner.h"
-#include "base/time/tick_clock.h"
-
-namespace policy {
-
-RateLimiter::RateLimiter(size_t max_requests,
- const base::TimeDelta& duration,
- const base::Closure& callback,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- scoped_ptr<base::TickClock> clock)
- : max_requests_(max_requests),
- duration_(duration),
- callback_(callback),
- task_runner_(task_runner),
- clock_(clock.Pass()) {
- DCHECK_GT(max_requests_, 0u);
-}
-
-RateLimiter::~RateLimiter() {}
-
-void RateLimiter::PostRequest() {
- DCHECK(CalledOnValidThread());
-
- const base::TimeTicks now = clock_->NowTicks();
- const base::TimeTicks period_start = now - duration_;
- while (!invocation_times_.empty() &&
- invocation_times_.front() <= period_start) {
- invocation_times_.pop();
- }
-
- delayed_callback_.Cancel();
-
- if (invocation_times_.size() < max_requests_) {
- invocation_times_.push(now);
- callback_.Run();
- } else {
- // From the while() loop above we have front() > period_start,
- // so time_until_next_callback > 0.
- const base::TimeDelta time_until_next_callback =
- invocation_times_.front() - period_start;
- delayed_callback_.Reset(
- base::Bind(&RateLimiter::PostRequest, base::Unretained(this)));
- task_runner_->PostDelayedTask(
- FROM_HERE, delayed_callback_.callback(), time_until_next_callback);
- }
-}
-
-} // namespace policy
« no previous file with comments | « chrome/browser/policy/cloud/rate_limiter.h ('k') | chrome/browser/policy/cloud/rate_limiter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698