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
tree: 9c8bdb818183e518b4511ff4ba026925385501f7
  1. init/
  2. policy_manager/
  3. .gitignore
  4. 99-gpio-dutflag.rules
  5. action.h
  6. action_mock.h
  7. action_pipe.h
  8. action_pipe_unittest.cc
  9. action_processor.cc
  10. action_processor.h
  11. action_processor_mock.h
  12. action_processor_unittest.cc
  13. action_unittest.cc
  14. build
  15. bzip.cc
  16. bzip.h
  17. bzip_extent_writer.cc
  18. bzip_extent_writer.h
  19. bzip_extent_writer_unittest.cc
  20. certificate_checker.cc
  21. certificate_checker.h
  22. certificate_checker_mock.h
  23. certificate_checker_unittest.cc
  24. chrome_browser_proxy_resolver.cc
  25. chrome_browser_proxy_resolver.h
  26. chrome_browser_proxy_resolver_unittest.cc
  27. clock.cc
  28. clock.h
  29. clock_interface.h
  30. connection_manager.cc
  31. connection_manager.h
  32. connection_manager_unittest.cc
  33. constants.cc
  34. constants.h
  35. cycle_breaker.cc
  36. cycle_breaker.h
  37. cycle_breaker_unittest.cc
  38. dbus_constants.h
  39. dbus_service.cc
  40. dbus_service.h
  41. dbus_wrapper_interface.h
  42. delta_diff_generator.cc
  43. delta_diff_generator.h
  44. delta_diff_generator_unittest.cc
  45. delta_performer.cc
  46. delta_performer.h
  47. delta_performer_unittest.cc
  48. download_action.cc
  49. download_action.h
  50. download_action_unittest.cc
  51. error_code.h
  52. extent_mapper.cc
  53. extent_mapper.h
  54. extent_mapper_unittest.cc
  55. extent_ranges.cc
  56. extent_ranges.h
  57. extent_ranges_unittest.cc
  58. extent_writer.cc
  59. extent_writer.h
  60. extent_writer_unittest.cc
  61. fake_clock.h
  62. fake_hardware.h
  63. fake_p2p_manager.h
  64. fake_p2p_manager_configuration.h
  65. fake_prefs.cc
  66. fake_prefs.h
  67. fake_system_state.cc
  68. fake_system_state.h
  69. file_descriptor.cc
  70. file_descriptor.h
  71. file_writer.cc
  72. file_writer.h
  73. file_writer_mock.h
  74. file_writer_unittest.cc
  75. filesystem_copier_action.cc
  76. filesystem_copier_action.h
  77. filesystem_copier_action_unittest.cc
  78. filesystem_iterator.cc
  79. filesystem_iterator.h
  80. filesystem_iterator_unittest.cc
  81. full_update_generator.cc
  82. full_update_generator.h
  83. full_update_generator_unittest.cc
  84. gen_coverage_html
  85. generate_delta_main.cc
  86. gpio_handler.cc
  87. gpio_handler.h
  88. gpio_handler_unittest.cc
  89. gpio_handler_unittest.h
  90. gpio_mock_file_descriptor.cc
  91. gpio_mock_file_descriptor.h
  92. gpio_mock_udev_interface.cc
  93. gpio_mock_udev_interface.h
  94. graph_types.h
  95. graph_utils.cc
  96. graph_utils.h
  97. graph_utils_unittest.cc
  98. hardware.cc
  99. hardware.h
  100. hardware_interface.h
  101. http_common.cc
  102. http_common.h
  103. http_fetcher.cc
  104. http_fetcher.h
  105. http_fetcher_unittest.cc
  106. hwid_override.cc
  107. hwid_override.h
  108. hwid_override_unittest.cc
  109. inherit-review-settings-ok
  110. install_plan.cc
  111. install_plan.h
  112. libcurl_http_fetcher.cc
  113. libcurl_http_fetcher.h
  114. LICENSE
  115. local_coverage_rate
  116. main.cc
  117. metadata.cc
  118. metadata.h
  119. metadata_unittest.cc
  120. metrics.cc
  121. metrics.h
  122. mock_connection_manager.h
  123. mock_dbus_wrapper.h
  124. mock_file_writer.h
  125. mock_gpio_handler.h
  126. mock_hardware.h
  127. mock_http_fetcher.cc
  128. mock_http_fetcher.h
  129. mock_p2p_manager.h
  130. mock_payload_state.h
  131. multi_range_http_fetcher.cc
  132. multi_range_http_fetcher.h
  133. omaha_hash_calculator.cc
  134. omaha_hash_calculator.h
  135. omaha_hash_calculator_unittest.cc
  136. omaha_request_action.cc
  137. omaha_request_action.h
  138. omaha_request_action_unittest.cc
  139. omaha_request_params.cc
  140. omaha_request_params.h
  141. omaha_request_params_unittest.cc
  142. omaha_response.h
  143. omaha_response_handler_action.cc
  144. omaha_response_handler_action.h
  145. omaha_response_handler_action_unittest.cc
  146. p2p_manager.cc
  147. p2p_manager.h
  148. p2p_manager_unittest.cc
  149. payload_signer.cc
  150. payload_signer.h
  151. payload_signer_unittest.cc
  152. payload_state.cc
  153. payload_state.h
  154. payload_state_interface.h
  155. payload_state_unittest.cc
  156. postinstall_runner_action.cc
  157. postinstall_runner_action.h
  158. postinstall_runner_action_unittest.cc
  159. prefs.cc
  160. prefs.h
  161. prefs_interface.h
  162. prefs_mock.h
  163. prefs_unittest.cc
  164. proxy_resolver.cc
  165. proxy_resolver.h
  166. real_dbus_wrapper.h
  167. real_system_state.cc
  168. real_system_state.h
  169. run_unittests
  170. sample_omaha_v3_response.xml
  171. SConstruct
  172. simple_key_value_store.cc
  173. simple_key_value_store.h
  174. simple_key_value_store_unittest.cc
  175. subprocess.cc
  176. subprocess.h
  177. subprocess_unittest.cc
  178. system_state.h
  179. tarjan.cc
  180. tarjan.h
  181. tarjan_unittest.cc
  182. terminator.cc
  183. terminator.h
  184. terminator_unittest.cc
  185. test_http_server.cc
  186. test_utils.cc
  187. test_utils.h
  188. testrunner.cc
  189. topological_sort.cc
  190. topological_sort.h
  191. topological_sort_unittest.cc
  192. udev_interface.h
  193. unittest_key.pem
  194. unittest_key2.pem
  195. update_attempter.cc
  196. update_attempter.h
  197. update_attempter_mock.h
  198. update_attempter_unittest.cc
  199. update_check_scheduler.cc
  200. update_check_scheduler.h
  201. update_check_scheduler_unittest.cc
  202. update_engine.xml
  203. update_engine_client.cc
  204. update_metadata.proto
  205. UpdateEngine.conf
  206. utils.cc
  207. utils.h
  208. utils_unittest.cc
  209. WATCHLISTS
  210. zip_unittest.cc