1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
6#define CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include "base/process/process.h"
13#include "base/strings/stringprintf.h"
14#include "build/build_config.h"  // USE_TCMALLOC
15
16template <typename T> struct DefaultSingletonTraits;
17class GURL;
18
19namespace content {
20class BrowserContext;
21}
22
23// Returns true if the given URL will be handled by the browser about handler.
24// Nowadays, these go through the webui, so the return is always false.
25// Either way, |url| will be processed by URLFixerUpper::FixupURL, which
26// replaces the about: scheme with chrome:// for all about:foo URLs except
27// "about:blank".
28// Some |url| host values will be replaced with their respective redirects.
29//
30// This is used by BrowserURLHandler.
31bool WillHandleBrowserAboutURL(GURL* url,
32                               content::BrowserContext* browser_context);
33
34// We have a few magic commands that don't cause navigations, but rather pop up
35// dialogs. This function handles those cases, and returns true if so. In this
36// case, normal tab navigation should be skipped.
37bool HandleNonNavigationAboutURL(const GURL& url);
38
39#if defined(USE_TCMALLOC)
40// A map of header strings (e.g. "Browser", "Renderer PID 123")
41// to the tcmalloc output collected for each process.
42typedef std::map<std::string, std::string> AboutTcmallocOutputsType;
43
44class AboutTcmallocOutputs {
45 public:
46  // Returns the singleton instance.
47  static AboutTcmallocOutputs* GetInstance();
48
49  AboutTcmallocOutputsType* outputs() { return &outputs_; }
50
51  // Records the output for a specified header string.
52  void SetOutput(const std::string& header, const std::string& output) {
53    outputs_[header] = output;
54  }
55
56  // Callback for output returned from renderer processes.  Adds
57  // the output for a canonical renderer header string that
58  // incorporates the pid.
59  void RendererCallback(base::ProcessId pid, const std::string& output) {
60    SetOutput(
61        base::StringPrintf("Renderer PID %d", static_cast<int>(pid)), output);
62  }
63
64 private:
65  AboutTcmallocOutputs();
66  ~AboutTcmallocOutputs();
67
68  AboutTcmallocOutputsType outputs_;
69
70  friend struct DefaultSingletonTraits<AboutTcmallocOutputs>;
71
72  DISALLOW_COPY_AND_ASSIGN(AboutTcmallocOutputs);
73};
74
75// Glue between the callback task and the method in the singleton.
76void AboutTcmallocRendererCallback(base::ProcessId pid,
77                                   const std::string& output);
78#endif  // defined(USE_TCMALLOC)
79
80#endif  // CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
81