Commit 40fbb25a authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Convert DeclarativeRule to OnceCallback

The ConsistencyChecker callback is only ever invoked from
DeclarativeRule::Create and never stored so this should be a
OnceCallback.

Bug: 1152268
Change-Id: I6148ce40bc0a04d25e5ab9c936fd8f83fa7e5b83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593936Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837596}
parent de2c3629
......@@ -209,9 +209,10 @@ class DeclarativeRule {
// Checks whether the set of |conditions| and |actions| are consistent.
// Returns true in case of consistency and MUST set |error| otherwise.
using ConsistencyChecker = base::Callback<bool(const ConditionSet* conditions,
const ActionSet* actions,
std::string* error)>;
using ConsistencyChecker =
base::OnceCallback<bool(const ConditionSet* conditions,
const ActionSet* actions,
std::string* error)>;
DeclarativeRule(const GlobalRuleId& id,
const Tags& tags,
......@@ -472,7 +473,8 @@ DeclarativeRule<ConditionT, ActionT>::Create(
CHECK(actions.get());
if (!check_consistency.is_null() &&
!check_consistency.Run(conditions.get(), actions.get(), error)) {
!std::move(check_consistency)
.Run(conditions.get(), actions.get(), error)) {
DCHECK(!error->empty());
return std::move(error_result);
}
......
......@@ -394,7 +394,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
&json_rule));
std::unique_ptr<Rule> rule(Rule::Create(
matcher.condition_factory(), nullptr, extension.get(), base::Time(),
json_rule, base::Bind(AtLeastOneCondition), &error));
json_rule, base::BindOnce(AtLeastOneCondition), &error));
EXPECT_TRUE(rule);
EXPECT_EQ("", error);
......@@ -411,8 +411,8 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
})"),
&json_rule));
rule = Rule::Create(matcher.condition_factory(), nullptr, extension.get(),
base::Time(), json_rule, base::Bind(AtLeastOneCondition),
&error);
base::Time(), json_rule,
base::BindOnce(AtLeastOneCondition), &error);
EXPECT_FALSE(rule);
EXPECT_EQ("No conditions", error);
}
......
......@@ -164,7 +164,7 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
std::unique_ptr<WebRequestRule> webrequest_rule = WebRequestRule::Create(
url_matcher_.condition_factory(), browser_context(), extension,
extension_installation_time, *rule,
base::Bind(&Checker, base::Unretained(extension)), &error);
base::BindOnce(&Checker, base::Unretained(extension)), &error);
if (!error.empty()) {
// We don't return here, because we want to clear temporary
// condition sets in the url_matcher_.
......
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