AU: Fix potential issues with premature destruction of HTTP fetchers.

This patch adds a new TransferTerminated callback to the
HttpFetcher class. It fixes two potential memory corruption
issues with premature destruction of HttpFetcher instances:

1. When MultiHttpFetcher completes a range, it terminates
the current fetcher and starts the next one, if any. Change
so that the next fetcher is started when the
TransferTerminated callback is received from the current
fetcher. This prevents the multi fetcher from sending a
TransferComplete/TransferTerminated callbacks before the
underlying fetcher is cleaned up, which may lead to the
fetchers being destroyed prematurely.

2. If the download action fails due to a failed write,
terminate the transfer and then wait for the transfer
terminated callback before notifying the action processor
that the action is complete. Otherwise, the action may get
destroyed before the transfer is actually terminated
possibly leading to memory corruption, etc.

Hopefully these changes fix crosbug.com/8798.

BUG=8798
TEST=unit tests, tested on device with write errors

Change-Id: If416b95625ab31662f2e1308df6bdd1757a2ad78

Review URL: http://codereview.chromium.org/5009009
9 files changed
tree: c20e9407270739c597b4846fa594f47668aed019
  1. certs/
  2. .gitignore
  3. action.h
  4. action_mock.h
  5. action_pipe.h
  6. action_pipe_unittest.cc
  7. action_processor.cc
  8. action_processor.h
  9. action_processor_mock.h
  10. action_processor_unittest.cc
  11. action_unittest.cc
  12. buffered_file_writer.cc
  13. buffered_file_writer.h
  14. buffered_file_writer_unittest.cc
  15. bzip.cc
  16. bzip.h
  17. bzip_extent_writer.cc
  18. bzip_extent_writer.h
  19. bzip_extent_writer_unittest.cc
  20. cycle_breaker.cc
  21. cycle_breaker.h
  22. cycle_breaker_unittest.cc
  23. dbus_constants.h
  24. dbus_interface.h
  25. dbus_service.cc
  26. dbus_service.h
  27. decompressing_file_writer.cc
  28. decompressing_file_writer.h
  29. decompressing_file_writer_unittest.cc
  30. delta_diff_generator.cc
  31. delta_diff_generator.h
  32. delta_diff_generator_unittest.cc
  33. delta_performer.cc
  34. delta_performer.h
  35. delta_performer_unittest.cc
  36. download_action.cc
  37. download_action.h
  38. download_action_unittest.cc
  39. extent_mapper.cc
  40. extent_mapper.h
  41. extent_mapper_unittest.cc
  42. extent_ranges.cc
  43. extent_ranges.h
  44. extent_ranges_unittest.cc
  45. extent_writer.cc
  46. extent_writer.h
  47. extent_writer_unittest.cc
  48. file_writer.cc
  49. file_writer.h
  50. file_writer_mock.h
  51. file_writer_unittest.cc
  52. filesystem_copier_action.cc
  53. filesystem_copier_action.h
  54. filesystem_copier_action_unittest.cc
  55. filesystem_iterator.cc
  56. filesystem_iterator.h
  57. filesystem_iterator_unittest.cc
  58. flimflam_proxy.cc
  59. flimflam_proxy.h
  60. flimflam_proxy_unittest.cc
  61. full_update_generator.cc
  62. full_update_generator.h
  63. full_update_generator_unittest.cc
  64. gen_coverage_html.sh
  65. generate_delta_main.cc
  66. graph_types.h
  67. graph_utils.cc
  68. graph_utils.h
  69. graph_utils_unittest.cc
  70. gzip.cc
  71. gzip.h
  72. http_fetcher.h
  73. http_fetcher_unittest.cc
  74. inherit-review-settings-ok
  75. install_plan.h
  76. integration_unittest.cc
  77. libcurl_http_fetcher.cc
  78. libcurl_http_fetcher.h
  79. LICENSE
  80. local_coverage_rate.sh
  81. main.cc
  82. marshal.list
  83. mock_dbus_interface.h
  84. mock_file_writer.h
  85. mock_http_fetcher.cc
  86. mock_http_fetcher.h
  87. multi_http_fetcher.h
  88. omaha_hash_calculator.cc
  89. omaha_hash_calculator.h
  90. omaha_hash_calculator_unittest.cc
  91. omaha_request_action.cc
  92. omaha_request_action.h
  93. omaha_request_action_unittest.cc
  94. omaha_request_params.cc
  95. omaha_request_params.h
  96. omaha_request_params_unittest.cc
  97. omaha_response_handler_action.cc
  98. omaha_response_handler_action.h
  99. omaha_response_handler_action_unittest.cc
  100. org.chromium.UpdateEngine.service
  101. payload_signer.cc
  102. payload_signer.h
  103. payload_signer_unittest.cc
  104. postinstall_runner_action.cc
  105. postinstall_runner_action.h
  106. postinstall_runner_action_unittest.cc
  107. prefs.cc
  108. prefs.h
  109. prefs_interface.h
  110. prefs_mock.h
  111. prefs_unittest.cc
  112. SConstruct
  113. setup_dev_packages
  114. simple_key_value_store.cc
  115. simple_key_value_store.h
  116. simple_key_value_store_unittest.cc
  117. split_file_writer.cc
  118. split_file_writer.h
  119. split_file_writer_unittest.cc
  120. subprocess.cc
  121. subprocess.h
  122. subprocess_unittest.cc
  123. tarjan.cc
  124. tarjan.h
  125. tarjan_unittest.cc
  126. terminator.cc
  127. terminator.h
  128. test_http_server.cc
  129. test_utils.cc
  130. test_utils.h
  131. testrunner.cc
  132. topological_sort.cc
  133. topological_sort.h
  134. topological_sort_unittest.cc
  135. unittest_key.pem
  136. update_attempter.cc
  137. update_attempter.h
  138. update_attempter_mock.h
  139. update_attempter_unittest.cc
  140. update_check_scheduler.cc
  141. update_check_scheduler.h
  142. update_check_scheduler_unittest.cc
  143. update_engine.xml
  144. update_engine_client.cc
  145. update_metadata.proto
  146. UpdateEngine.conf
  147. utils.cc
  148. utils.h
  149. utils_unittest.cc
  150. WATCHLISTS
  151. zip_unittest.cc