OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/webui/log_web_ui_url.h" | 5 #include "chrome/browser/ui/webui/log_web_ui_url.h" |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "base/hash.h" | 8 #include "base/hash.h" |
8 #include "base/metrics/histogram_base.h" | 9 #include "base/metrics/histogram_base.h" |
9 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
11 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 #if defined(ENABLE_EXTENSIONS) | 15 #if defined(ENABLE_EXTENSIONS) |
15 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
16 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
17 #endif | 18 #endif |
18 | 19 |
19 namespace webui { | 20 namespace webui { |
20 | 21 |
22 namespace { | |
23 | |
24 static WebUIUrlHash* g_hash = nullptr; | |
Dan Beam
2015/09/26 23:02:14
if you have any suggestions that don't require thi
| |
25 | |
26 uint32 DefaultHash(const GURL& web_ui_url) { | |
27 return base::Hash(web_ui_url.spec()); | |
28 } | |
29 | |
30 } // namespace | |
31 | |
21 bool LogWebUIUrl(const GURL& web_ui_url) { | 32 bool LogWebUIUrl(const GURL& web_ui_url) { |
22 bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) || | 33 bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) || |
23 web_ui_url.SchemeIs(content::kChromeDevToolsScheme); | 34 web_ui_url.SchemeIs(content::kChromeDevToolsScheme); |
24 | 35 |
25 #if defined(ENABLE_EXTENSIONS) | 36 #if defined(ENABLE_EXTENSIONS) |
26 if (web_ui_url.SchemeIs(extensions::kExtensionScheme)) | 37 if (web_ui_url.SchemeIs(extensions::kExtensionScheme)) |
27 should_log = web_ui_url.host() == extension_misc::kBookmarkManagerId; | 38 should_log = web_ui_url.host() == extension_misc::kBookmarkManagerId; |
28 #endif | 39 #endif |
29 | 40 |
30 if (should_log) { | 41 if (should_log) { |
31 uint32 hash = base::Hash(web_ui_url.GetOrigin().spec()); | 42 if (!g_hash) |
43 g_hash = new WebUIUrlHash(base::Bind(DefaultHash)); | |
44 | |
45 uint32 hash = g_hash->Run(web_ui_url.GetOrigin()); | |
32 UMA_HISTOGRAM_SPARSE_SLOWLY("WebUI.CreatedForUrl", | 46 UMA_HISTOGRAM_SPARSE_SLOWLY("WebUI.CreatedForUrl", |
33 static_cast<base::HistogramBase::Sample>(hash)); | 47 static_cast<base::HistogramBase::Sample>(hash)); |
34 } | 48 } |
35 | 49 |
36 return should_log; | 50 return should_log; |
37 } | 51 } |
38 | 52 |
53 void SetHashFunctionForTesting(const WebUIUrlHash& testing_hash) { | |
54 if (g_hash) { | |
55 delete g_hash; | |
56 g_hash = nullptr; | |
57 } | |
58 | |
59 if (!testing_hash.is_null()) | |
60 g_hash = new WebUIUrlHash(testing_hash); | |
61 } | |
62 | |
39 } // namespace webui | 63 } // namespace webui |
OLD | NEW |