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.cc b/common/libcurl_http_fetcher.cc
index d36e32b..5a248e6 100644
--- a/common/libcurl_http_fetcher.cc
+++ b/common/libcurl_http_fetcher.cc
@@ -29,6 +29,7 @@
#include "update_engine/common/certificate_checker.h"
#include "update_engine/common/hardware_interface.h"
#include "update_engine/common/platform_constants.h"
+#include "update_engine/system_state.h"
using base::TimeDelta;
using brillo::MessageLoop;
@@ -44,6 +45,21 @@
const int kNoNetworkRetrySeconds = 10;
} // namespace
+LibcurlHttpFetcher::LibcurlHttpFetcher(
+ ProxyResolver* proxy_resolver,
+ SystemState* system_state,
+ std::unique_ptr<CertificateChecker> certificate_checker)
+ : HttpFetcher(proxy_resolver),
+ hardware_(system_state->hardware()),
+ certificate_checker_(std::move(certificate_checker)) {
+ // Dev users want a longer timeout (180 seconds) because they may
+ // be waiting on the dev server to build an image.
+ if (!hardware_->IsOfficialBuild())
+ low_speed_time_seconds_ = kDownloadDevModeLowSpeedTimeSeconds;
+ if (!hardware_->IsOOBEComplete(nullptr))
+ max_retry_count_ = kDownloadMaxRetryCountOobeNotComplete;
+}
+
LibcurlHttpFetcher::~LibcurlHttpFetcher() {
LOG_IF(ERROR, transfer_in_progress_)
<< "Destroying the fetcher while a transfer is in progress.";
@@ -181,7 +197,7 @@
// Lock down the appropriate curl options for HTTP or HTTPS depending on
// the url.
- if (GetSystemState()->hardware()->IsOfficialBuild()) {
+ if (hardware_->IsOfficialBuild()) {
if (base::StartsWithASCII(url_, "http://", false))
SetCurlOptionsForHttp();
else
@@ -222,9 +238,9 @@
CURLE_OK);
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSL_CIPHER_LIST, "HIGH:!ADH"),
CURLE_OK);
- if (check_certificate_ != CertificateChecker::kNone) {
+ if (certificate_checker_ != nullptr) {
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSL_CTX_DATA,
- &check_certificate_),
+ certificate_checker_.get()),
CURLE_OK);
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSL_CTX_FUNCTION,
CertificateChecker::ProcessSSLContext),