• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_APP_CRASH_REPORTER_CLIENT_H_
6 #define COMPONENTS_CRASH_APP_CRASH_REPORTER_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/strings/string16.h"
11 #include "build/build_config.h"
12 
13 namespace base {
14 class FilePath;
15 }
16 
17 #if defined(OS_MACOSX)
18 // We don't want to directly include
19 // breakpad/src/client/mac/Framework/Breakpad.h here, so we repeat the
20 // definition of BreakpadRef.
21 //
22 // On Mac, when compiling without breakpad support, a stub implementation is
23 // compiled in. Not having any includes of the breakpad library allows for
24 // reusing this header for the stub.
25 typedef void* BreakpadRef;
26 #endif
27 
28 namespace crash_reporter {
29 
30 class CrashReporterClient;
31 
32 // Setter and getter for the client.  The client should be set early, before any
33 // crash reporter code is called, and should stay alive throughout the entire
34 // runtime.
35 void SetCrashReporterClient(CrashReporterClient* client);
36 
37 #if defined(CRASH_IMPLEMENTATION)
38 // The components's embedder API should only be used by the component.
39 CrashReporterClient* GetCrashReporterClient();
40 #endif
41 
42 // Interface that the embedder implements.
43 class CrashReporterClient {
44  public:
45   CrashReporterClient();
46   virtual ~CrashReporterClient();
47 
48   // Sets the crash reporting client ID, a unique identifier for the client
49   // that is sending crash reports. After it is set, it should not be changed.
50   // |client_guid| may either be a full GUID or a GUID that was already stripped
51   // from its dashes.
52   virtual void SetCrashReporterClientIdFromGUID(const std::string& client_guid);
53 
54 #if defined(OS_WIN)
55   // Returns true if an alternative location to store the minidump files was
56   // specified. Returns true if |crash_dir| was set.
57   virtual bool GetAlternativeCrashDumpLocation(base::FilePath* crash_dir);
58 
59   // Returns a textual description of the product type and version to include
60   // in the crash report.
61   virtual void GetProductNameAndVersion(const base::FilePath& exe_path,
62                                         base::string16* product_name,
63                                         base::string16* version,
64                                         base::string16* special_build,
65                                         base::string16* channel_name);
66 
67   // Returns true if a restart dialog should be displayed. In that case,
68   // |message| and |title| are set to a message to display in a dialog box with
69   // the given title before restarting, and |is_rtl_locale| indicates whether
70   // to display the text as RTL.
71   virtual bool ShouldShowRestartDialog(base::string16* title,
72                                        base::string16* message,
73                                        bool* is_rtl_locale);
74 
75   // Returns true if it is ok to restart the application. Invoked right before
76   // restarting after a crash.
77   virtual bool AboutToRestart();
78 
79   // Returns true if the crash report uploader supports deferred uploads.
80   virtual bool GetDeferredUploadsSupported(bool is_per_user_install);
81 
82   // Returns true if the running binary is a per-user installation.
83   virtual bool GetIsPerUserInstall(const base::FilePath& exe_path);
84 
85   // Returns true if larger crash dumps should be dumped.
86   virtual bool GetShouldDumpLargerDumps(bool is_per_user_install);
87 
88   // Returns the result code to return when breakpad failed to respawn a
89   // crashed process.
90   virtual int GetResultCodeRespawnFailed();
91 
92   // Invoked when initializing the crash reporter in the browser process.
93   virtual void InitBrowserCrashDumpsRegKey();
94 
95   // Invoked before attempting to write a minidump.
96   virtual void RecordCrashDumpAttempt(bool is_real_crash);
97 #endif
98 
99 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_IOS)
100   // Returns a textual description of the product type and version to include
101   // in the crash report.
102   virtual void GetProductNameAndVersion(std::string* product_name,
103                                         std::string* version);
104 
105   virtual base::FilePath GetReporterLogFilename();
106 #endif
107 
108   // The location where minidump files should be written. Returns true if
109   // |crash_dir| was set.
110   virtual bool GetCrashDumpLocation(base::FilePath* crash_dir);
111 
112   // Register all of the potential crash keys that can be sent to the crash
113   // reporting server. Returns the size of the union of all keys.
114   virtual size_t RegisterCrashKeys();
115 
116   // Returns true if running in unattended mode (for automated testing).
117   virtual bool IsRunningUnattended();
118 
119   // Returns true if the user has given consent to collect stats.
120   virtual bool GetCollectStatsConsent();
121 
122 #if defined(OS_WIN) || defined(OS_MACOSX)
123   // Returns true if crash reporting is enforced via management policies. In
124   // that case, |breakpad_enabled| is set to the value enforced by policies.
125   virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);
126 #endif
127 
128 #if defined(OS_ANDROID)
129   // Returns the descriptor key of the android minidump global descriptor.
130   virtual int GetAndroidMinidumpDescriptor();
131 #endif
132 
133 #if defined(OS_MACOSX)
134   // Install additional breakpad filter callbacks.
135   virtual void InstallAdditionalFilters(BreakpadRef breakpad);
136 #endif
137 
138   // Returns true if breakpad should run in the given process type.
139   virtual bool EnableBreakpadForProcess(const std::string& process_type);
140 };
141 
142 }  // namespace crash_reporter
143 
144 #endif  // COMPONENTS_CRASH_APP_CRASH_REPORTER_CLIENT_H_
145