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

Unified Diff: components/policy/core/common/cloud/rate_limiter.cc

Issue 375933002: Remove cloud policy refresh rate limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months 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
Index: components/policy/core/common/cloud/rate_limiter.cc
diff --git a/components/policy/core/common/cloud/rate_limiter.cc b/components/policy/core/common/cloud/rate_limiter.cc
deleted file mode 100644
index 010d7d24af2b3801f7314e0b014ea571b05d897a..0000000000000000000000000000000000000000
--- a/components/policy/core/common/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 "components/policy/core/common/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 | « components/policy/core/common/cloud/rate_limiter.h ('k') | components/policy/core/common/cloud/rate_limiter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698