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

Unified Diff: chrome/browser/ui/webui/log_web_ui_url.cc

Issue 1367343002: Add browser test for WebUI URL logging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: safer? Created 5 years, 3 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
Index: chrome/browser/ui/webui/log_web_ui_url.cc
diff --git a/chrome/browser/ui/webui/log_web_ui_url.cc b/chrome/browser/ui/webui/log_web_ui_url.cc
index 3b793a211879fecf1fcad90fa6f2fa1fc6a417a6..245b4f3a782ec1ac76ef4b145b406cc454718d54 100644
--- a/chrome/browser/ui/webui/log_web_ui_url.cc
+++ b/chrome/browser/ui/webui/log_web_ui_url.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/webui/log_web_ui_url.h"
+#include "base/bind.h"
#include "base/hash.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/sparse_histogram.h"
@@ -18,6 +19,16 @@
namespace webui {
+namespace {
+
+static WebUIUrlHash* g_hash = nullptr;
Dan Beam 2015/09/26 23:02:14 if you have any suggestions that don't require thi
+
+uint32 DefaultHash(const GURL& web_ui_url) {
+ return base::Hash(web_ui_url.spec());
+}
+
+} // namespace
+
bool LogWebUIUrl(const GURL& web_ui_url) {
bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) ||
web_ui_url.SchemeIs(content::kChromeDevToolsScheme);
@@ -28,7 +39,10 @@ bool LogWebUIUrl(const GURL& web_ui_url) {
#endif
if (should_log) {
- uint32 hash = base::Hash(web_ui_url.GetOrigin().spec());
+ if (!g_hash)
+ g_hash = new WebUIUrlHash(base::Bind(DefaultHash));
+
+ uint32 hash = g_hash->Run(web_ui_url.GetOrigin());
UMA_HISTOGRAM_SPARSE_SLOWLY("WebUI.CreatedForUrl",
static_cast<base::HistogramBase::Sample>(hash));
}
@@ -36,4 +50,14 @@ bool LogWebUIUrl(const GURL& web_ui_url) {
return should_log;
}
+void SetHashFunctionForTesting(const WebUIUrlHash& testing_hash) {
+ if (g_hash) {
+ delete g_hash;
+ g_hash = nullptr;
+ }
+
+ if (!testing_hash.is_null())
+ g_hash = new WebUIUrlHash(testing_hash);
+}
+
} // namespace webui

Powered by Google App Engine
This is Rietveld 408576698