OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ | 5 #ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ |
6 #define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ | 6 #define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/debug/crash_logging.h" | 13 #include "base/debug/crash_logging.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 | 15 |
16 class CommandLine; | 16 class CommandLine; |
17 | 17 |
18 // The maximum number of variation chunks we will report. | 18 // The maximum number of variation chunks we will report. |
19 // Also used in chrome/app, but we define it here to avoid a common->app | 19 // Also used in chrome/app, but we define it here to avoid a common->app |
20 // dependency. | 20 // dependency. |
21 static const size_t kMaxReportedVariationChunks = 15; | 21 static const size_t kMaxReportedVariationChunks = 15; |
22 | 22 |
23 // The maximum size of a variation chunk. This size was picked to be | 23 // The maximum size of a variation chunk. This size was picked to be |
24 // consistent between platforms and the value was chosen from the Windows | 24 // consistent between platforms and the value was chosen from the Windows |
25 // limit of google_breakpad::CustomInfoEntry::kValueMaxLength. | 25 // limit of google_breakpad::CustomInfoEntry::kValueMaxLength. |
26 static const size_t kMaxVariationChunkSize = 64; | 26 static const size_t kMaxVariationChunkSize = 64; |
27 | 27 |
| 28 // The maximum number of prn-info-* records. |
| 29 static const size_t kMaxReportedPrinterRecords = 4; |
| 30 |
28 // The maximum number of command line switches to include in the crash | 31 // The maximum number of command line switches to include in the crash |
29 // report's metadata. Note that the mini-dump itself will also contain the | 32 // report's metadata. Note that the mini-dump itself will also contain the |
30 // (original) command line arguments within the PEB. | 33 // (original) command line arguments within the PEB. |
31 // Also used in chrome/app, but we define it here to avoid a common->app | 34 // Also used in chrome/app, but we define it here to avoid a common->app |
32 // dependency. | 35 // dependency. |
33 static const size_t kMaxSwitches = 15; | 36 static const size_t kMaxSwitches = 15; |
34 | 37 |
35 namespace child_process_logging { | 38 namespace child_process_logging { |
36 | 39 |
37 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 40 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
38 // These are declared here so the crash reporter can access them directly in | 41 // These are declared here so the crash reporter can access them directly in |
39 // compromised context without going through the standard library. | 42 // compromised context without going through the standard library. |
40 extern char g_client_id[]; | 43 extern char g_client_id[]; |
41 extern char g_num_switches[]; | 44 extern char g_num_switches[]; |
42 extern char g_num_variations[]; | 45 extern char g_num_variations[]; |
| 46 extern char g_printer_info[]; |
43 extern char g_switches[]; | 47 extern char g_switches[]; |
44 extern char g_variation_chunks[]; | 48 extern char g_variation_chunks[]; |
45 | 49 |
46 // Assume command line switches are less than 64 chars. | 50 // Assume command line switches are less than 64 chars. |
47 static const size_t kSwitchLen = 64; | 51 static const size_t kSwitchLen = 64; |
| 52 |
| 53 // Assume printer info strings are less than 64 chars. |
| 54 static const size_t kPrinterInfoStrLen = 64; |
48 #endif | 55 #endif |
49 | 56 |
50 // Sets the Client ID that is used as GUID if a Chrome process crashes. | 57 // Sets the Client ID that is used as GUID if a Chrome process crashes. |
51 void SetClientId(const std::string& client_id); | 58 void SetClientId(const std::string& client_id); |
52 | 59 |
53 // Gets the Client ID to be used as GUID for crash reporting. Returns the client | 60 // Gets the Client ID to be used as GUID for crash reporting. Returns the client |
54 // id in |client_id| if it's known, an empty string otherwise. | 61 // id in |client_id| if it's known, an empty string otherwise. |
55 std::string GetClientId(); | 62 std::string GetClientId(); |
56 | 63 |
| 64 // Sets the data on the printer to send along with crash reports. Data may be |
| 65 // separated by ';' up to kMaxReportedPrinterRecords strings. Each substring |
| 66 // would be cut to 63 chars. |
| 67 void SetPrinterInfo(const char* printer_info); |
| 68 |
57 // Sets the command line arguments to send along with crash reports to the | 69 // Sets the command line arguments to send along with crash reports to the |
58 // values in |command_line|. | 70 // values in |command_line|. |
59 void SetCommandLine(const CommandLine* command_line); | 71 void SetCommandLine(const CommandLine* command_line); |
60 | 72 |
61 // Initialize the list of experiment info to send along with crash reports. | 73 // Initialize the list of experiment info to send along with crash reports. |
62 void SetExperimentList(const std::vector<string16>& state); | 74 void SetExperimentList(const std::vector<string16>& state); |
63 | 75 |
| 76 // Set/clear information about currently accessed printer. |
| 77 class ScopedPrinterInfoSetter { |
| 78 public: |
| 79 explicit ScopedPrinterInfoSetter(const std::string& printer_info) { |
| 80 SetPrinterInfo(printer_info.c_str()); |
| 81 } |
| 82 |
| 83 ~ScopedPrinterInfoSetter() { |
| 84 SetPrinterInfo(""); |
| 85 } |
| 86 |
| 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter); |
| 89 }; |
| 90 |
64 } // namespace child_process_logging | 91 } // namespace child_process_logging |
65 | 92 |
66 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
67 namespace child_process_logging { | 94 namespace child_process_logging { |
68 | 95 |
69 // Sets up the base/debug/crash_logging.h mechanism. | 96 // Sets up the base/debug/crash_logging.h mechanism. |
70 void Init(); | 97 void Init(); |
71 | 98 |
72 } // namespace child_process_logging | 99 } // namespace child_process_logging |
73 #endif // defined(OS_WIN) | 100 #endif // defined(OS_WIN) |
74 | 101 |
75 #endif // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ | 102 #endif // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ |
OLD | NEW |