Chromium Code Reviews| Index: components/autofill/core/browser/autofill_ukm.cc |
| diff --git a/components/autofill/core/browser/autofill_ukm.cc b/components/autofill/core/browser/autofill_ukm.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f34f9c327701de2a296956be79d80a274b2fe2f |
| --- /dev/null |
| +++ b/components/autofill/core/browser/autofill_ukm.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/autofill/core/browser/autofill_ukm.h" |
| + |
| +#include <map> |
| + |
| +#include "components/ukm/ukm_entry_builder.h" |
| +#include "components/ukm/ukm_service.h" |
| +#include "url/gurl.h" |
| + |
| +namespace autofill { |
| + |
| +// static |
| +bool AutofillUkm::LogUkm(ukm::UkmService* ukm_service, |
| + const GURL& url, |
| + const std::string& ukm, |
| + const std::map<std::string, int>& metrics) { |
| + if (!ukm_service) { |
| + DVLOG(3) << "No UKM service."; |
|
Mathieu
2017/03/09 18:40:49
these DVLOG are not very useful?
sebsg
2017/03/09 19:57:04
Done.
|
| + return false; |
| + } |
| + |
| + if (!url.is_valid()) { |
| + DVLOG(3) << "Invalid URL."; |
| + return false; |
| + } |
| + |
| + if (metrics.empty()) { |
| + DVLOG(3) << "No Metrics to log."; |
| + return false; |
| + } |
| + |
| + DVLOG(3) << "Sending event for url: " << url.spec(); |
| + int32_t source_id = ukm_service->GetNewSourceID(); |
| + ukm_service->UpdateSourceURL(source_id, url); |
| + std::unique_ptr<ukm::UkmEntryBuilder> builder = |
| + ukm_service->GetEntryBuilder(source_id, ukm.c_str()); |
| + |
| + for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
| + builder->AddMetric(it->first.c_str(), it->second); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace autofill |