Report Enum metrics from CertificateChecker.

The certificate checker was reporting a "user action" whenever an
update check HTTPS connection or HTTPS payload download had an invalid
HTTPS certificate or a valid one that was changed since the last
connection to the same server.

This patch sends an Enum metric for every HTTPS connection to check for
and update or download the payload with one of the three options: an
invalid certificate, a valid one already seen or a valid but different
certificate.

This patch also moves these metrics to the metrics.{h,cc} module, where
all the other metrics are reported, using an observer pattern in the
CertificateChecker, needed to remove the dependency on the metrics
library from the libpayload_consumer.

Bug: 25818567
TEST=FEATURES=test emerge-link update_engine; mma;

Change-Id: Ia1b6eb799e13b439b520ba14549d8973e18bcbfa
diff --git a/common/libcurl_http_fetcher.h b/common/libcurl_http_fetcher.h
index 52a4111..9e8abda 100644
--- a/common/libcurl_http_fetcher.h
+++ b/common/libcurl_http_fetcher.h
@@ -18,6 +18,7 @@
 #define UPDATE_ENGINE_COMMON_LIBCURL_HTTP_FETCHER_H_
 
 #include <map>
+#include <memory>
 #include <string>
 #include <utility>
 
@@ -32,7 +33,6 @@
 #include "update_engine/common/http_fetcher.h"
 #include "update_engine/system_state.h"
 
-
 // This is a concrete implementation of HttpFetcher that uses libcurl to do the
 // http work.
 
@@ -41,15 +41,10 @@
 class LibcurlHttpFetcher : public HttpFetcher {
  public:
   LibcurlHttpFetcher(ProxyResolver* proxy_resolver,
-                     SystemState* system_state)
-      : HttpFetcher(proxy_resolver, system_state) {
-    // Dev users want a longer timeout (180 seconds) because they may
-    // be waiting on the dev server to build an image.
-    if (!system_state->hardware()->IsOfficialBuild())
-      low_speed_time_seconds_ = kDownloadDevModeLowSpeedTimeSeconds;
-    if (!system_state_->hardware()->IsOOBEComplete(nullptr))
-      max_retry_count_ = kDownloadMaxRetryCountOobeNotComplete;
-  }
+                     SystemState* system_state,
+                     std::unique_ptr<CertificateChecker> certificate_checker);
+  LibcurlHttpFetcher(ProxyResolver* proxy_resolver, SystemState* system_state)
+      : LibcurlHttpFetcher(proxy_resolver, system_state, nullptr) {}
 
   // Cleans up all internal state. Does not notify delegate
   ~LibcurlHttpFetcher() override;
@@ -90,11 +85,6 @@
     no_network_max_retries_ = retries;
   }
 
-  void set_check_certificate(
-      CertificateChecker::ServerToCheck check_certificate) {
-    check_certificate_ = check_certificate;
-  }
-
   size_t GetBytesDownloaded() override {
     return static_cast<size_t>(bytes_downloaded_);
   }
@@ -180,6 +170,9 @@
   // written to |out_type|).
   bool GetProxyType(const std::string& proxy, curl_proxytype* out_type);
 
+  // Hardware interface used to query dev-mode and official build settings.
+  HardwareInterface* hardware_;
+
   // Handles for the libcurl library
   CURLM* curl_multi_handle_{nullptr};
   CURL* curl_handle_{nullptr};
@@ -238,11 +231,9 @@
   // if we get a terminate request, queue it until we can handle it.
   bool terminate_requested_{false};
 
-  // Represents which server certificate to be checked against this
-  // connection's certificate. If no certificate check needs to be performed,
-  // this should be kNone.
-  CertificateChecker::ServerToCheck check_certificate_{
-      CertificateChecker::kNone};
+  // The CertificateChecker used to check this connection's certificate. If no
+  // certificate check needs to be performed, this should be empty.
+  std::unique_ptr<CertificateChecker> certificate_checker_;
 
   int low_speed_limit_bps_{kDownloadLowSpeedLimitBps};
   int low_speed_time_seconds_{kDownloadLowSpeedTimeSeconds};