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

Introduce Session Log Manager

This change introduces the SessionLogManager class. The
SessionLogManager owns the various logging classes and will be
responsible for constructing the session log when requested by the user.

Bug: 1128204
Change-Id: I4c41effce7d1faf99f2c68c773642e44aec18dfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2632870
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844967}
parent 1a592fb9
...@@ -18,6 +18,8 @@ static_library("backend") { ...@@ -18,6 +18,8 @@ static_library("backend") {
"power_manager_client_conversions.h", "power_manager_client_conversions.h",
"routine_log.cc", "routine_log.cc",
"routine_log.h", "routine_log.h",
"session_log_handler.cc",
"session_log_handler.h",
"system_data_provider.cc", "system_data_provider.cc",
"system_data_provider.h", "system_data_provider.h",
"system_routine_controller.cc", "system_routine_controller.cc",
......
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/diagnostics_ui/backend/session_log_handler.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/strings/strcat.h"
#include "chromeos/components/diagnostics_ui/backend/routine_log.h"
#include "chromeos/components/diagnostics_ui/backend/telemetry_log.h"
namespace chromeos {
namespace diagnostics {
namespace {
const char kRoutineLogSectionHeader[] = "=== Routine Log === \n";
const char kTelemetryLogSectionHeader[] = "=== Telemetry Log === \n";
const char kRoutineLogPath[] = "/var/log/diagnostics_routine_log";
} // namespace
SessionLogHandler::SessionLogHandler()
: SessionLogHandler(base::FilePath(kRoutineLogPath)) {}
SessionLogHandler::~SessionLogHandler() = default;
SessionLogHandler::SessionLogHandler(const base::FilePath& routine_log_path)
: telemetry_log_(std::make_unique<TelemetryLog>()),
routine_log_(std::make_unique<RoutineLog>(routine_log_path)) {}
TelemetryLog* SessionLogHandler::GetTelemetryLog() const {
return telemetry_log_.get();
}
RoutineLog* SessionLogHandler::GetRoutineLog() const {
return routine_log_.get();
}
bool SessionLogHandler::CreateSessionLog(const base::FilePath& file_path) {
// Fetch RoutineLog
const std::string routine_log_contents = routine_log_->GetContents();
// Fetch TelemetryLog
const std::string telemetry_log_contents = telemetry_log_->GetContents();
const std::string combined_contents =
base::StrCat({kTelemetryLogSectionHeader, telemetry_log_contents,
kRoutineLogSectionHeader, routine_log_contents});
return base::WriteFile(file_path, combined_contents);
}
} // namespace diagnostics
} // namespace chromeos
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_SESSION_LOG_HANDLER_H_
#define CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_SESSION_LOG_HANDLER_H_
#include <memory>
namespace base {
class FilePath;
} // namespace base
namespace chromeos {
namespace diagnostics {
class TelemetryLog;
class RoutineLog;
class SessionLogHandler {
public:
SessionLogHandler();
~SessionLogHandler();
// Constructor for testing, allowing an injected `routine_log_path`. Should
// not be called outside of tests.
SessionLogHandler(const base::FilePath& routine_log_path);
SessionLogHandler(const SessionLogHandler&) = delete;
SessionLogHandler& operator=(const SessionLogHandler&) = delete;
TelemetryLog* GetTelemetryLog() const;
RoutineLog* GetRoutineLog() const;
private:
// Creates a session log at `file_path`. The session log includes the contents
// of both `telemetry_log_` and `routine_log_`. Returns true if the file was
// successfully written. Retrns false otherwise.
bool CreateSessionLog(const base::FilePath& file_path);
std::unique_ptr<TelemetryLog> telemetry_log_;
std::unique_ptr<RoutineLog> routine_log_;
};
} // namespace diagnostics
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_BACKEND_SESSION_LOG_HANDLER_H_
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