Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS 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 _CRASH_USER_COLLECTOR_H_ |
| 6 | #define _CRASH_USER_COLLECTOR_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
Chris Sosa | 522c061 | 2010-06-18 11:08:11 -0700 | [diff] [blame] | 10 | #include "crash-reporter/system_logging.h" |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 11 | |
| 12 | class FilePath; |
| 13 | |
| 14 | // User crash collector. |
| 15 | class UserCollector { |
| 16 | public: |
| 17 | typedef void (*CountCrashFunction)(); |
| 18 | typedef bool (*IsFeedbackAllowedFunction)(); |
| 19 | |
| 20 | UserCollector(); |
| 21 | |
| 22 | // Initialize the user crash collector for detection of crashes, |
| 23 | // given a crash counting function, the path to this executable, |
| 24 | // metrics collection enabled oracle, and system logger facility. |
| 25 | // Crash detection/reporting is not enabled until Enable is |
| 26 | // called. |
| 27 | void Initialize(CountCrashFunction count_crash, |
| 28 | const std::string &our_path, |
| 29 | IsFeedbackAllowedFunction is_metrics_allowed, |
| 30 | SystemLogging *logger); |
| 31 | |
| 32 | virtual ~UserCollector(); |
| 33 | |
| 34 | // Enable collection. |
| 35 | bool Enable() { return SetUpInternal(true); } |
| 36 | |
| 37 | // Disable collection. |
| 38 | bool Disable() { return SetUpInternal(false); } |
| 39 | |
| 40 | // Handle a specific user crash. |
| 41 | void HandleCrash(int signal, int pid, const std::string &exec); |
| 42 | |
| 43 | // Set (override the default) core file pattern. |
| 44 | void set_core_pattern_file(const std::string &pattern) { |
| 45 | core_pattern_file_ = pattern; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | friend class UserCollectorTest; |
| 50 | |
| 51 | std::string GetPattern(bool enabled) const; |
| 52 | bool SetUpInternal(bool enabled); |
| 53 | |
| 54 | std::string core_pattern_file_; |
| 55 | CountCrashFunction count_crash_function_; |
| 56 | std::string our_path_; |
| 57 | bool initialized_; |
| 58 | IsFeedbackAllowedFunction is_feedback_allowed_function_; |
| 59 | SystemLogging *logger_; |
| 60 | }; |
| 61 | |
| 62 | #endif // _CRASH_USER_COLLECTOR_H_ |