Commit e7360494 authored by Bailey Berro's avatar Bailey Berro Committed by Chromium LUCI CQ

Add RoutineLog::GetContents() Method

This change adds a GetContents() method to retrieve the current
routine log.


Bug: 1128204
Change-Id: If57dad4163dfce9843dffc4648fb728e73496807
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627965
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844944}
parent 86c6b722
...@@ -53,6 +53,17 @@ void RoutineLog::LogRoutineCompleted(mojom::RoutineType type, ...@@ -53,6 +53,17 @@ void RoutineLog::LogRoutineCompleted(mojom::RoutineType type,
AppendToLog(log_line.str()); AppendToLog(log_line.str());
} }
std::string RoutineLog::GetContents() const {
if (!base::PathExists(routine_log_file_path_)) {
return "";
}
std::string contents;
base::ReadFileToString(routine_log_file_path_, &contents);
return contents;
}
void RoutineLog::AppendToLog(const std::string& content) { void RoutineLog::AppendToLog(const std::string& content) {
base::AppendToFile(routine_log_file_path_, content.data(), content.size()); base::AppendToFile(routine_log_file_path_, content.data(), content.size());
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_ROUTINE_LOG_H_ #ifndef CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_ROUTINE_LOG_H_
#define CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_ROUTINE_LOG_H_ #define CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_ROUTINE_LOG_H_
#include <string>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chromeos/components/diagnostics_ui/mojom/system_routine_controller.mojom.h" #include "chromeos/components/diagnostics_ui/mojom/system_routine_controller.mojom.h"
...@@ -28,6 +30,9 @@ class RoutineLog { ...@@ -28,6 +30,9 @@ class RoutineLog {
void LogRoutineCompleted(mojom::RoutineType type, void LogRoutineCompleted(mojom::RoutineType type,
mojom::StandardRoutineResult result); mojom::StandardRoutineResult result);
// Returns the current RoutineLog as a string.
std::string GetContents() const;
private: private:
void AppendToLog(const std::string& content); void AppendToLog(const std::string& content);
......
...@@ -64,6 +64,7 @@ TEST_F(RoutineLogTest, Empty) { ...@@ -64,6 +64,7 @@ TEST_F(RoutineLogTest, Empty) {
RoutineLog log(log_path_); RoutineLog log(log_path_);
EXPECT_FALSE(base::PathExists(log_path_)); EXPECT_FALSE(base::PathExists(log_path_));
EXPECT_TRUE(log.GetContents().empty());
} }
TEST_F(RoutineLogTest, Basic) { TEST_F(RoutineLogTest, Basic) {
...@@ -73,8 +74,7 @@ TEST_F(RoutineLogTest, Basic) { ...@@ -73,8 +74,7 @@ TEST_F(RoutineLogTest, Basic) {
EXPECT_TRUE(base::PathExists(log_path_)); EXPECT_TRUE(base::PathExists(log_path_));
std::string contents; const std::string contents = log.GetContents();
base::ReadFileToString(log_path_, &contents);
const std::string first_line = GetLogLines(contents)[0]; const std::string first_line = GetLogLines(contents)[0];
const std::vector<std::string> first_line_contents = const std::vector<std::string> first_line_contents =
GetLogLineContents(first_line); GetLogLineContents(first_line);
...@@ -92,8 +92,7 @@ TEST_F(RoutineLogTest, TwoLine) { ...@@ -92,8 +92,7 @@ TEST_F(RoutineLogTest, TwoLine) {
mojom::StandardRoutineResult::kTestPassed); mojom::StandardRoutineResult::kTestPassed);
EXPECT_TRUE(base::PathExists(log_path_)); EXPECT_TRUE(base::PathExists(log_path_));
std::string contents; const std::string contents = log.GetContents();
base::ReadFileToString(log_path_, &contents);
const std::vector<std::string> log_lines = GetLogLines(contents); const std::vector<std::string> log_lines = GetLogLines(contents);
const std::string first_line = log_lines[0]; const std::string first_line = log_lines[0];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment