Index: components/ukm/ukm_source.cc |
diff --git a/components/ukm/ukm_source.cc b/components/ukm/ukm_source.cc |
index 182ce126918a7bf88ffd4efaeb9633dca566ac90..c9eda128a8f6c23114069054fa3a03db6f809f70 100644 |
--- a/components/ukm/ukm_source.cc |
+++ b/components/ukm/ukm_source.cc |
@@ -9,6 +9,24 @@ |
namespace ukm { |
+namespace { |
+ |
+// The maximum length of a URL we will record. |
+constexpr int kMaxURLLength = 2 * 1024; |
+ |
+// The string sent in place of a URL if the real URL was too long. |
+constexpr char kMaxUrlLengthMessage[] = "URLTooLong"; |
+ |
+// Returns a URL that is under the length limit, by returning a constant |
+// string when the URl is too long. |
+std::string GetShortenedURL(const GURL& url) { |
+ if (url.spec().length() > kMaxURLLength) |
+ return kMaxUrlLengthMessage; |
+ return url.spec(); |
+} |
+ |
+} // namespace |
+ |
UkmSource::UkmSource() = default; |
UkmSource::~UkmSource() = default; |
@@ -28,9 +46,9 @@ void UkmSource::PopulateProto(Source* proto_source) const { |
DCHECK(!proto_source->has_initial_url()); |
proto_source->set_id(id_); |
- proto_source->set_url(url_.spec()); |
+ proto_source->set_url(GetShortenedURL(url_)); |
if (!initial_url_.is_empty()) |
- proto_source->set_initial_url(initial_url_.spec()); |
+ proto_source->set_initial_url(GetShortenedURL(initial_url_)); |
} |
} // namespace ukm |