PolicyManager: EvaluationContext uses weak references for events.
When a timeout is scheduled a new reference to the EvaluationContext
was kept to be used while calling the OnTimeout() method on that
instance. This means that even if you remove all the external
references from objects that use the EvaluationContext, it will still
be alive until the timeout makes it release the reference.
This patch uses a weak reference for the internal callback, which
means that when the PolicyManager removes all its references to the
EvaluationContext, it is destroyed.
BUG=chromium:340871
TEST=Unit test added.
Change-Id: Icd25891ca5f59cde1e7872f5fc2d942dc234030e
Reviewed-on: https://chromium-review.googlesource.com/191078
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/evaluation_context.cc b/policy_manager/evaluation_context.cc
index c756ddf..90855ad 100644
--- a/policy_manager/evaluation_context.cc
+++ b/policy_manager/evaluation_context.cc
@@ -91,7 +91,8 @@
return false;
if (reeval_timeout_set) {
poll_timeout_event_ = RunFromMainLoopAfterTimeout(
- base::Bind(&EvaluationContext::OnPollTimeout, this), // refcounted.
+ base::Bind(&EvaluationContext::OnPollTimeout,
+ weak_ptr_factory_.GetWeakPtr()),
reeval_timeout);
}