Commit 29ebd775 authored by Nikita Podguzov's avatar Nikita Podguzov Committed by Commit Bot

Printing API: Introduce quotas for submitJob() and getPrinterInfo()

As far as these methods are computationally intensive we want to add
quotas for them.

Bug: 996785
Change-Id: I8573d39fa3d6388b97de08636a3997d51a768a5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007812Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Nikita Podguzov <nikitapodguzov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738154}
parent 32d207b9
...@@ -9,11 +9,22 @@ ...@@ -9,11 +9,22 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/extensions/printing/printing_api_handler.h" #include "chrome/browser/chromeos/extensions/printing/printing_api_handler.h"
#include "extensions/browser/quota_service.h"
namespace extensions { namespace extensions {
PrintingSubmitJobFunction::~PrintingSubmitJobFunction() = default; PrintingSubmitJobFunction::~PrintingSubmitJobFunction() = default;
void PrintingSubmitJobFunction::GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const {
QuotaLimitHeuristic::Config config = {
api::printing::MAX_SUBMIT_JOB_CALLS_PER_MINUTE,
base::TimeDelta::FromMinutes(1)};
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
config, std::make_unique<QuotaLimitHeuristic::SingletonBucketMapper>(),
"MAX_SUBMIT_JOB_CALLS_PER_MINUTE"));
}
ExtensionFunction::ResponseAction PrintingSubmitJobFunction::Run() { ExtensionFunction::ResponseAction PrintingSubmitJobFunction::Run() {
std::unique_ptr<api::printing::SubmitJob::Params> params( std::unique_ptr<api::printing::SubmitJob::Params> params(
api::printing::SubmitJob::Params::Create(*args_)); api::printing::SubmitJob::Params::Create(*args_));
...@@ -65,6 +76,16 @@ ExtensionFunction::ResponseAction PrintingGetPrintersFunction::Run() { ...@@ -65,6 +76,16 @@ ExtensionFunction::ResponseAction PrintingGetPrintersFunction::Run() {
PrintingGetPrinterInfoFunction::~PrintingGetPrinterInfoFunction() = default; PrintingGetPrinterInfoFunction::~PrintingGetPrinterInfoFunction() = default;
void PrintingGetPrinterInfoFunction::GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const {
QuotaLimitHeuristic::Config config = {
api::printing::MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE,
base::TimeDelta::FromMinutes(1)};
heuristics->push_back(std::make_unique<QuotaService::TimedLimit>(
config, std::make_unique<QuotaLimitHeuristic::SingletonBucketMapper>(),
"MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE"));
}
ExtensionFunction::ResponseAction PrintingGetPrinterInfoFunction::Run() { ExtensionFunction::ResponseAction PrintingGetPrinterInfoFunction::Run() {
std::unique_ptr<api::printing::GetPrinterInfo::Params> params( std::unique_ptr<api::printing::GetPrinterInfo::Params> params(
api::printing::GetPrinterInfo::Params::Create(*args_)); api::printing::GetPrinterInfo::Params::Create(*args_));
......
...@@ -24,6 +24,7 @@ class PrintingSubmitJobFunction : public ExtensionFunction { ...@@ -24,6 +24,7 @@ class PrintingSubmitJobFunction : public ExtensionFunction {
~PrintingSubmitJobFunction() override; ~PrintingSubmitJobFunction() override;
// ExtensionFunction: // ExtensionFunction:
void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override;
ResponseAction Run() override; ResponseAction Run() override;
private: private:
...@@ -61,6 +62,7 @@ class PrintingGetPrinterInfoFunction : public ExtensionFunction { ...@@ -61,6 +62,7 @@ class PrintingGetPrinterInfoFunction : public ExtensionFunction {
~PrintingGetPrinterInfoFunction() override; ~PrintingGetPrinterInfoFunction() override;
// ExtensionFunction: // ExtensionFunction:
void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override;
ResponseAction Run() override; ResponseAction Run() override;
private: private:
......
...@@ -168,6 +168,16 @@ namespace printing { ...@@ -168,6 +168,16 @@ namespace printing {
GetPrinterInfoCallback callback); GetPrinterInfoCallback callback);
}; };
interface Properties {
// The maximum number of times that $(ref:submitJob) can be called per
// minute.
[value=20] static long MAX_SUBMIT_JOB_CALLS_PER_MINUTE();
// The maximum number of times that $(ref:getPrinterInfo) can be called per
// minute.
[value=20] static long MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE();
};
interface Events { interface Events {
// Event fired when the status of the job is changed. // Event fired when the status of the job is changed.
// This is only fired for the jobs created by this extension. // This is only fired for the jobs created by this extension.
......
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