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.
5 #ifndef COMPONENTS_CRASH_TOOLS_CRASH_SERVICE_H_
6 #define COMPONENTS_CRASH_TOOLS_CRASH_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/synchronization/lock.h"
14 namespace google_breakpad
{
16 class CrashReportSender
;
17 class CrashGenerationServer
;
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.
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
);
43 // Command line switches:
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
[];
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
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
[];
68 // Returns number of crash dumps handled.
69 int requests_handled() const {
70 return requests_handled_
;
72 // Returns number of crash clients registered.
73 int clients_connected() const {
74 return clients_connected_
;
76 // Returns number of crash clients terminated.
77 int clients_terminated() const {
78 return clients_terminated_
;
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().
87 static void OnClientConnected(void* context
,
88 const google_breakpad::ClientInfo
* client_info
);
90 static void OnClientDumpRequest(
92 const google_breakpad::ClientInfo
* client_info
,
93 const std::wstring
* file_path
);
95 static void OnClientExited(void* context
,
96 const google_breakpad::ClientInfo
* client_info
);
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
);
102 // Returns the security descriptor which access to low integrity processes
103 // The caller is supposed to free the security descriptor by calling
105 PSECURITY_DESCRIPTOR
GetSecurityDescriptorForLowIntegrity();
107 google_breakpad::CrashGenerationServer
* dumper_
;
108 google_breakpad::CrashReportSender
* sender_
;
110 // the extra tag sent to the server with each dump.
111 std::wstring reporter_tag_
;
113 // clients serviced statistics:
114 int requests_handled_
;
116 volatile long clients_connected_
;
117 volatile long clients_terminated_
;
120 DISALLOW_COPY_AND_ASSIGN(CrashService
);
123 } // namespace breakpad
125 #endif // COMPONENTS_CRASH_TOOLS_CRASH_SERVICE_H_