1 // Copyright 2018 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 CHROME_CHROME_CLEANER_CRASH_CRASH_CLIENT_H_ 6 #define CHROME_CHROME_CLEANER_CRASH_CRASH_CLIENT_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/macros.h" 12 #include "base/synchronization/lock.h" 13 #include "chrome/chrome_cleaner/settings/settings_types.h" 14 15 namespace chrome_cleaner { 16 17 // This class manages interaction with the crash reporter. 18 class CrashClient { 19 public: 20 enum class Mode { REPORTER, CLEANER, MODE_COUNT }; 21 22 static CrashClient* GetInstance(); 23 24 // Set |client_id| to the current guid associated with crashes. |client_id| 25 // may be empty if no guid is associated. 26 static void GetClientId(std::wstring* client_id); 27 28 // Returns whether upload of crashes is enabled or not. 29 static bool IsUploadEnabled(); 30 31 CrashClient() = default; 32 virtual ~CrashClient() = default; 33 34 // Initializes collection and upload of crash reports. This will only be done 35 // if the user has agreed to crash dump reporting. 36 // 37 // Crash reporting has to be initialized as early as possible (e.g., the first 38 // thing in main()) to catch crashes occurring during process startup. Crashes 39 // which occur during the global static construction phase will not be caught 40 // and reported. This should not be a problem as static non-POD objects are 41 // not allowed by the style guide and exceptions to this rule are rare. 42 // 43 // |mode| controls a custom info entry present in the generated dumps to allow 44 // distinguishing between cleaner and reporter crashes on the backend. 45 // 46 // |process_type| identifies the type of process that reported the crash. 47 virtual bool InitializeCrashReporting(Mode mode, 48 SandboxType process_type) = 0; 49 50 private: 51 DISALLOW_COPY_AND_ASSIGN(CrashClient); 52 }; 53 54 } // namespace chrome_cleaner 55 56 #endif // CHROME_CHROME_CLEANER_CRASH_CRASH_CLIENT_H_ 57