PolicyManager: Specify the full Policy method type on the PM interface.
This patch replaces the template parameter "typename T" used to pass
the policy_method with its actual type, which can be inferred from
the remaining types, removing this template parameter.
This makes the C++ error messages more meaningful when the wrong
parameters are passed to a policy request.
BUG=None
TEST=Build. Manual test passing the wrong type for "result" and getting a meaningful error message.
Change-Id: I98cda8782a0db8642f1e6636af286a97a2df56a3
Reviewed-on: https://chromium-review.googlesource.com/193675
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/policy_manager.h b/policy_manager/policy_manager.h
index 5b89bf2..d874e9c 100644
--- a/policy_manager/policy_manager.h
+++ b/policy_manager/policy_manager.h
@@ -41,8 +41,14 @@
//
// An example call to this method is:
// pm.PolicyRequest(&Policy::SomePolicyMethod, &bool_result, arg1, arg2);
- template<typename T, typename R, typename... Args>
- EvalStatus PolicyRequest(T policy_method, R* result, Args... args);
+ template<typename R, typename... Args>
+ EvalStatus PolicyRequest(
+ EvalStatus (Policy::*policy_method)(EvaluationContext* ec,
+ State* state,
+ std::string* error,
+ R* result,
+ Args... args) const,
+ R* result, Args... args);
// Evaluates the given |policy_method| policy with the provided |args|
// arguments and calls the |callback| callback with the result when done.
@@ -52,10 +58,15 @@
// policy until another status is returned. If the policy implementation based
// its return value solely on const variables, the callback will be called
// with the EvalStatus::kAskMeAgainLater status.
- template<typename T, typename R, typename... Args>
+ template<typename R, typename... Args>
void AsyncPolicyRequest(
base::Callback<void(EvalStatus, const R& result)> callback,
- T policy_method, Args... args);
+ EvalStatus (Policy::*policy_method)(EvaluationContext* ec,
+ State* state,
+ std::string* error,
+ R* result,
+ Args... args) const,
+ Args... args);
protected:
// The PolicyManager receives ownership of the passed Policy instance.
@@ -73,10 +84,15 @@
// EvaluatePolicy() evaluates the passed |policy_method| method on the current
// policy with the given |args| arguments. If the method fails, the default
// policy is used instead.
- template<typename T, typename R, typename... Args>
- EvalStatus EvaluatePolicy(EvaluationContext* ec,
- T policy_method, R* result,
- Args... args);
+ template<typename R, typename... Args>
+ EvalStatus EvaluatePolicy(
+ EvaluationContext* ec,
+ EvalStatus (Policy::*policy_method)(EvaluationContext* ec,
+ State* state,
+ std::string* error,
+ R* result,
+ Args... args) const,
+ R* result, Args... args);
// OnPolicyReadyToEvaluate() is called by the main loop when the evaluation
// of the given |policy_method| should be executed. If the evaluation finishes
@@ -84,11 +100,16 @@
// returned by the policy. If the evaluation returns an
// EvalStatus::kAskMeAgainLater state, the |callback| will NOT be called and
// the evaluation will be re-scheduled to be called later.
- template<typename T, typename R, typename... Args>
+ template<typename R, typename... Args>
void OnPolicyReadyToEvaluate(
scoped_refptr<EvaluationContext> ec,
base::Callback<void(EvalStatus status, const R& result)> callback,
- T policy_method, Args... args);
+ EvalStatus (Policy::*policy_method)(EvaluationContext* ec,
+ State* state,
+ std::string* error,
+ R* result,
+ Args... args) const,
+ Args... args);
// The policy used by the PolicyManager. Note that since it is a const Policy,
// policy implementations are not allowed to persist state on this class.