update_engine: add logs and metrics for libcurl errors

curl_multi_perform may return code that is neither CURLM_OK or
CURLM_CALL_MULTI_PERFORM. When error returns we log them in
update_engine.log and send UMA metrics.

When update_engine does not get http response code from libcurl, we log
internal error code of the libcurl transfer for diagnosis.

Chrome CL to add the metrics enum is here: https://chromium-review.googlesource.com/c/chromium/src/+/1566150

BUG=chromium:927039
TEST=unittest

Change-Id: Ie8ce9dc0a6ce5ff6ffc2ff9425b652d125518558
Reviewed-on: https://chromium-review.googlesource.com/1562172
Commit-Ready: Sean Abraham <[email protected]>
Tested-by: Xiaochu Liu <[email protected]>
Reviewed-by: Xiaochu Liu <[email protected]>
Reviewed-by: Amin Hassani <[email protected]>
diff --git a/libcurl_http_fetcher.h b/libcurl_http_fetcher.h
index 25a2df3..24103de 100644
--- a/libcurl_http_fetcher.h
+++ b/libcurl_http_fetcher.h
@@ -106,6 +106,10 @@
     max_retry_count_ = max_retry_count;
   }
 
+  void set_is_update_check(bool is_update_check) {
+    is_update_check_ = is_update_check;
+  }
+
  private:
   // libcurl's CURLOPT_CLOSESOCKETFUNCTION callback function. Called when
   // closing a socket created with the CURLOPT_OPENSOCKETFUNCTION callback.
@@ -118,6 +122,11 @@
   // Asks libcurl for the http response code and stores it in the object.
   void GetHttpResponseCode();
 
+  // Logs curl handle info.
+  // This can be called only when an http request failed to avoid spamming the
+  // logs. This must be called after |ResumeTransfer| and before |CleanUp|.
+  void LogCurlHandleInfo();
+
   // Checks whether stored HTTP response is within the success range.
   inline bool IsHttpResponseSuccess() {
     return (http_response_code_ >= 200 && http_response_code_ < 300);
@@ -265,6 +274,9 @@
   // ServerToCheck::kNone.
   ServerToCheck server_to_check_{ServerToCheck::kNone};
 
+  // True if this object is for update check.
+  bool is_update_check_{false};
+
   int low_speed_limit_bps_{kDownloadLowSpeedLimitBps};
   int low_speed_time_seconds_{kDownloadLowSpeedTimeSeconds};
   int connect_timeout_seconds_{kDownloadConnectTimeoutSeconds};