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