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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/ukm/ukm_service_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ukm/ukm_source.h" 5 #include "components/ukm/ukm_source.h"
6 6
7 #include "base/hash.h" 7 #include "base/hash.h"
8 #include "components/metrics/proto/ukm/source.pb.h" 8 #include "components/metrics/proto/ukm/source.pb.h"
9 9
10 namespace ukm { 10 namespace ukm {
11 11
12 namespace {
13
14 // The maximum length of a URL we will record.
15 constexpr int kMaxURLLength = 2 * 1024;
16
17 // The string sent in place of a URL if the real URL was too long.
18 constexpr char kMaxUrlLengthMessage[] = "URLTooLong";
19
20 // Returns a URL that is under the length limit, by returning a constant
21 // string when the URl is too long.
22 std::string GetShortenedURL(const GURL& url) {
23 if (url.spec().length() > kMaxURLLength)
24 return kMaxUrlLengthMessage;
25 return url.spec();
26 }
27
28 } // namespace
29
12 UkmSource::UkmSource() = default; 30 UkmSource::UkmSource() = default;
13 31
14 UkmSource::~UkmSource() = default; 32 UkmSource::~UkmSource() = default;
15 33
16 void UkmSource::UpdateUrl(const GURL& url) { 34 void UkmSource::UpdateUrl(const GURL& url) {
17 DCHECK(!url_.is_empty()); 35 DCHECK(!url_.is_empty());
18 if (url_ == url) 36 if (url_ == url)
19 return; 37 return;
20 if (initial_url_.is_empty()) 38 if (initial_url_.is_empty())
21 initial_url_ = url_; 39 initial_url_ = url_;
22 url_ = url; 40 url_ = url;
23 } 41 }
24 42
25 void UkmSource::PopulateProto(Source* proto_source) const { 43 void UkmSource::PopulateProto(Source* proto_source) const {
26 DCHECK(!proto_source->has_id()); 44 DCHECK(!proto_source->has_id());
27 DCHECK(!proto_source->has_url()); 45 DCHECK(!proto_source->has_url());
28 DCHECK(!proto_source->has_initial_url()); 46 DCHECK(!proto_source->has_initial_url());
29 47
30 proto_source->set_id(id_); 48 proto_source->set_id(id_);
31 proto_source->set_url(url_.spec()); 49 proto_source->set_url(GetShortenedURL(url_));
32 if (!initial_url_.is_empty()) 50 if (!initial_url_.is_empty())
33 proto_source->set_initial_url(initial_url_.spec()); 51 proto_source->set_initial_url(GetShortenedURL(initial_url_));
34 } 52 }
35 53
36 } // namespace ukm 54 } // namespace ukm
OLDNEW
« 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