child_process_logging.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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_COMMON_CHILD_PROCESS_LOGGING_H_
6#define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
7#pragma once
8
9#include <set>
10#include <string>
11
12#include "base/basictypes.h"
13#include "googleurl/src/gurl.h"
14
15class GPUInfo;
16
17#if defined(OS_WIN)
18// The maximum number of active extensions we will report.
19// Also used in chrome/app, but we define it here to avoid a common->app
20// dependency.
21static const int kMaxReportedActiveExtensions = 10;
22#endif
23
24namespace child_process_logging {
25
26#if defined(OS_LINUX)
27// These are declared here so the crash reporter can access them directly in
28// compromised context without going through the standard library.
29extern char g_active_url[];
30extern char g_client_id[];
31#endif
32
33// Sets the URL that is logged if the child process crashes. Use GURL() to clear
34// the URL.
35void SetActiveURL(const GURL& url);
36
37// Sets the Client ID that is used as GUID if a Chrome process crashes.
38void SetClientId(const std::string& client_id);
39
40// Gets the Client ID to be used as GUID for crash reporting. Returns the client
41// id in |client_id| if it's known, an empty string otherwise.
42std::string GetClientId();
43
44// Sets the list of "active" extensions in this process. We overload "active" to
45// mean different things depending on the process type:
46// - browser: all enabled extensions
47// - renderer: the unique set of extension ids from all content scripts
48// - extension: the id of each extension running in this process (there can be
49//   multiple because of process collapsing).
50void SetActiveExtensions(const std::set<std::string>& extension_ids);
51
52// Sets a number of views/tabs opened in this process.
53void SetNumberOfViews(int number_of_views);
54
55// Sets the data on the gpu to send along with crash reports.
56void SetGpuInfo(const GPUInfo& gpu_info);
57
58// Simple wrapper class that sets the active URL in it's constructor and clears
59// the active URL in the destructor.
60class ScopedActiveURLSetter {
61 public:
62  explicit ScopedActiveURLSetter(const GURL& url)  {
63    SetActiveURL(url);
64  }
65
66  ~ScopedActiveURLSetter()  {
67    SetActiveURL(GURL());
68  }
69
70 private:
71  DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter);
72};
73
74}  // namespace child_process_logging
75
76#if defined(OS_MACOSX) && __OBJC__
77
78@class NSString;
79
80typedef void (*SetCrashKeyValueFuncPtr)(NSString*, NSString*);
81typedef void (*ClearCrashKeyValueFuncPtr)(NSString*);
82
83namespace child_process_logging {
84void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
85                          ClearCrashKeyValueFuncPtr clear_key_func);
86void SetActiveURLImpl(const GURL& url,
87                      SetCrashKeyValueFuncPtr set_key_func,
88                      ClearCrashKeyValueFuncPtr clear_key_func);
89
90extern const int kMaxNumCrashURLChunks;
91extern const int kMaxNumURLChunkValueLength;
92extern const char *kUrlChunkFormatStr;
93}  // namespace child_process_logging
94
95#endif  // defined(OS_MACOSX) && __OBJC__
96
97#endif  // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
98