OLD | NEW |
| (Empty) |
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 COMPONENTS_CRASH_CONTENT_TOOLS_CRASH_SERVICE_H_ | |
6 #define COMPONENTS_CRASH_CONTENT_TOOLS_CRASH_SERVICE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/files/file_path.h" | |
12 #include "base/synchronization/lock.h" | |
13 | |
14 namespace google_breakpad { | |
15 | |
16 class CrashReportSender; | |
17 class CrashGenerationServer; | |
18 class ClientInfo; | |
19 | |
20 } | |
21 | |
22 namespace breakpad { | |
23 | |
24 // This class implements an out-of-process crash server. It uses breakpad's | |
25 // CrashGenerationServer and CrashReportSender to generate and then send the | |
26 // crash dumps. Internally, it uses OS specific pipe to allow applications to | |
27 // register for crash dumps and later on when a registered application crashes | |
28 // it will signal an event that causes this code to wake up and perform a | |
29 // crash dump on the signaling process. The dump is then stored on disk and | |
30 // possibly sent to the crash2 servers. | |
31 class CrashService { | |
32 public: | |
33 CrashService(); | |
34 ~CrashService(); | |
35 | |
36 // Starts servicing crash dumps. Returns false if it failed. Do not use | |
37 // other members in that case. |operating_dir| is where the CrashService | |
38 // should store breakpad's checkpoint file. |dumps_path| is the directory | |
39 // where the crash dumps should be stored. | |
40 bool Initialize(const base::FilePath& operating_dir, | |
41 const base::FilePath& dumps_path); | |
42 | |
43 // Command line switches: | |
44 // | |
45 // --max-reports=<number> | |
46 // Allows to override the maximum number for reports per day. Normally | |
47 // the crash dumps are never sent so if you want to send any you must | |
48 // specify a positive number here. | |
49 static const char kMaxReports[]; | |
50 // --no-window | |
51 // Does not create a visible window on the desktop. The window does not have | |
52 // any other functionality other than allowing the crash service to be | |
53 // gracefully closed. | |
54 static const char kNoWindow[]; | |
55 // --reporter=<string> | |
56 // Allows to specify a custom string that appears on the detail crash report | |
57 // page in the crash server. This should be a 25 chars or less string. | |
58 // The default tag if not specified is 'crash svc'. | |
59 static const char kReporterTag[]; | |
60 // --dumps-dir=<directory-path> | |
61 // Override the directory to which crash dump files will be written. | |
62 static const char kDumpsDir[]; | |
63 // --pipe-name=<string> | |
64 // Override the name of the Windows named pipe on which we will | |
65 // listen for crash dump request messages. | |
66 static const char kPipeName[]; | |
67 | |
68 // Returns number of crash dumps handled. | |
69 int requests_handled() const { | |
70 return requests_handled_; | |
71 } | |
72 // Returns number of crash clients registered. | |
73 int clients_connected() const { | |
74 return clients_connected_; | |
75 } | |
76 // Returns number of crash clients terminated. | |
77 int clients_terminated() const { | |
78 return clients_terminated_; | |
79 } | |
80 | |
81 // Starts the processing loop. This function does not return unless the | |
82 // user is logging off or the user closes the crash service window. The | |
83 // return value is a good number to pass in ExitProcess(). | |
84 int ProcessingLoop(); | |
85 | |
86 private: | |
87 static void OnClientConnected(void* context, | |
88 const google_breakpad::ClientInfo* client_info); | |
89 | |
90 static void OnClientDumpRequest( | |
91 void* context, | |
92 const google_breakpad::ClientInfo* client_info, | |
93 const std::wstring* file_path); | |
94 | |
95 static void OnClientExited(void* context, | |
96 const google_breakpad::ClientInfo* client_info); | |
97 | |
98 // This routine sends the crash dump to the server. It takes the sending_ | |
99 // lock when it is performing the send. | |
100 static unsigned long __stdcall AsyncSendDump(void* context); | |
101 | |
102 // Returns the security descriptor which access to low integrity processes | |
103 // The caller is supposed to free the security descriptor by calling | |
104 // LocalFree. | |
105 PSECURITY_DESCRIPTOR GetSecurityDescriptorForLowIntegrity(); | |
106 | |
107 google_breakpad::CrashGenerationServer* dumper_; | |
108 google_breakpad::CrashReportSender* sender_; | |
109 | |
110 // the extra tag sent to the server with each dump. | |
111 std::wstring reporter_tag_; | |
112 | |
113 // clients serviced statistics: | |
114 int requests_handled_; | |
115 int requests_sent_; | |
116 volatile long clients_connected_; | |
117 volatile long clients_terminated_; | |
118 base::Lock sending_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(CrashService); | |
121 }; | |
122 | |
123 } // namespace breakpad | |
124 | |
125 #endif // COMPONENTS_CRASH_CONTENT_TOOLS_CRASH_SERVICE_H_ | |
OLD | NEW |