two_phase_testserver.py: Remove unnecessary method override.
[chromium-blink-merge.git] / chrome / tools / crash_service / crash_service.h
blob9ea56c576ad3308323b49b7413844c8f8703dc35
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 CHROME_TOOLS_CRASH_SERVICE_CRASH_SERVICE_H_
6 #define CHROME_TOOLS_CRASH_SERVICE_CRASH_SERVICE_H_
8 #include <string>
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;
18 class ClientInfo;
22 // This class implements an out-of-process crash server. It uses breakpad's
23 // CrashGenerationServer and CrashReportSender to generate and then send the
24 // crash dumps. Internally, it uses OS specific pipe to allow applications to
25 // register for crash dumps and later on when a registered application crashes
26 // it will signal an event that causes this code to wake up and perform a
27 // crash dump on the signaling process. The dump is then stored on disk and
28 // possibly sent to the crash2 servers.
29 class CrashService {
30 public:
31 // The ctor takes a directory that needs to be writable and will create
32 // a subdirectory inside to keep logs, crashes and checkpoint files.
33 explicit CrashService(const std::wstring& report_dir);
34 ~CrashService();
36 // Starts servicing crash dumps. The command_line specifies various behaviors,
37 // see below for more information. Returns false if it failed. Do not use
38 // other members in that case.
39 bool Initialize(const std::wstring& command_line);
41 // Command line switches:
43 // --max-reports=<number>
44 // Allows to override the maximum number for reports per day. Normally
45 // the crash dumps are never sent so if you want to send any you must
46 // specify a positive number here.
47 static const char kMaxReports[];
48 // --no-window
49 // Does not create a visible window on the desktop. The window does not have
50 // any other functionality other than allowing the crash service to be
51 // gracefully closed.
52 static const char kNoWindow[];
53 // --reporter=<string>
54 // Allows to specify a custom string that appears on the detail crash report
55 // page in the crash server. This should be a 25 chars or less string.
56 // The default tag if not specified is 'crash svc'.
57 static const char kReporterTag[];
58 // --dumps-dir=<directory-path>
59 // Override the directory to which crash dump files will be written.
60 static const char kDumpsDir[];
61 // --pipe-name=<string>
62 // Override the name of the Windows named pipe on which we will
63 // listen for crash dump request messages.
64 static const char kPipeName[];
66 // Returns number of crash dumps handled.
67 int requests_handled() const {
68 return requests_handled_;
70 // Returns number of crash clients registered.
71 int clients_connected() const {
72 return clients_connected_;
74 // Returns number of crash clients terminated.
75 int clients_terminated() const {
76 return clients_terminated_;
79 // Starts the processing loop. This function does not return unless the
80 // user is logging off or the user closes the crash service window. The
81 // return value is a good number to pass in ExitProcess().
82 int ProcessingLoop();
84 private:
85 static void OnClientConnected(void* context,
86 const google_breakpad::ClientInfo* client_info);
88 static void OnClientDumpRequest(
89 void* context,
90 const google_breakpad::ClientInfo* client_info,
91 const std::wstring* file_path);
93 static void OnClientExited(void* context,
94 const google_breakpad::ClientInfo* client_info);
96 // This routine sends the crash dump to the server. It takes the sending_
97 // lock when it is performing the send.
98 static unsigned long __stdcall AsyncSendDump(void* context);
100 // Returns the security descriptor which access to low integrity processes
101 // The caller is supposed to free the security descriptor by calling
102 // LocalFree.
103 PSECURITY_DESCRIPTOR GetSecurityDescriptorForLowIntegrity();
105 google_breakpad::CrashGenerationServer* dumper_;
106 google_breakpad::CrashReportSender* sender_;
108 // the path to dumps and logs directory.
109 base::FilePath report_path_;
110 // the extra tag sent to the server with each dump.
111 std::wstring reporter_tag_;
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_;
120 DISALLOW_COPY_AND_ASSIGN(CrashService);
123 #endif // CHROME_TOOLS_CRASH_SERVICE_CRASH_SERVICE_H_