summaryrefslogtreecommitdiff
path: root/chromium/services/metrics
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/services/metrics
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/services/metrics')
-rw-r--r--chromium/services/metrics/public/cpp/ukm_source.cc29
-rw-r--r--chromium/services/metrics/public/cpp/ukm_source.h1
-rw-r--r--chromium/services/metrics/public/cpp/ukm_source_id_unittest.cc6
3 files changed, 32 insertions, 4 deletions
diff --git a/chromium/services/metrics/public/cpp/ukm_source.cc b/chromium/services/metrics/public/cpp/ukm_source.cc
index 408d0ad9a2e..b83454bd115 100644
--- a/chromium/services/metrics/public/cpp/ukm_source.cc
+++ b/chromium/services/metrics/public/cpp/ukm_source.cc
@@ -9,6 +9,7 @@
#include "base/atomicops.h"
#include "base/check_op.h"
#include "base/hash/hash.h"
+#include "base/notreached.h"
#include "third_party/metrics_proto/ukm/source.pb.h"
namespace ukm {
@@ -35,6 +36,28 @@ std::string GetShortenedURL(const GURL& url) {
return url.spec();
}
+// Translates ukm::SourceIdType to the equivalent Source proto enum value.
+SourceType ToProtobufSourceType(SourceIdType source_id_type) {
+ switch (source_id_type) {
+ case SourceIdType::DEFAULT:
+ return SourceType::DEFAULT;
+ case SourceIdType::NAVIGATION_ID:
+ return SourceType::NAVIGATION_ID;
+ case SourceIdType::APP_ID:
+ return SourceType::APP_ID;
+ case SourceIdType::HISTORY_ID:
+ return SourceType::HISTORY_ID;
+ case SourceIdType::WEBAPK_ID:
+ return SourceType::WEBAPK_ID;
+ case SourceIdType::PAYMENT_APP_ID:
+ return SourceType::PAYMENT_APP_ID;
+ case SourceIdType::DESKTOP_WEB_APP_ID:
+ return SourceType::DESKTOP_WEB_APP_ID;
+ default:
+ NOTREACHED();
+ return SourceType::DEFAULT;
+ }
+}
} // namespace
// static
@@ -70,6 +93,7 @@ UkmSource::NavigationData UkmSource::NavigationData::CopyWithSanitizedUrls(
UkmSource::UkmSource(ukm::SourceId id, const GURL& url)
: id_(id),
+ type_(GetSourceIdType(id_)),
custom_tab_state_(g_custom_tab_state),
creation_time_(base::TimeTicks::Now()) {
navigation_data_.urls = {url};
@@ -78,10 +102,11 @@ UkmSource::UkmSource(ukm::SourceId id, const GURL& url)
UkmSource::UkmSource(ukm::SourceId id, const NavigationData& navigation_data)
: id_(id),
+ type_(GetSourceIdType(id_)),
navigation_data_(navigation_data),
custom_tab_state_(g_custom_tab_state),
creation_time_(base::TimeTicks::Now()) {
- DCHECK(GetSourceIdType(id_) == SourceIdType::NAVIGATION_ID);
+ DCHECK(type_ == SourceIdType::NAVIGATION_ID);
DCHECK(!navigation_data.urls.empty());
DCHECK(!navigation_data.urls.back().is_empty());
}
@@ -98,10 +123,12 @@ void UkmSource::UpdateUrl(const GURL& new_url) {
void UkmSource::PopulateProto(Source* proto_source) const {
DCHECK(!proto_source->has_id());
+ DCHECK(!proto_source->has_type());
DCHECK(!proto_source->has_url());
DCHECK(!proto_source->has_initial_url());
proto_source->set_id(id_);
+ proto_source->set_type(ToProtobufSourceType(type_));
for (const auto& url : urls()) {
proto_source->add_urls()->set_url(GetShortenedURL(url));
}
diff --git a/chromium/services/metrics/public/cpp/ukm_source.h b/chromium/services/metrics/public/cpp/ukm_source.h
index ec138b0888b..fd65515dfeb 100644
--- a/chromium/services/metrics/public/cpp/ukm_source.h
+++ b/chromium/services/metrics/public/cpp/ukm_source.h
@@ -113,6 +113,7 @@ class METRICS_EXPORT UkmSource {
private:
const ukm::SourceId id_;
+ const ukm::SourceIdType type_;
NavigationData navigation_data_;
diff --git a/chromium/services/metrics/public/cpp/ukm_source_id_unittest.cc b/chromium/services/metrics/public/cpp/ukm_source_id_unittest.cc
index eff8fda5293..6c976a3e248 100644
--- a/chromium/services/metrics/public/cpp/ukm_source_id_unittest.cc
+++ b/chromium/services/metrics/public/cpp/ukm_source_id_unittest.cc
@@ -15,7 +15,7 @@ TEST(UkmSourceIdTest, AssignSourceIds) {
for (size_t i = 0; i < numIds; i++) {
ids[i] = AssignNewSourceId();
EXPECT_NE(kInvalidSourceId, ids[i]);
- EXPECT_EQ(SourceIdType::UKM, GetSourceIdType(ids[i]));
+ EXPECT_EQ(SourceIdType::DEFAULT, GetSourceIdType(ids[i]));
for (size_t j = 0; j < i; j++) {
EXPECT_NE(ids[j], ids[i]);
}
@@ -37,9 +37,9 @@ TEST(UkmSourceIdTest, ConvertToNavigationType) {
}
TEST(UkmSourceIdTest, GetSourceIdType) {
- // Check that the newly assigned id is defaulted to "UKM" type.
+ // Check that the newly assigned id has the default type.
const SourceId new_id = AssignNewSourceId();
- EXPECT_EQ(SourceIdType::UKM, GetSourceIdType(new_id));
+ EXPECT_EQ(SourceIdType::DEFAULT, GetSourceIdType(new_id));
const int64_t num_types = static_cast<int64_t>(SourceIdType::kMaxValue);
for (int64_t type_index = 0; type_index <= num_types; type_index++) {