| 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_SOURCE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/types.h> |
| 9 | 10 |
| 10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "chrome/browser/feedback/system_logs/system_logs_fetcher.h" | 13 #include "chrome/browser/feedback/system_logs/system_logs_fetcher.h" |
| 13 #include "components/feedback/anonymizer_tool.h" | 14 #include "components/feedback/anonymizer_tool.h" |
| 14 | 15 |
| 15 namespace system_logs { | 16 namespace system_logs { |
| 16 | 17 |
| 17 // Gathers log data from a single source, possibly incrementally. | 18 // Gathers log data from a single source, possibly incrementally. |
| 18 class SingleLogSource : public SystemLogsSource { | 19 class SingleLogSource : public SystemLogsSource { |
| 19 public: | 20 public: |
| 20 enum class SupportedSource { | 21 enum class SupportedSource { |
| 21 // For /var/log/messages. | 22 // For /var/log/messages. |
| 22 kMessages, | 23 kMessages, |
| 23 | 24 |
| 24 // For /var/log/ui/ui.LATEST. | 25 // For /var/log/ui/ui.LATEST. |
| 25 kUiLatest, | 26 kUiLatest, |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 explicit SingleLogSource(SupportedSource source); | 29 explicit SingleLogSource(SupportedSource source); |
| 29 ~SingleLogSource() override; | 30 ~SingleLogSource() override; |
| 30 | 31 |
| 31 // system_logs::SystemLogsSource: | 32 // system_logs::SystemLogsSource: |
| 32 void Fetch(const SysLogsSourceCallback& callback) override; | 33 void Fetch(const SysLogsSourceCallback& callback) override; |
| 33 | 34 |
| 34 private: | 35 private: |
| 35 friend class SingleLogSourceTest; | 36 friend class SingleLogSourceTest; |
| 36 | 37 |
| 38 // Returns the full path of the log file. |
| 39 base::FilePath GetLogFilePath() const; |
| 40 |
| 37 // Reads all available content from |file_| that has not already been read. | 41 // Reads all available content from |file_| that has not already been read. |
| 38 void ReadFile(SystemLogsResponse* result); | 42 // Stores results as a single entry in |result|, with |source_name()| as key |
| 43 // and the read log contents as value. |
| 44 // |
| 45 // Handles rotation of underlying log file by reading all remaining contents |
| 46 // of old file and then opening and reading from new file. |
| 47 // |
| 48 // |num_rotations_allowed| limits the number of rotations that can take place |
| 49 // before the function returns. This avoids this function never returning due |
| 50 // to indefinitely repeated log file rotation. If this number is exceeded |
| 51 // during a call, ReadFile() stops checking for log file rotation for the |
| 52 // remainder of its execution. Any further rotation could result in missed log |
| 53 // data. |
| 54 void ReadFile(size_t num_rotations_allowed, SystemLogsResponse* result); |
| 39 | 55 |
| 40 // Path to system log file directory. | 56 // Path to system log file directory. |
| 41 base::FilePath log_file_dir_path_; | 57 base::FilePath log_file_dir_path_; |
| 42 | 58 |
| 43 // Keeps track of how much data has been read from |file_|. | 59 // Keeps track of how much data has been read from |file_|. |
| 44 size_t num_bytes_read_; | 60 size_t num_bytes_read_; |
| 45 | 61 |
| 46 // Handle for reading the log file that is source of logging data. | 62 // Handle for reading the log file that is source of logging data. |
| 47 base::File file_; | 63 base::File file_; |
| 48 | 64 |
| 65 // File system inode value that was associated with |log_file_path_| when it |
| 66 // was originally opened for reading. |
| 67 ino_t file_inode_; |
| 68 |
| 49 // For removing PII from log results. | 69 // For removing PII from log results. |
| 50 feedback::AnonymizerTool anonymizer_; | 70 feedback::AnonymizerTool anonymizer_; |
| 51 | 71 |
| 52 base::WeakPtrFactory<SingleLogSource> weak_ptr_factory_; | 72 base::WeakPtrFactory<SingleLogSource> weak_ptr_factory_; |
| 53 | 73 |
| 54 DISALLOW_COPY_AND_ASSIGN(SingleLogSource); | 74 DISALLOW_COPY_AND_ASSIGN(SingleLogSource); |
| 55 }; | 75 }; |
| 56 | 76 |
| 57 } // namespace system_logs | 77 } // namespace system_logs |
| 58 | 78 |
| 59 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ | 79 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SINGLE_LOG_SOURCE_H_ |
| OLD | NEW |