PolicyManager: Don't schedule a callback when there are no observers.
BaseVariable::NotifyValueChanged() will schedule a callback to call
all the observers on that variable from the same call. This prevents
a corner case where the observer removes itself and is detroyed
between the NotifyValueChanged() and the callback while it doesn't
fire all observers from the same context that called
NotifyValueChanged(). Nevertheless, this callback interferes with
the unittest code where Variables are created and removed all the
time, and the scheduled callback could remain on the main loop until
other unittest runs it.
This patch only schedules the callback to the BaseVariable if there
is any observer waiting for it, which helps to reduce this
uninteresting callbacks during testing.
BUG=chromium:358326
TEST=Unit test still pass.
Change-Id: I4f86d7eaf956afeebee91d27a80b9e3061bc56fb
Reviewed-on: https://chromium-review.googlesource.com/195447
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
1 file changed