Commit 4e854f7e authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Cleanup] Use unique_ptr in QuotaService

Instead of passing BucketMapper as a raw pointer and then taking
ownership by wrapping it in a unique_ptr, pass it in as a unique_ptr
directly.

Bug: None
Change-Id: I3357fe432651c9dcd7884d6f6d7e76040c70d806
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015631Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734591}
parent 53fe7332
......@@ -316,14 +316,16 @@ void CertificateProviderRequestPinFunction::GetQuotaLimitHeuristics(
api::certificate_provider::kMaxClosedDialogsPerMinute - 1,
base::TimeDelta::FromMinutes(1)};
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
short_limit_config, new RequestPinExceptFirstQuotaBucketMapper,
short_limit_config,
std::make_unique<RequestPinExceptFirstQuotaBucketMapper>(),
"MAX_PIN_DIALOGS_CLOSED_PER_MINUTE"));
QuotaLimitHeuristic::Config long_limit_config = {
api::certificate_provider::kMaxClosedDialogsPer10Minutes - 1,
base::TimeDelta::FromMinutes(10)};
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
long_limit_config, new RequestPinExceptFirstQuotaBucketMapper,
long_limit_config,
std::make_unique<RequestPinExceptFirstQuotaBucketMapper>(),
"MAX_PIN_DIALOGS_CLOSED_PER_10_MINUTES"));
}
......
......@@ -141,10 +141,12 @@ void GetModificationQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) {
api::storage::sync::MAX_WRITE_OPERATIONS_PER_HOUR,
base::TimeDelta::FromHours(1)};
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
short_limit_config, new QuotaLimitHeuristic::SingletonBucketMapper(),
short_limit_config,
std::make_unique<QuotaLimitHeuristic::SingletonBucketMapper>(),
"MAX_WRITE_OPERATIONS_PER_MINUTE"));
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
long_limit_config, new QuotaLimitHeuristic::SingletonBucketMapper(),
long_limit_config,
std::make_unique<QuotaLimitHeuristic::SingletonBucketMapper>(),
"MAX_WRITE_OPERATIONS_PER_HOUR"));
}
......
......@@ -2563,10 +2563,11 @@ void ExtensionWebRequestEventRouter::ClearSignaled(uint64_t request_id,
// when the cache is cleared (when page loads happen).
class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic {
public:
ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map)
ClearCacheQuotaHeuristic(const Config& config,
std::unique_ptr<BucketMapper> map)
: QuotaLimitHeuristic(
config,
map,
std::move(map),
"MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"),
callback_registered_(false) {}
~ClearCacheQuotaHeuristic() override {}
......@@ -2867,10 +2868,8 @@ void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics(
// See web_request.json for current value.
web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES,
base::TimeDelta::FromMinutes(10)};
QuotaLimitHeuristic::BucketMapper* bucket_mapper =
new QuotaLimitHeuristic::SingletonBucketMapper();
heuristics->push_back(
std::make_unique<ClearCacheQuotaHeuristic>(config, bucket_mapper));
heuristics->push_back(std::make_unique<ClearCacheQuotaHeuristic>(
config, std::make_unique<QuotaLimitHeuristic::SingletonBucketMapper>()));
}
void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded(
......
......@@ -106,9 +106,9 @@ void QuotaLimitHeuristic::SingletonBucketMapper::GetBucketsForArgs(
}
QuotaLimitHeuristic::QuotaLimitHeuristic(const Config& config,
BucketMapper* map,
std::unique_ptr<BucketMapper> map,
const std::string& name)
: config_(config), bucket_mapper_(map), name_(name) {}
: config_(config), bucket_mapper_(std::move(map)), name_(name) {}
QuotaLimitHeuristic::~QuotaLimitHeuristic() {}
......
......@@ -21,7 +21,6 @@
#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
......@@ -174,9 +173,8 @@ class QuotaLimitHeuristic {
DISALLOW_COPY_AND_ASSIGN(SingletonBucketMapper);
};
// Ownership of |map| is given to the new QuotaLimitHeuristic.
QuotaLimitHeuristic(const Config& config,
BucketMapper* map,
std::unique_ptr<BucketMapper> map,
const std::string& name);
virtual ~QuotaLimitHeuristic();
......@@ -202,7 +200,7 @@ class QuotaLimitHeuristic {
const Config config_;
// The mapper used in Map. Cannot be NULL.
// The mapper used in Map. Cannot be null.
std::unique_ptr<BucketMapper> bucket_mapper_;
// The name of the heuristic for formatting error messages.
......@@ -215,8 +213,10 @@ class QuotaLimitHeuristic {
// a given period of time; e.g "no more than 100 events in an hour".
class QuotaService::TimedLimit : public QuotaLimitHeuristic {
public:
TimedLimit(const Config& config, BucketMapper* map, const std::string& name)
: QuotaLimitHeuristic(config, map, name) {}
TimedLimit(const Config& config,
std::unique_ptr<BucketMapper> map,
const std::string& name)
: QuotaLimitHeuristic(config, std::move(map), name) {}
bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override;
};
......
......@@ -72,8 +72,8 @@ class TimedLimitMockFunction : public MockFunction {
explicit TimedLimitMockFunction(const char* name) : MockFunction(name) {}
void GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const override {
heuristics->push_back(
std::make_unique<TimedLimit>(k2PerMinute, new Mapper(), kGenericName));
heuristics->push_back(std::make_unique<TimedLimit>(
k2PerMinute, std::make_unique<Mapper>(), kGenericName));
}
private:
......@@ -86,7 +86,7 @@ class FrozenMockFunction : public MockFunction {
void GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const override {
heuristics->push_back(std::make_unique<TimedLimit>(
kFrozenConfig, new Mapper(), kGenericName));
kFrozenConfig, std::make_unique<Mapper>(), kGenericName));
}
private:
......@@ -140,7 +140,7 @@ class QuotaLimitHeuristicTest : public testing::Test {
};
TEST_F(QuotaLimitHeuristicTest, Timed) {
TimedLimit lim(k2PerMinute, new MockMapper(), kGenericName);
TimedLimit lim(k2PerMinute, std::make_unique<MockMapper>(), kGenericName);
Bucket b;
b.Reset(k2PerMinute, kStartTime);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment