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