OLD | NEW |
(Empty) | |
| 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_REPORTER_CRASH_COLLECTOR_H_ |
| 6 #define _CRASH_REPORTER_CRASH_COLLECTOR_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <sys/stat.h> |
| 10 |
| 11 #include "gtest/gtest_prod.h" // for FRIEND_TEST |
| 12 |
| 13 class FilePath; |
| 14 class SystemLogging; |
| 15 |
| 16 // User crash collector. |
| 17 class CrashCollector { |
| 18 public: |
| 19 typedef void (*CountCrashFunction)(); |
| 20 typedef bool (*IsFeedbackAllowedFunction)(); |
| 21 |
| 22 CrashCollector(); |
| 23 |
| 24 virtual ~CrashCollector(); |
| 25 |
| 26 // Initialize the crash collector for detection of crashes, given a |
| 27 // crash counting function, metrics collection enabled oracle, and |
| 28 // system logger facility. |
| 29 void Initialize(CountCrashFunction count_crash, |
| 30 IsFeedbackAllowedFunction is_metrics_allowed, |
| 31 SystemLogging *logger); |
| 32 |
| 33 protected: |
| 34 friend class CrashCollectorTest; |
| 35 FRIEND_TEST(CrashCollectorTest, GetCrashDirectoryInfo); |
| 36 FRIEND_TEST(CrashCollectorTest, FormatDumpBasename); |
| 37 FRIEND_TEST(CrashCollectorTest, Initialize); |
| 38 |
| 39 // For testing, set the directory always returned by |
| 40 // GetCreatedCrashDirectoryByEuid. |
| 41 void ForceCrashDirectory(const char *forced_directory) { |
| 42 forced_crash_directory_ = forced_directory; |
| 43 } |
| 44 |
| 45 FilePath GetCrashDirectoryInfo(uid_t process_euid, |
| 46 uid_t default_user_id, |
| 47 gid_t default_user_group, |
| 48 mode_t *mode, |
| 49 uid_t *directory_owner, |
| 50 gid_t *directory_group); |
| 51 bool GetUserInfoFromName(const std::string &name, |
| 52 uid_t *uid, |
| 53 gid_t *gid); |
| 54 // Determines the crash directory for given eud, and creates the |
| 55 // directory if necessary with appropriate permissions. Returns |
| 56 // true whether or not directory needed to be created, false on any |
| 57 // failure. |
| 58 bool GetCreatedCrashDirectoryByEuid(uid_t euid, |
| 59 FilePath *crash_file_path); |
| 60 std::string FormatDumpBasename(const std::string &exec_name, |
| 61 time_t timestamp, |
| 62 pid_t pid); |
| 63 |
| 64 CountCrashFunction count_crash_function_; |
| 65 IsFeedbackAllowedFunction is_feedback_allowed_function_; |
| 66 SystemLogging *logger_; |
| 67 const char *forced_crash_directory_; |
| 68 }; |
| 69 |
| 70 #endif // _CRASH_REPORTER_CRASH_COLLECTOR_H_ |
OLD | NEW |