Commit 18771b95 authored by Jenny Zhang's avatar Jenny Zhang Committed by Commit Bot

Attach lacros user log to ash feedback report.

Enable ash to read and send lacros user log in the feedback report.
This helps to collect lacros log in case lacros crashes or
being terminated for some reason. User can still send feedback via
ash-chrome ui or "alt-shift-i".

TBR=afakhry@chromium.org

Bug: 1119925
Change-Id: I1274f09f75b885627bd97ef165d55861bb7ead5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2393235
Commit-Queue: Jenny Zhang <jennyz@chromium.org>
Reviewed-by: default avatarMiriam Zimmerman <mutexlox@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804524}
parent aa616dc5
...@@ -4115,14 +4115,19 @@ static_library("browser") { ...@@ -4115,14 +4115,19 @@ static_library("browser") {
] ]
} }
if (is_chromeos || chromeos_is_browser_only) {
sources += [
"feedback/system_logs/log_sources/user_log_files_log_source.cc",
"feedback/system_logs/log_sources/user_log_files_log_source.h",
]
}
# TODO(crbug.com/1052397): Rename chromeos_is_browser_only to is_lacros. # TODO(crbug.com/1052397): Rename chromeos_is_browser_only to is_lacros.
if (chromeos_is_browser_only) { if (chromeos_is_browser_only) {
assert(enable_native_notifications) assert(enable_native_notifications)
sources += [ sources += [
"lacros/lacros_chrome_service_delegate_impl.cc", "lacros/lacros_chrome_service_delegate_impl.cc",
"lacros/lacros_chrome_service_delegate_impl.h", "lacros/lacros_chrome_service_delegate_impl.h",
"lacros/system_logs/user_log_files_log_source.cc",
"lacros/system_logs/user_log_files_log_source.h",
"metrics/lacros_metrics_provider.cc", "metrics/lacros_metrics_provider.cc",
"metrics/lacros_metrics_provider.h", "metrics/lacros_metrics_provider.h",
"notifications/notification_platform_bridge_chromeos.cc", "notifications/notification_platform_bridge_chromeos.cc",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/feedback/system_logs/system_logs_fetcher.h" #include "components/feedback/system_logs/system_logs_fetcher.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/crosapi/browser_util.h"
#include "chrome/browser/chromeos/system_logs/command_line_log_source.h" #include "chrome/browser/chromeos/system_logs/command_line_log_source.h"
#include "chrome/browser/chromeos/system_logs/dbus_log_source.h" #include "chrome/browser/chromeos/system_logs/dbus_log_source.h"
#include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h" #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h"
...@@ -24,14 +25,24 @@ ...@@ -24,14 +25,24 @@
#include "chrome/browser/chromeos/system_logs/shill_log_source.h" #include "chrome/browser/chromeos/system_logs/shill_log_source.h"
#include "chrome/browser/chromeos/system_logs/touch_log_source.h" #include "chrome/browser/chromeos/system_logs/touch_log_source.h"
#include "chrome/browser/chromeos/system_logs/ui_hierarchy_log_source.h" #include "chrome/browser/chromeos/system_logs/ui_hierarchy_log_source.h"
#include "chromeos/constants/chromeos_features.h"
#endif #endif
#if BUILDFLAG(IS_LACROS) #if defined(OS_CHROMEOS) || BUILDFLAG(IS_LACROS)
#include "chrome/browser/lacros/system_logs/user_log_files_log_source.h" #include "chrome/browser/feedback/system_logs/log_sources/user_log_files_log_source.h"
#endif #endif
namespace system_logs { namespace system_logs {
#if defined(OS_CHROMEOS) || BUILDFLAG(IS_LACROS)
namespace {
constexpr char kDefaultLogPath[] = "/home/chronos/user/lacros/lacros.log";
constexpr char kLacrosUserLogKey[] = "lacros_user_log";
} // namespace
#endif
SystemLogsFetcher* BuildChromeSystemLogsFetcher(bool scrub_data) { SystemLogsFetcher* BuildChromeSystemLogsFetcher(bool scrub_data) {
SystemLogsFetcher* fetcher = new SystemLogsFetcher( SystemLogsFetcher* fetcher = new SystemLogsFetcher(
scrub_data, extension_misc::kBuiltInFirstPartyExtensionIds); scrub_data, extension_misc::kBuiltInFirstPartyExtensionIds);
...@@ -56,9 +67,18 @@ SystemLogsFetcher* BuildChromeSystemLogsFetcher(bool scrub_data) { ...@@ -56,9 +67,18 @@ SystemLogsFetcher* BuildChromeSystemLogsFetcher(bool scrub_data) {
#endif #endif
#if BUILDFLAG(IS_LACROS) #if BUILDFLAG(IS_LACROS)
fetcher->AddSource(std::make_unique<UserLogFilesLogSource>()); fetcher->AddSource(std::make_unique<UserLogFilesLogSource>(
base::FilePath(kDefaultLogPath), kLacrosUserLogKey));
#endif #endif
#if defined(OS_CHROMEOS)
if (chromeos::features::IsLacrosSupportEnabled() &&
crosapi::browser_util::IsLacrosAllowed()) {
fetcher->AddSource(std::make_unique<UserLogFilesLogSource>(
base::FilePath(kDefaultLogPath), kLacrosUserLogKey));
}
#endif // OS_CHROMEOS
return fetcher; return fetcher;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/lacros/system_logs/user_log_files_log_source.h" #include "chrome/browser/feedback/system_logs/log_sources/user_log_files_log_source.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -14,9 +14,6 @@ namespace system_logs { ...@@ -14,9 +14,6 @@ namespace system_logs {
namespace { namespace {
constexpr char kDefaultLogPath[] = "/home/chronos/user/lacros/lacros.log";
constexpr char kLogKey[] = "lacros_user_log";
// Maximum buffer size for user logs in bytes. // Maximum buffer size for user logs in bytes.
const int64_t kMaxLogSize = 1024 * 1024; const int64_t kMaxLogSize = 1024 * 1024;
constexpr char kLogTruncated[] = "<earlier logs truncated>\n"; constexpr char kLogTruncated[] = "<earlier logs truncated>\n";
...@@ -24,8 +21,12 @@ constexpr char kNotAvailable[] = "<not available>"; ...@@ -24,8 +21,12 @@ constexpr char kNotAvailable[] = "<not available>";
} // namespace } // namespace
UserLogFilesLogSource::UserLogFilesLogSource() UserLogFilesLogSource::UserLogFilesLogSource(
: SystemLogsSource("UserLoggedFiles") {} const base::FilePath& log_file_path,
const std::string& log_key)
: SystemLogsSource("UserLoggedFiles"),
log_file_path_(log_file_path),
log_key_(log_key) {}
UserLogFilesLogSource::~UserLogFilesLogSource() = default; UserLogFilesLogSource::~UserLogFilesLogSource() = default;
...@@ -35,11 +36,10 @@ void UserLogFilesLogSource::Fetch(SysLogsSourceCallback callback) { ...@@ -35,11 +36,10 @@ void UserLogFilesLogSource::Fetch(SysLogsSourceCallback callback) {
auto response = std::make_unique<SystemLogsResponse>(); auto response = std::make_unique<SystemLogsResponse>();
auto* response_ptr = response.get(); auto* response_ptr = response.get();
const base::FilePath log_file_path = base::FilePath(kDefaultLogPath);
base::ThreadPool::PostTaskAndReply( base::ThreadPool::PostTaskAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&UserLogFilesLogSource::ReadFile, base::BindOnce(&UserLogFilesLogSource::ReadFile,
weak_ptr_factory_.GetWeakPtr(), log_file_path, kLogKey, weak_ptr_factory_.GetWeakPtr(), log_file_path_, log_key_,
response_ptr), response_ptr),
base::BindOnce(std::move(callback), std::move(response))); base::BindOnce(std::move(callback), std::move(response)));
} }
......
...@@ -2,28 +2,25 @@ ...@@ -2,28 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_LACROS_SYSTEM_LOGS_USER_LOG_FILES_LOG_SOURCE_H_ #ifndef CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_LOG_SOURCES_USER_LOG_FILES_LOG_SOURCE_H_
#define CHROME_BROWSER_LACROS_SYSTEM_LOGS_USER_LOG_FILES_LOG_SOURCE_H_ #define CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_LOG_SOURCES_USER_LOG_FILES_LOG_SOURCE_H_
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/feedback/system_logs/system_logs_source.h" #include "components/feedback/system_logs/system_logs_source.h"
namespace base {
class FilePath;
}
namespace system_logs { namespace system_logs {
// This class gathers log data from Lacros user log files. // This class gathers log data from user log files.
class UserLogFilesLogSource : public SystemLogsSource { class UserLogFilesLogSource : public SystemLogsSource {
public: public:
UserLogFilesLogSource(); UserLogFilesLogSource(const base::FilePath& log_file_path,
const std::string& log_key);
UserLogFilesLogSource(const UserLogFilesLogSource&) = delete; UserLogFilesLogSource(const UserLogFilesLogSource&) = delete;
~UserLogFilesLogSource() override;
UserLogFilesLogSource& operator=(const UserLogFilesLogSource&) = delete; UserLogFilesLogSource& operator=(const UserLogFilesLogSource&) = delete;
~UserLogFilesLogSource() override;
// SystemLogsSource override: // SystemLogsSource override:
void Fetch(SysLogsSourceCallback callback) override; void Fetch(SysLogsSourceCallback callback) override;
...@@ -33,9 +30,12 @@ class UserLogFilesLogSource : public SystemLogsSource { ...@@ -33,9 +30,12 @@ class UserLogFilesLogSource : public SystemLogsSource {
const std::string& log_key, const std::string& log_key,
SystemLogsResponse* response); SystemLogsResponse* response);
const base::FilePath log_file_path_;
const std::string log_key_;
base::WeakPtrFactory<UserLogFilesLogSource> weak_ptr_factory_{this}; base::WeakPtrFactory<UserLogFilesLogSource> weak_ptr_factory_{this};
}; };
} // namespace system_logs } // namespace system_logs
#endif // CHROME_BROWSER_LACROS_SYSTEM_LOGS_USER_LOG_FILES_LOG_SOURCE_H_ #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_LOG_SOURCES_USER_LOG_FILES_LOG_SOURCE_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