Home | History | Annotate | Download | only in app
      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_BREAKPAD_APP_BREAKPAD_CLIENT_H_
      6 #define COMPONENTS_BREAKPAD_APP_BREAKPAD_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 breakpad {
     29 
     30 class BreakpadClient;
     31 
     32 // Setter and getter for the client.  The client should be set early, before any
     33 // breakpad code is called, and should stay alive throughout the entire runtime.
     34 void SetBreakpadClient(BreakpadClient* client);
     35 
     36 #if defined(BREAKPAD_IMPLEMENTATION)
     37 // Breakpad's embedder API should only be used by breakpad.
     38 BreakpadClient* GetBreakpadClient();
     39 #endif
     40 
     41 // Interface that the embedder implements.
     42 class BreakpadClient {
     43  public:
     44   BreakpadClient();
     45   virtual ~BreakpadClient();
     46 
     47   // Sets the Breakpad client ID, which is a unique identifier for the client
     48   // that is sending crash reports. After it is set, it should not be changed.
     49   virtual void SetClientID(const std::string& client_id);
     50 
     51 #if defined(OS_WIN)
     52   // Returns true if an alternative location to store the minidump files was
     53   // specified. Returns true if |crash_dir| was set.
     54   virtual bool GetAlternativeCrashDumpLocation(base::FilePath* crash_dir);
     55 
     56   // Returns a textual description of the product type and version to include
     57   // in the crash report.
     58   virtual void GetProductNameAndVersion(const base::FilePath& exe_path,
     59                                         base::string16* product_name,
     60                                         base::string16* version,
     61                                         base::string16* special_build,
     62                                         base::string16* channel_name);
     63 
     64   // Returns true if a restart dialog should be displayed. In that case,
     65   // |message| and |title| are set to a message to display in a dialog box with
     66   // the given title before restarting, and |is_rtl_locale| indicates whether
     67   // to display the text as RTL.
     68   virtual bool ShouldShowRestartDialog(base::string16* title,
     69                                        base::string16* message,
     70                                        bool* is_rtl_locale);
     71 
     72   // Returns true if it is ok to restart the application. Invoked right before
     73   // restarting after a crash.
     74   virtual bool AboutToRestart();
     75 
     76   // Returns true if the crash report uploader supports deferred uploads.
     77   virtual bool GetDeferredUploadsSupported(bool is_per_user_install);
     78 
     79   // Returns true if the running binary is a per-user installation.
     80   virtual bool GetIsPerUserInstall(const base::FilePath& exe_path);
     81 
     82   // Returns true if larger crash dumps should be dumped.
     83   virtual bool GetShouldDumpLargerDumps(bool is_per_user_install);
     84 
     85   // Returns the result code to return when breakpad failed to respawn a
     86   // crashed process.
     87   virtual int GetResultCodeRespawnFailed();
     88 
     89   // Invoked when initializing breakpad in the browser process.
     90   virtual void InitBrowserCrashDumpsRegKey();
     91 
     92   // Invoked before attempting to write a minidump.
     93   virtual void RecordCrashDumpAttempt(bool is_real_crash);
     94 #endif
     95 
     96 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_IOS)
     97   // Returns a textual description of the product type and version to include
     98   // in the crash report.
     99   virtual void GetProductNameAndVersion(std::string* product_name,
    100                                         std::string* version);
    101 
    102   virtual base::FilePath GetReporterLogFilename();
    103 #endif
    104 
    105   // The location where minidump files should be written. Returns true if
    106   // |crash_dir| was set.
    107   virtual bool GetCrashDumpLocation(base::FilePath* crash_dir);
    108 
    109 #if defined(OS_POSIX)
    110   // Sets a function that'll be invoked to dump the current process when
    111   // without crashing.
    112   virtual void SetDumpWithoutCrashingFunction(void (*function)());
    113 #endif
    114 
    115   // Register all of the potential crash keys that can be sent to the crash
    116   // reporting server. Returns the size of the union of all keys.
    117   virtual size_t RegisterCrashKeys();
    118 
    119   // Returns true if running in unattended mode (for automated testing).
    120   virtual bool IsRunningUnattended();
    121 
    122   // Returns true if the user has given consent to collect stats.
    123   virtual bool GetCollectStatsConsent();
    124 
    125 #if defined(OS_WIN) || defined(OS_MACOSX)
    126   // Returns true if breakpad is enforced via management policies. In that
    127   // case, |breakpad_enabled| is set to the value enforced by policies.
    128   virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);
    129 #endif
    130 
    131 #if defined(OS_ANDROID)
    132   // Returns the descriptor key of the android minidump global descriptor.
    133   virtual int GetAndroidMinidumpDescriptor();
    134 #endif
    135 
    136 #if defined(OS_MACOSX)
    137   // Install additional breakpad filter callbacks.
    138   virtual void InstallAdditionalFilters(BreakpadRef breakpad);
    139 #endif
    140 
    141   // Returns true if breakpad should run in the given process type.
    142   virtual bool EnableBreakpadForProcess(const std::string& process_type);
    143 };
    144 
    145 }  // namespace breakpad
    146 
    147 #endif  // COMPONENTS_BREAKPAD_APP_BREAKPAD_CLIENT_H_
    148