summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/log_web_ui_url.cc
blob: 9679ab1746eb6dbeb6d3750829b78d35b6dd322e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/log_web_ui_url.h"

#include <stdint.h>

#include "base/hash.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/sparse_histogram.h"
#include "chrome/common/url_constants.h"
#include "content/public/common/url_constants.h"
#include "url/gurl.h"

#if defined(ENABLE_EXTENSIONS)
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/common/constants.h"
#endif

namespace webui {

const char kWebUICreatedForUrl[] = "WebUI.CreatedForUrl";

bool LogWebUIUrl(const GURL& web_ui_url) {
  bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) ||
                    web_ui_url.SchemeIs(content::kChromeDevToolsScheme);

#if defined(ENABLE_EXTENSIONS)
  if (web_ui_url.SchemeIs(extensions::kExtensionScheme))
    should_log = web_ui_url.host() == extension_misc::kBookmarkManagerId;
#endif

  if (should_log) {
    uint32_t hash = base::Hash(web_ui_url.GetOrigin().spec());
    UMA_HISTOGRAM_SPARSE_SLOWLY(kWebUICreatedForUrl,
                                static_cast<base::HistogramBase::Sample>(hash));
  }

  return should_log;
}

}  // namespace webui