Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: components/ukm/ukm_source.cc

Issue 2756773002: Ensure UKM only sends URLs under a specific length (currently 2K). (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ukm/ukm_service_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/ukm/ukm_service_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698