1 // Copyright (c) 2012 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.
5 #ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
6 #define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
12 #include "base/basictypes.h"
13 #include "base/debug/crash_logging.h"
14 #include "base/strings/string16.h"
23 // The maximum number of active extensions we will report.
24 // Also used in chrome/app, but we define it here to avoid a common->app
26 static const size_t kMaxReportedActiveExtensions
= 10;
28 // The maximum number of variation chunks we will report.
29 // Also used in chrome/app, but we define it here to avoid a common->app
31 static const size_t kMaxReportedVariationChunks
= 15;
33 // The maximum size of a variation chunk. This size was picked to be
34 // consistent between platforms and the value was chosen from the Windows
35 // limit of google_breakpad::CustomInfoEntry::kValueMaxLength.
36 static const size_t kMaxVariationChunkSize
= 64;
38 // The maximum number of prn-info-* records.
39 static const size_t kMaxReportedPrinterRecords
= 4;
41 // The maximum number of command line switches to include in the crash
42 // report's metadata. Note that the mini-dump itself will also contain the
43 // (original) command line arguments within the PEB.
44 // Also used in chrome/app, but we define it here to avoid a common->app
46 static const size_t kMaxSwitches
= 15;
48 namespace child_process_logging
{
50 #if defined(OS_POSIX) && !defined(OS_MACOSX)
51 // These are declared here so the crash reporter can access them directly in
52 // compromised context without going through the standard library.
53 extern char g_active_url
[];
54 extern char g_channel
[];
55 extern char g_client_id
[];
56 extern char g_extension_ids
[];
57 extern char g_gpu_vendor_id
[];
58 extern char g_gpu_device_id
[];
59 extern char g_gpu_gl_vendor
[];
60 extern char g_gpu_gl_renderer
[];
61 extern char g_gpu_driver_ver
[];
62 extern char g_gpu_ps_ver
[];
63 extern char g_gpu_vs_ver
[];
64 extern char g_num_extensions
[];
65 extern char g_num_switches
[];
66 extern char g_num_variations
[];
67 extern char g_num_views
[];
68 extern char g_printer_info
[];
69 extern char g_switches
[];
70 extern char g_variation_chunks
[];
72 // Assume IDs are 32 bytes long.
73 static const size_t kExtensionLen
= 32;
75 // Assume command line switches are less than 64 chars.
76 static const size_t kSwitchLen
= 64;
78 // Assume printer info strings are less than 64 chars.
79 static const size_t kPrinterInfoStrLen
= 64;
82 // Sets the URL that is logged if the child process crashes. Use GURL() to clear
84 void SetActiveURL(const GURL
& url
);
86 // Sets the Client ID that is used as GUID if a Chrome process crashes.
87 void SetClientId(const std::string
& client_id
);
89 // Gets the Client ID to be used as GUID for crash reporting. Returns the client
90 // id in |client_id| if it's known, an empty string otherwise.
91 std::string
GetClientId();
93 // Sets the list of "active" extensions in this process. We overload "active" to
94 // mean different things depending on the process type:
95 // - browser: all enabled extensions
96 // - renderer: the unique set of extension ids from all content scripts
97 // - extension: the id of each extension running in this process (there can be
98 // multiple because of process collapsing).
99 void SetActiveExtensions(const std::set
<std::string
>& extension_ids
);
101 // Sets a number of views/tabs opened in this process.
102 void SetNumberOfViews(int number_of_views
);
104 // Sets the data on the gpu to send along with crash reports.
105 void SetGpuInfo(const gpu::GPUInfo
& gpu_info
);
107 // Sets the data on the printer to send along with crash reports. Data may be
108 // separated by ';' up to kMaxReportedPrinterRecords strings. Each substring
109 // would be cut to 63 chars.
110 void SetPrinterInfo(const char* printer_info
);
112 // Sets the command line arguments to send along with crash reports to the
113 // values in |command_line|.
114 void SetCommandLine(const CommandLine
* command_line
);
116 // Initialize the list of experiment info to send along with crash reports.
117 void SetExperimentList(const std::vector
<string16
>& state
);
119 #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
120 // Sets the product channel data to send along with crash reports to |channel|.
121 void SetChannel(const std::string
& channel
);
124 // Simple wrapper class that sets the active URL in it's constructor and clears
125 // the active URL in the destructor.
126 class ScopedActiveURLSetter
{
128 explicit ScopedActiveURLSetter(const GURL
& url
) {
132 ~ScopedActiveURLSetter() {
133 SetActiveURL(GURL());
137 DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter
);
140 // Set/clear information about currently accessed printer.
141 class ScopedPrinterInfoSetter
{
143 explicit ScopedPrinterInfoSetter(const std::string
& printer_info
) {
144 SetPrinterInfo(printer_info
.c_str());
147 ~ScopedPrinterInfoSetter() {
152 DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter
);
155 } // namespace child_process_logging
157 #if defined(OS_MACOSX)
159 namespace child_process_logging
{
161 void SetActiveURLImpl(const GURL
& url
,
162 base::debug::SetCrashKeyValueFuncT set_key_func
,
163 base::debug::ClearCrashKeyValueFuncT clear_key_func
);
165 extern const size_t kMaxNumCrashURLChunks
;
166 extern const size_t kMaxNumURLChunkValueLength
;
167 extern const char* kUrlChunkFormatStr
;
169 } // namespace child_process_logging
171 #endif // defined(OS_MACOSX)
173 #endif // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_