update_engine: ReceivedBytes returns boolean on transfer completion/termination

Currently, there are situations that a HttpFetcherDelegate.ReceivedBytes can
cause an eventual transfer completion or termination. This can eventually cause
the object (holding an instance) of HttpFetcherDelegate to be deallocated. So
there should not be any access to any member variable if the object is
deallocated. In this CL we add a return value to ReceivedBytes to indicate
explicitly that this situation happened so we can be careful about acceessing
member variables after a call to this.

BUG=chromium:868520
TEST=unittests

Change-Id: I18db33910f6171c4e426d9bbe604fa1ae07a56dc
Reviewed-on: https://chromium-review.googlesource.com/1158124
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/common/file_fetcher.cc b/common/file_fetcher.cc
index d0a109b..3836e54 100644
--- a/common/file_fetcher.cc
+++ b/common/file_fetcher.cc
@@ -138,8 +138,9 @@
       delegate_->TransferComplete(this, true);
   } else {
     bytes_copied_ += bytes_read;
-    if (delegate_)
-      delegate_->ReceivedBytes(this, buffer_.data(), bytes_read);
+    if (delegate_ &&
+        !delegate_->ReceivedBytes(this, buffer_.data(), bytes_read))
+      return;
     ScheduleRead();
   }
 }