| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_FILE_LOG_SOURCE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_FILE_LOG_SOURCE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| 11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/feedback/system_logs/system_logs_fetcher.h" | 13 #include "chrome/browser/feedback/system_logs/system_logs_fetcher.h" |
| 14 #include "components/feedback/anonymizer_tool.h" | 14 #include "components/feedback/anonymizer_tool.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class Time; | 17 class Time; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace system_logs { | 20 namespace system_logs { |
| 21 | 21 |
| 22 // Gathers log data from a single source, possibly incrementally. | 22 // Gathers log data from a single source, possibly incrementally. |
| 23 class SingleLogSource : public SystemLogsSource { | 23 class SingleLogFileLogSource : public SystemLogsSource { |
| 24 public: | 24 public: |
| 25 enum class SupportedSource { | 25 enum class SupportedSource { |
| 26 // For /var/log/messages. | 26 // For /var/log/messages. |
| 27 kMessages, | 27 kMessages, |
| 28 | 28 |
| 29 // For /var/log/ui/ui.LATEST. | 29 // For /var/log/ui/ui.LATEST. |
| 30 kUiLatest, | 30 kUiLatest, |
| 31 | 31 |
| 32 // For /var/log/atrus.log. | 32 // For /var/log/atrus.log. |
| 33 kAtrusLog, | 33 kAtrusLog, |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 explicit SingleLogSource(SupportedSource source); | 36 explicit SingleLogFileLogSource(SupportedSource source); |
| 37 ~SingleLogSource() override; | 37 ~SingleLogFileLogSource() override; |
| 38 | 38 |
| 39 // During testing, use this to set a custom Chrome start time to override the | 39 // During testing, use this to set a custom Chrome start time to override the |
| 40 // actual start time. Does not take ownership of |start_time|. Call this again | 40 // actual start time. Does not take ownership of |start_time|. Call this again |
| 41 // with |start_time|=nullptr when done with testing. | 41 // with |start_time|=nullptr when done with testing. |
| 42 static void SetChromeStartTimeForTesting(const base::Time* start_time); | 42 static void SetChromeStartTimeForTesting(const base::Time* start_time); |
| 43 | 43 |
| 44 // system_logs::SystemLogsSource: | 44 // system_logs::SystemLogsSource: |
| 45 void Fetch(const SysLogsSourceCallback& callback) override; | 45 void Fetch(const SysLogsSourceCallback& callback) override; |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 friend class SingleLogSourceTest; | 48 friend class SingleLogFileLogSourceTest; |
| 49 | 49 |
| 50 // Returns the full path of the log file. | 50 // Returns the full path of the log file. |
| 51 base::FilePath GetLogFilePath() const; | 51 base::FilePath GetLogFilePath() const; |
| 52 | 52 |
| 53 // Reads all available content from |file_| that has not already been read. | 53 // Reads all available content from |file_| that has not already been read. |
| 54 // Stores results as a single entry in |result|, with |source_name()| as key | 54 // Stores results as a single entry in |result|, with |source_name()| as key |
| 55 // and the read log contents as value. | 55 // and the read log contents as value. |
| 56 // | 56 // |
| 57 // Handles rotation of underlying log file by reading all remaining contents | 57 // Handles rotation of underlying log file by reading all remaining contents |
| 58 // of old file and then opening and reading from new file. | 58 // of old file and then opening and reading from new file. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 // Handle for reading the log file that is source of logging data. | 77 // Handle for reading the log file that is source of logging data. |
| 78 base::File file_; | 78 base::File file_; |
| 79 | 79 |
| 80 // File system inode value that was associated with |log_file_path_| when it | 80 // File system inode value that was associated with |log_file_path_| when it |
| 81 // was originally opened for reading. | 81 // was originally opened for reading. |
| 82 ino_t file_inode_; | 82 ino_t file_inode_; |
| 83 | 83 |
| 84 // For removing PII from log results. | 84 // For removing PII from log results. |
| 85 feedback::AnonymizerTool anonymizer_; | 85 feedback::AnonymizerTool anonymizer_; |
| 86 | 86 |
| 87 base::WeakPtrFactory<SingleLogSource> weak_ptr_factory_; | 87 base::WeakPtrFactory<SingleLogFileLogSource> weak_ptr_factory_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(SingleLogSource); | 89 DISALLOW_COPY_AND_ASSIGN(SingleLogFileLogSource); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace system_logs | 92 } // namespace system_logs |
| 93 | 93 |
| 94 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ | 94 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_FILE_LOG_SOURCE_H_ |
| OLD | NEW |