Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3887)

Unified Diff: chrome/browser/chromeos/system_logs/single_log_source.cc

Issue 2939543002: Refactor SingleLogSource for better test coverage (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system_logs/single_log_source.cc
diff --git a/chrome/browser/chromeos/system_logs/single_log_source.cc b/chrome/browser/chromeos/system_logs/single_log_source.cc
index 826dd20a868b330a163730a3e560d54878c3001e..22eedff884c1028f03462e8bf20ab249441c0462 100644
--- a/chrome/browser/chromeos/system_logs/single_log_source.cc
+++ b/chrome/browser/chromeos/system_logs/single_log_source.cc
@@ -13,23 +13,28 @@ namespace system_logs {
namespace {
-// Converts a logs source type to the corresponding filename. In the future, if
-// non-file source types are added, this function should return an empty string.
-std::string GetLogFileSourceFilename(SingleLogSource::SupportedSource source) {
+const char kDefaultSystemLogDirPath[] = "/var/log";
+
+// Converts a logs source type to the corresponding file path, relative to the
+// base system log directory path. In the future, if non-file source types are
+// added, this function should return an empty file path.
+base::FilePath GetLogFileSourceRelativeFilePath(
+ SingleLogSource::SupportedSource source) {
switch (source) {
case SingleLogSource::SupportedSource::kMessages:
- return "/var/log/messages";
+ return base::FilePath("messages");
case SingleLogSource::SupportedSource::kUiLatest:
- return "/var/log/ui/ui.LATEST";
+ return base::FilePath("ui/ui.LATEST");
}
NOTREACHED();
- return "";
+ return base::FilePath();
}
} // namespace
SingleLogSource::SingleLogSource(SupportedSource source)
- : SystemLogsSource(GetLogFileSourceFilename(source)),
+ : SystemLogsSource(GetLogFileSourceRelativeFilePath(source).value()),
+ log_file_dir_path_(kDefaultSystemLogDirPath),
num_bytes_read_(0),
weak_ptr_factory_(this) {}
@@ -51,7 +56,7 @@ void SingleLogSource::Fetch(const SysLogsSourceCallback& callback) {
void SingleLogSource::ReadFile(SystemLogsResponse* result) {
// Attempt to open the file if it was not previously opened.
if (!file_.IsValid()) {
- file_.Initialize(base::FilePath(source_name()),
+ file_.Initialize(base::FilePath(log_file_dir_path_).Append(source_name()),
base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!file_.IsValid())
return;

Powered by Google App Engine
This is Rietveld 408576698