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

Unified Diff: components/domain_reliability/util.cc

Issue 1180223006: Domain Reliability: Simplify configs and reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix memory leak in unittests Created 5 years, 1 month 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/domain_reliability/util.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/domain_reliability/util.cc
diff --git a/components/domain_reliability/util.cc b/components/domain_reliability/util.cc
index 06a8942eaf7a0c8d812f383ae3787ebd5a2e1c14..5fca298187d9d02333ad9026ef04acfc2215f4e5 100644
--- a/components/domain_reliability/util.cc
+++ b/components/domain_reliability/util.cc
@@ -67,6 +67,11 @@ const struct NetErrorMapping {
{ net::ERR_SSL_UNRECOGNIZED_NAME_ALERT, "ssl.unrecognized_name_alert" }
};
+bool CanReportFullBeaconURLToCollector(const GURL& beacon_url,
+ const GURL& collector_url) {
+ return beacon_url.GetOrigin() == collector_url.GetOrigin();
+}
+
} // namespace
// static
@@ -154,6 +159,34 @@ void GetUploadResultFromResponseDetails(
return;
}
+// N.B. This uses a ScopedVector because that's what JSONValueConverter uses
+// for repeated fields of any type, and Config uses JSONValueConverter to parse
+// JSON configs.
+GURL SanitizeURLForReport(const GURL& beacon_url,
+ const GURL& collector_url,
+ const ScopedVector<std::string>& path_prefixes) {
+ if (CanReportFullBeaconURLToCollector(beacon_url, collector_url))
+ return beacon_url.GetAsReferrer();
+
+ std::string path = beacon_url.path();
+ const std::string empty_path;
+ const std::string* longest_path_prefix = &empty_path;
+ for (const std::string* path_prefix : path_prefixes) {
+ if (path.substr(0, path_prefix->length()) == *path_prefix &&
+ path_prefix->length() > longest_path_prefix->length()) {
+ longest_path_prefix = path_prefix;
+ }
+ }
+
+ GURL::Replacements replacements;
+ replacements.ClearUsername();
+ replacements.ClearPassword();
+ replacements.SetPathStr(*longest_path_prefix);
+ replacements.ClearQuery();
+ replacements.ClearRef();
+ return beacon_url.ReplaceComponents(replacements);
+}
+
namespace {
class ActualTimer : public MockableTime::Timer {
« no previous file with comments | « components/domain_reliability/util.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698