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