Commit 48c80c1f authored by Chris Morin's avatar Chris Morin Committed by Commit Bot

Refactor feedback code

List of changes:
* restructure FeedbackPrivateDelegate to have a more generic interface
* remove unecessary use of unique_ptrs
* change instances of RepeatingCallback to OnceCallback
* factor common DebugDaemonLogSource callback functionality into one callback
* use move semantics to avoid large string copies

BUG=None
TEST=Ensure feedback report upload works

Change-Id: I5b33ab60c727e2a92a08a463e9ad874e5e72b3d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560516Reviewed-by: default avatarChris Morin <cmtm@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Chris Morin <cmtm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650420}
parent 782696dd
...@@ -89,25 +89,31 @@ void DebugDaemonLogSource::Fetch(SysLogsSourceCallback callback) { ...@@ -89,25 +89,31 @@ void DebugDaemonLogSource::Fetch(SysLogsSourceCallback callback) {
client->GetRoutes(true, // Numeric client->GetRoutes(true, // Numeric
false, // No IPv6 false, // No IPv6
base::Bind(&DebugDaemonLogSource::OnGetRoutes, base::BindOnce(&DebugDaemonLogSource::OnGetRoutes,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
++num_pending_requests_; ++num_pending_requests_;
client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus,
weak_ptr_factory_.GetWeakPtr())); client->GetNetworkStatus(base::BindOnce(&DebugDaemonLogSource::OnGetOneLog,
weak_ptr_factory_.GetWeakPtr(),
kNetworkStatusKeyName));
++num_pending_requests_; ++num_pending_requests_;
client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus,
weak_ptr_factory_.GetWeakPtr())); client->GetModemStatus(base::BindOnce(&DebugDaemonLogSource::OnGetOneLog,
weak_ptr_factory_.GetWeakPtr(),
kModemStatusKeyName));
++num_pending_requests_; ++num_pending_requests_;
client->GetWiMaxStatus(base::Bind(&DebugDaemonLogSource::OnGetWiMaxStatus,
weak_ptr_factory_.GetWeakPtr())); client->GetWiMaxStatus(base::BindOnce(&DebugDaemonLogSource::OnGetOneLog,
weak_ptr_factory_.GetWeakPtr(),
kWiMaxStatusKeyName));
++num_pending_requests_; ++num_pending_requests_;
if (scrub_) { if (scrub_) {
client->GetScrubbedBigLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs, client->GetScrubbedBigLogs(base::BindOnce(&DebugDaemonLogSource::OnGetLogs,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} else { } else {
client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs, client->GetAllLogs(base::BindOnce(&DebugDaemonLogSource::OnGetLogs,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
++num_pending_requests_; ++num_pending_requests_;
} }
...@@ -122,28 +128,11 @@ void DebugDaemonLogSource::OnGetRoutes( ...@@ -122,28 +128,11 @@ void DebugDaemonLogSource::OnGetRoutes(
RequestCompleted(); RequestCompleted();
} }
void DebugDaemonLogSource::OnGetNetworkStatus( void DebugDaemonLogSource::OnGetOneLog(std::string key,
base::Optional<std::string> status) { base::Optional<std::string> status) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(*response_)[kNetworkStatusKeyName] =
std::move(status).value_or(kNotAvailable);
RequestCompleted();
}
void DebugDaemonLogSource::OnGetModemStatus(
base::Optional<std::string> status) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(*response_)[kModemStatusKeyName] = std::move(status).value_or(kNotAvailable);
RequestCompleted();
}
void DebugDaemonLogSource::OnGetWiMaxStatus(
base::Optional<std::string> status) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(*response_)[kWiMaxStatusKeyName] = std::move(status).value_or(kNotAvailable); (*response_)[std::move(key)] = std::move(status).value_or(kNotAvailable);
RequestCompleted(); RequestCompleted();
} }
......
...@@ -33,11 +33,9 @@ class DebugDaemonLogSource : public SystemLogsSource { ...@@ -33,11 +33,9 @@ class DebugDaemonLogSource : public SystemLogsSource {
private: private:
typedef std::map<std::string, std::string> KeyValueMap; typedef std::map<std::string, std::string> KeyValueMap;
// Callbacks for the 5 different dbus calls to debugd. // Callbacks for the dbus calls to debugd.
void OnGetRoutes(base::Optional<std::vector<std::string>> routes); void OnGetRoutes(base::Optional<std::vector<std::string>> routes);
void OnGetNetworkStatus(base::Optional<std::string> status); void OnGetOneLog(std::string key, base::Optional<std::string> status);
void OnGetModemStatus(base::Optional<std::string> status);
void OnGetWiMaxStatus(base::Optional<std::string> status);
void OnGetLogs(bool succeeded, void OnGetLogs(bool succeeded,
const KeyValueMap& logs); const KeyValueMap& logs);
......
...@@ -15,7 +15,6 @@ namespace system_logs { ...@@ -15,7 +15,6 @@ namespace system_logs {
namespace { namespace {
constexpr char kIwlwifiDumpKey[] = "iwlwifi_dump";
constexpr char kIwlwifiDumpLocation[] = "/var/log/last_iwlwifi_dump"; constexpr char kIwlwifiDumpLocation[] = "/var/log/last_iwlwifi_dump";
std::unique_ptr<SystemLogsResponse> CheckExistenceOnBlockingTaskRunner() { std::unique_ptr<SystemLogsResponse> CheckExistenceOnBlockingTaskRunner() {
...@@ -70,20 +69,8 @@ void IwlwifiDumpLogSource::Fetch(SysLogsSourceCallback callback) { ...@@ -70,20 +69,8 @@ void IwlwifiDumpLogSource::Fetch(SysLogsSourceCallback callback) {
base::BindOnce(std::move(callback))); base::BindOnce(std::move(callback)));
} }
bool ContainsIwlwifiLogs(FeedbackCommon::SystemLogsMap* sys_logs) { bool ContainsIwlwifiLogs(const FeedbackCommon::SystemLogsMap* sys_logs) {
return sys_logs->count(kIwlwifiDumpKey); return sys_logs->count(kIwlwifiDumpKey);
} }
void MergeIwlwifiLogs(
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs,
system_logs::SysLogsFetcherCallback callback,
std::unique_ptr<system_logs::SystemLogsResponse> fetched_iwlwifi_response) {
if (fetched_iwlwifi_response->count(kIwlwifiDumpKey)) {
(*original_sys_logs)[kIwlwifiDumpKey] =
std::move(fetched_iwlwifi_response->at(kIwlwifiDumpKey));
}
std::move(callback).Run(std::move(original_sys_logs));
}
} // namespace system_logs } // namespace system_logs
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace system_logs { namespace system_logs {
constexpr char kIwlwifiDumpKey[] = "iwlwifi_dump";
// The classes here are used to attach debug dump information from // The classes here are used to attach debug dump information from
// Intel Wi-Fi NICs that will be produced when those NICs have issues // Intel Wi-Fi NICs that will be produced when those NICs have issues
// such as firmware crashes. This information will be used to help // such as firmware crashes. This information will be used to help
...@@ -49,16 +51,7 @@ class IwlwifiDumpLogSource : public SystemLogsSource { ...@@ -49,16 +51,7 @@ class IwlwifiDumpLogSource : public SystemLogsSource {
}; };
// Checks to see if |sys_logs| contains the iwlwifi logs key. // Checks to see if |sys_logs| contains the iwlwifi logs key.
bool ContainsIwlwifiLogs(FeedbackCommon::SystemLogsMap* sys_logs); bool ContainsIwlwifiLogs(const FeedbackCommon::SystemLogsMap* sys_logs);
// This should be passed as a callback to the fetcher that will fetch logs
// from the IwlwifiDumpLogSource above. It will merge the
// |fetched_iwlwifi_response| into the |original_sys_logs| and call the
// |callback| with that result.
void MergeIwlwifiLogs(
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs,
system_logs::SysLogsFetcherCallback callback,
std::unique_ptr<system_logs::SystemLogsResponse> fetched_iwlwifi_response);
} // namespace system_logs } // namespace system_logs
......
...@@ -177,24 +177,34 @@ ChromeFeedbackPrivateDelegate::CreateSingleLogSource( ...@@ -177,24 +177,34 @@ ChromeFeedbackPrivateDelegate::CreateSingleLogSource(
} }
} }
void ChromeFeedbackPrivateDelegate::FetchAndMergeIwlwifiDumpLogsIfPresent( void OnFetchedExtraLogs(
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs, scoped_refptr<feedback::FeedbackData> feedback_data,
content::BrowserContext* context, FetchExtraLogsCallback callback,
system_logs::SysLogsFetcherCallback callback) const { std::unique_ptr<system_logs::SystemLogsResponse> response) {
if (!original_sys_logs || using system_logs::kIwlwifiDumpKey;
!system_logs::ContainsIwlwifiLogs(original_sys_logs.get())) { if (response && response->count(kIwlwifiDumpKey)) {
VLOG(1) << "WiFi dump logs are not present."; feedback_data->AddLog(kIwlwifiDumpKey,
std::move(callback).Run(std::move(original_sys_logs)); std::move(response->at(kIwlwifiDumpKey)));
return;
} }
std::move(callback).Run(feedback_data);
}
VLOG(1) << "Fetching WiFi dump logs."; void ChromeFeedbackPrivateDelegate::FetchExtraLogs(
system_logs::SystemLogsFetcher* fetcher = scoped_refptr<feedback::FeedbackData> feedback_data,
new system_logs::SystemLogsFetcher(true /* scrub_data */); FetchExtraLogsCallback callback) const {
fetcher->AddSource(std::make_unique<system_logs::IwlwifiDumpLogSource>()); // Anonymize data.
fetcher->Fetch(base::BindOnce(&system_logs::MergeIwlwifiLogs, constexpr bool scrub = true;
std::move(original_sys_logs),
std::move(callback))); if (system_logs::ContainsIwlwifiLogs(feedback_data->sys_info())) {
VLOG(1) << "Fetching WiFi dump logs.";
system_logs::SystemLogsFetcher* fetcher =
new system_logs::SystemLogsFetcher(scrub);
fetcher->AddSource(std::make_unique<system_logs::IwlwifiDumpLogSource>());
fetcher->Fetch(base::BindOnce(&OnFetchedExtraLogs, feedback_data,
std::move(callback)));
} else {
VLOG(1) << "WiFi dump logs are not present.";
}
} }
void ChromeFeedbackPrivateDelegate::UnloadFeedbackExtension( void ChromeFeedbackPrivateDelegate::UnloadFeedbackExtension(
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_CHROME_FEEDBACK_PRIVATE_DELEGATE_H_ #ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_CHROME_FEEDBACK_PRIVATE_DELEGATE_H_
#define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_CHROME_FEEDBACK_PRIVATE_DELEGATE_H_ #define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_CHROME_FEEDBACK_PRIVATE_DELEGATE_H_
#include "components/feedback/feedback_common.h" #include "components/feedback/feedback_data.h"
#include "extensions/browser/api/feedback_private/feedback_private_delegate.h" #include "extensions/browser/api/feedback_private/feedback_private_delegate.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -26,10 +26,8 @@ class ChromeFeedbackPrivateDelegate : public FeedbackPrivateDelegate { ...@@ -26,10 +26,8 @@ class ChromeFeedbackPrivateDelegate : public FeedbackPrivateDelegate {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource( std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource(
api::feedback_private::LogSource source_type) const override; api::feedback_private::LogSource source_type) const override;
void FetchAndMergeIwlwifiDumpLogsIfPresent( void FetchExtraLogs(scoped_refptr<feedback::FeedbackData> feedback_data,
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs, FetchExtraLogsCallback callback) const override;
content::BrowserContext* context,
system_logs::SysLogsFetcherCallback callback) const override;
void UnloadFeedbackExtension(content::BrowserContext* context) const override; void UnloadFeedbackExtension(content::BrowserContext* context) const override;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
std::string GetSignedInUserEmail( std::string GetSignedInUserEmail(
......
...@@ -39,7 +39,9 @@ void OnGetSystemInformation( ...@@ -39,7 +39,9 @@ void OnGetSystemInformation(
feedback_data->set_context(profile); feedback_data->set_context(profile);
feedback_data->set_description(description); feedback_data->set_description(description);
feedback_data->SetAndCompressSystemInfo(std::move(sys_info)); if (sys_info)
feedback_data->AddLogs(std::move(*sys_info));
feedback_data->CompressSystemInfo();
GetFeedbackService(profile)->SendFeedback(feedback_data, callback); GetFeedbackService(profile)->SendFeedback(feedback_data, callback);
} }
......
...@@ -50,11 +50,11 @@ const int kBigLogsDBusTimeoutMS = 120 * 1000; ...@@ -50,11 +50,11 @@ const int kBigLogsDBusTimeoutMS = 120 * 1000;
// the requester. // the requester.
class PipeReaderWrapper : public base::SupportsWeakPtr<PipeReaderWrapper> { class PipeReaderWrapper : public base::SupportsWeakPtr<PipeReaderWrapper> {
public: public:
explicit PipeReaderWrapper(const DebugDaemonClient::GetLogsCallback& callback) explicit PipeReaderWrapper(DebugDaemonClient::GetLogsCallback callback)
: pipe_reader_(base::CreateTaskRunnerWithTraits( : pipe_reader_(base::CreateTaskRunnerWithTraits(
{base::MayBlock(), {base::MayBlock(),
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})),
callback_(callback) {} callback_(std::move(callback)) {}
base::ScopedFD Initialize() { base::ScopedFD Initialize() {
return pipe_reader_.StartIO( return pipe_reader_.StartIO(
...@@ -92,9 +92,9 @@ class PipeReaderWrapper : public base::SupportsWeakPtr<PipeReaderWrapper> { ...@@ -92,9 +92,9 @@ class PipeReaderWrapper : public base::SupportsWeakPtr<PipeReaderWrapper> {
void RunCallbackAndDestroy( void RunCallbackAndDestroy(
base::Optional<std::map<std::string, std::string>> result) { base::Optional<std::map<std::string, std::string>> result) {
if (result.has_value()) { if (result.has_value()) {
callback_.Run(true, result.value()); std::move(callback_).Run(true, std::move(result.value()));
} else { } else {
callback_.Run(false, std::map<std::string, std::string>()); std::move(callback_).Run(false, std::map<std::string, std::string>());
} }
delete this; delete this;
} }
...@@ -236,22 +236,22 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -236,22 +236,22 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void GetScrubbedLogs(const GetLogsCallback& callback) override { void GetScrubbedLogs(GetLogsCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetFeedbackLogs); debugd::kGetFeedbackLogs);
debugdaemon_proxy_->CallMethod( debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetAllLogs, base::BindOnce(&DebugDaemonClientImpl::OnGetAllLogs,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void GetScrubbedBigLogs(const GetLogsCallback& callback) override { void GetScrubbedBigLogs(GetLogsCallback callback) override {
// The PipeReaderWrapper is a self-deleting object; we don't have to worry // The PipeReaderWrapper is a self-deleting object; we don't have to worry
// about ownership or lifetime. We need to create a new one for each Big // about ownership or lifetime. We need to create a new one for each Big
// Logs requests in order to queue these requests. One request can take a // Logs requests in order to queue these requests. One request can take a
// long time to be processed and a new request should never be ignored nor // long time to be processed and a new request should never be ignored nor
// cancels the on-going one. // cancels the on-going one.
PipeReaderWrapper* pipe_reader = new PipeReaderWrapper(callback); PipeReaderWrapper* pipe_reader = new PipeReaderWrapper(std::move(callback));
base::ScopedFD pipe_write_end = pipe_reader->Initialize(); base::ScopedFD pipe_write_end = pipe_reader->Initialize();
dbus::MethodCall method_call(debugd::kDebugdInterface, dbus::MethodCall method_call(debugd::kDebugdInterface,
...@@ -267,22 +267,22 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -267,22 +267,22 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
pipe_reader->AsWeakPtr())); pipe_reader->AsWeakPtr()));
} }
void GetAllLogs(const GetLogsCallback& callback) override { void GetAllLogs(GetLogsCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetAllLogs); debugd::kGetAllLogs);
debugdaemon_proxy_->CallMethod( debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetAllLogs, base::BindOnce(&DebugDaemonClientImpl::OnGetAllLogs,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void GetUserLogFiles(const GetLogsCallback& callback) override { void GetUserLogFiles(GetLogsCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetUserLogFiles); debugd::kGetUserLogFiles);
debugdaemon_proxy_->CallMethod( debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetUserLogFiles, base::BindOnce(&DebugDaemonClientImpl::OnGetUserLogFiles,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void GetLog(const std::string& log_name, void GetLog(const std::string& log_name,
...@@ -605,13 +605,12 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -605,13 +605,12 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
std::move(callback).Run(std::move(routes)); std::move(callback).Run(std::move(routes));
} }
void OnGetAllLogs(const GetLogsCallback& callback, void OnGetAllLogs(GetLogsCallback callback, dbus::Response* response) {
dbus::Response* response) {
std::map<std::string, std::string> logs; std::map<std::string, std::string> logs;
bool broken = false; // did we see a broken (k,v) pair? bool broken = false; // did we see a broken (k,v) pair?
dbus::MessageReader sub_reader(NULL); dbus::MessageReader sub_reader(NULL);
if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) {
callback.Run(false, logs); std::move(callback).Run(false, logs);
return; return;
} }
while (sub_reader.HasMoreData()) { while (sub_reader.HasMoreData()) {
...@@ -625,12 +624,11 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -625,12 +624,11 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
} }
logs[key] = value; logs[key] = value;
} }
callback.Run(!sub_reader.HasMoreData() && !broken, logs); std::move(callback).Run(!sub_reader.HasMoreData() && !broken, logs);
} }
void OnGetUserLogFiles(const GetLogsCallback& callback, void OnGetUserLogFiles(GetLogsCallback callback, dbus::Response* response) {
dbus::Response* response) { return OnGetAllLogs(std::move(callback), response);
return OnGetAllLogs(callback, response);
} }
void OnBigFeedbackLogsResponse(base::WeakPtr<PipeReaderWrapper> pipe_reader, void OnBigFeedbackLogsResponse(base::WeakPtr<PipeReaderWrapper> pipe_reader,
......
...@@ -90,22 +90,22 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) DebugDaemonClient ...@@ -90,22 +90,22 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) DebugDaemonClient
// Callback type for GetScrubbedLogs(), GetAllLogs() or GetUserLogFiles(). // Callback type for GetScrubbedLogs(), GetAllLogs() or GetUserLogFiles().
using GetLogsCallback = using GetLogsCallback =
base::Callback<void(bool succeeded, base::OnceCallback<void(bool succeeded,
const std::map<std::string, std::string>& logs)>; const std::map<std::string, std::string>& logs)>;
// Gets scrubbed logs from debugd. // Gets scrubbed logs from debugd.
virtual void GetScrubbedLogs(const GetLogsCallback& callback) = 0; virtual void GetScrubbedLogs(GetLogsCallback callback) = 0;
// Gets the scrubbed logs from debugd that are very large and cannot be // Gets the scrubbed logs from debugd that are very large and cannot be
// returned directly from D-Bus. These logs will include ARC and cheets // returned directly from D-Bus. These logs will include ARC and cheets
// system information. // system information.
virtual void GetScrubbedBigLogs(const GetLogsCallback& callback) = 0; virtual void GetScrubbedBigLogs(GetLogsCallback callback) = 0;
// Gets all logs collected by debugd. // Gets all logs collected by debugd.
virtual void GetAllLogs(const GetLogsCallback& callback) = 0; virtual void GetAllLogs(GetLogsCallback callback) = 0;
// Gets list of user log files that must be read by Chrome. // Gets list of user log files that must be read by Chrome.
virtual void GetUserLogFiles(const GetLogsCallback& callback) = 0; virtual void GetUserLogFiles(GetLogsCallback callback) = 0;
// Gets an individual log source provided by debugd. // Gets an individual log source provided by debugd.
virtual void GetLog(const std::string& log_name, virtual void GetLog(const std::string& log_name,
......
...@@ -114,34 +114,33 @@ void FakeDebugDaemonClient::GetPerfOutput( ...@@ -114,34 +114,33 @@ void FakeDebugDaemonClient::GetPerfOutput(
int file_descriptor, int file_descriptor,
DBusMethodCallback<uint64_t> error_callback) {} DBusMethodCallback<uint64_t> error_callback) {}
void FakeDebugDaemonClient::GetScrubbedLogs(const GetLogsCallback& callback) { void FakeDebugDaemonClient::GetScrubbedLogs(GetLogsCallback callback) {
std::map<std::string, std::string> sample; std::map<std::string, std::string> sample;
sample["Sample Scrubbed Log"] = "Your email address is xxxxxxxx"; sample["Sample Scrubbed Log"] = "Your email address is xxxxxxxx";
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, false, sample)); FROM_HERE, base::BindOnce(std::move(callback), false, sample));
} }
void FakeDebugDaemonClient::GetScrubbedBigLogs( void FakeDebugDaemonClient::GetScrubbedBigLogs(GetLogsCallback callback) {
const GetLogsCallback& callback) {
std::map<std::string, std::string> sample; std::map<std::string, std::string> sample;
sample["Sample Scrubbed Big Log"] = "Your email address is xxxxxxxx"; sample["Sample Scrubbed Big Log"] = "Your email address is xxxxxxxx";
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, false, sample)); FROM_HERE, base::BindOnce(std::move(callback), false, sample));
} }
void FakeDebugDaemonClient::GetAllLogs(const GetLogsCallback& callback) { void FakeDebugDaemonClient::GetAllLogs(GetLogsCallback callback) {
std::map<std::string, std::string> sample; std::map<std::string, std::string> sample;
sample["Sample Log"] = "Your email address is abc@abc.com"; sample["Sample Log"] = "Your email address is abc@abc.com";
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, false, sample)); FROM_HERE, base::BindOnce(std::move(callback), false, sample));
} }
void FakeDebugDaemonClient::GetUserLogFiles(const GetLogsCallback& callback) { void FakeDebugDaemonClient::GetUserLogFiles(GetLogsCallback callback) {
std::map<std::string, std::string> user_logs; std::map<std::string, std::string> user_logs;
user_logs["preferences"] = "Preferences"; user_logs["preferences"] = "Preferences";
user_logs["invalid_file"] = "Invalid File"; user_logs["invalid_file"] = "Invalid File";
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, true, user_logs)); FROM_HERE, base::BindOnce(std::move(callback), true, user_logs));
} }
void FakeDebugDaemonClient::GetLog(const std::string& log_name, void FakeDebugDaemonClient::GetLog(const std::string& log_name,
......
...@@ -53,12 +53,12 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeDebugDaemonClient ...@@ -53,12 +53,12 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeDebugDaemonClient
const std::vector<std::string>& perf_args, const std::vector<std::string>& perf_args,
int file_descriptor, int file_descriptor,
DBusMethodCallback<uint64_t> callback) override; DBusMethodCallback<uint64_t> callback) override;
void GetScrubbedLogs(const GetLogsCallback& callback) override; void GetScrubbedLogs(GetLogsCallback callback) override;
void GetScrubbedBigLogs(const GetLogsCallback& callback) override; void GetScrubbedBigLogs(GetLogsCallback callback) override;
void GetAllLogs(const GetLogsCallback& callback) override; void GetAllLogs(GetLogsCallback callback) override;
void GetLog(const std::string& log_name, void GetLog(const std::string& log_name,
DBusMethodCallback<std::string> callback) override; DBusMethodCallback<std::string> callback) override;
void GetUserLogFiles(const GetLogsCallback& callback) override; void GetUserLogFiles(GetLogsCallback callback) override;
void TestICMP(const std::string& ip_address, void TestICMP(const std::string& ip_address,
const TestICMPCallback& callback) override; const TestICMPCallback& callback) override;
void TestICMPWithOptions(const std::string& ip_address, void TestICMPWithOptions(const std::string& ip_address,
......
...@@ -131,8 +131,8 @@ void FeedbackCommon::AddFile(const std::string& filename, std::string data) { ...@@ -131,8 +131,8 @@ void FeedbackCommon::AddFile(const std::string& filename, std::string data) {
attachments_.emplace_back(filename, std::move(data)); attachments_.emplace_back(filename, std::move(data));
} }
void FeedbackCommon::AddLog(const std::string& name, const std::string& value) { void FeedbackCommon::AddLog(std::string name, std::string value) {
logs_[name] = value; logs_[std::move(name)] = std::move(value);
} }
void FeedbackCommon::AddLogs(SystemLogsMap logs) { void FeedbackCommon::AddLogs(SystemLogsMap logs) {
......
...@@ -40,7 +40,7 @@ class FeedbackCommon : public base::RefCountedThreadSafe<FeedbackCommon> { ...@@ -40,7 +40,7 @@ class FeedbackCommon : public base::RefCountedThreadSafe<FeedbackCommon> {
void AddFile(const std::string& filename, std::string data); void AddFile(const std::string& filename, std::string data);
void AddLog(const std::string& name, const std::string& value); void AddLog(std::string name, std::string value);
void AddLogs(SystemLogsMap logs); void AddLogs(SystemLogsMap logs);
// Fill in |feedback_data| with all the data that we have collected. // Fill in |feedback_data| with all the data that we have collected.
......
...@@ -53,8 +53,7 @@ void FeedbackData::OnFeedbackPageDataComplete() { ...@@ -53,8 +53,7 @@ void FeedbackData::OnFeedbackPageDataComplete() {
SendReport(); SendReport();
} }
void FeedbackData::SetAndCompressSystemInfo( void FeedbackData::CompressSystemInfo() {
std::unique_ptr<FeedbackData::SystemLogsMap> sys_info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (trace_id_ != 0) { if (trace_id_ != 0) {
...@@ -69,14 +68,11 @@ void FeedbackData::SetAndCompressSystemInfo( ...@@ -69,14 +68,11 @@ void FeedbackData::SetAndCompressSystemInfo(
} }
} }
if (sys_info) { ++pending_op_count_;
++pending_op_count_; base::PostTaskWithTraitsAndReply(
AddLogs(std::move(*sys_info)); FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::PostTaskWithTraitsAndReply( base::BindOnce(&FeedbackData::CompressLogs, this),
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, base::BindOnce(&FeedbackData::OnCompressComplete, this));
base::BindOnce(&FeedbackData::CompressLogs, this),
base::BindOnce(&FeedbackData::OnCompressComplete, this));
}
} }
void FeedbackData::SetAndCompressHistograms(std::string histograms) { void FeedbackData::SetAndCompressHistograms(std::string histograms) {
......
...@@ -30,9 +30,8 @@ class FeedbackData : public FeedbackCommon { ...@@ -30,9 +30,8 @@ class FeedbackData : public FeedbackCommon {
// Called once we've updated all the data from the feedback page. // Called once we've updated all the data from the feedback page.
void OnFeedbackPageDataComplete(); void OnFeedbackPageDataComplete();
// Sets the system information for this instance and kicks off its // Kicks off compression of the system information for this instance.
// compression. void CompressSystemInfo();
void SetAndCompressSystemInfo(std::unique_ptr<SystemLogsMap> sys_info);
// Sets the histograms for this instance and kicks off its // Sets the histograms for this instance and kicks off its
// compression. // compression.
......
...@@ -316,13 +316,10 @@ ExtensionFunction::ResponseAction FeedbackPrivateSendFeedbackFunction::Run() { ...@@ -316,13 +316,10 @@ ExtensionFunction::ResponseAction FeedbackPrivateSendFeedbackFunction::Run() {
feedback_data->set_screenshot_uuid(*feedback_info.screenshot_blob_uuid); feedback_data->set_screenshot_uuid(*feedback_info.screenshot_blob_uuid);
} }
auto sys_logs = std::make_unique<FeedbackData::SystemLogsMap>(); const bool send_histograms =
const SystemInformationList* sys_info = feedback_info.send_histograms && *feedback_info.send_histograms;
feedback_info.system_information.get(); const bool send_bluetooth_logs =
if (sys_info) { feedback_info.send_bluetooth_logs && *feedback_info.send_bluetooth_logs;
for (const SystemInformation& info : *sys_info)
sys_logs->emplace(info.key, info.value);
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
feedback_data->set_from_assistant(feedback_info.from_assistant && feedback_data->set_from_assistant(feedback_info.from_assistant &&
...@@ -330,31 +327,32 @@ ExtensionFunction::ResponseAction FeedbackPrivateSendFeedbackFunction::Run() { ...@@ -330,31 +327,32 @@ ExtensionFunction::ResponseAction FeedbackPrivateSendFeedbackFunction::Run() {
feedback_data->set_assistant_debug_info_allowed( feedback_data->set_assistant_debug_info_allowed(
feedback_info.assistant_debug_info_allowed && feedback_info.assistant_debug_info_allowed &&
*feedback_info.assistant_debug_info_allowed); *feedback_info.assistant_debug_info_allowed);
#endif // defined(OS_CHROMEOS)
delegate->FetchAndMergeIwlwifiDumpLogsIfPresent( if (params->feedback.system_information) {
std::move(sys_logs), browser_context(), for (SystemInformation& info : *params->feedback.system_information)
base::BindOnce( feedback_data->AddLog(std::move(info.key), std::move(info.value));
&FeedbackPrivateSendFeedbackFunction::OnAllLogsFetched, this, #if defined(OS_CHROMEOS)
feedback_data, delegate->FetchExtraLogs(
feedback_info.send_histograms && *feedback_info.send_histograms, feedback_data,
feedback_info.send_bluetooth_logs && base::BindOnce(&FeedbackPrivateSendFeedbackFunction::OnAllLogsFetched,
*feedback_info.send_bluetooth_logs)); this, send_histograms, send_bluetooth_logs));
#else return RespondLater();
OnAllLogsFetched(feedback_data, false /* send_histograms */,
false /* send_bluetooth_logs */, std::move(sys_logs));
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
}
OnAllLogsFetched(send_histograms, send_bluetooth_logs, feedback_data);
return RespondLater(); return RespondLater();
} }
void FeedbackPrivateSendFeedbackFunction::OnAllLogsFetched( void FeedbackPrivateSendFeedbackFunction::OnAllLogsFetched(
scoped_refptr<FeedbackData> feedback_data,
bool send_histograms, bool send_histograms,
bool send_bluetooth_logs, bool send_bluetooth_logs,
std::unique_ptr<system_logs::SystemLogsResponse> sys_logs) { scoped_refptr<feedback::FeedbackData> feedback_data) {
VLOG(1) << "All logs have been fetched. Proceeding with sending the report."; VLOG(1) << "All logs have been fetched. Proceeding with sending the report.";
feedback_data->SetAndCompressSystemInfo(std::move(sys_logs)); feedback_data->CompressSystemInfo();
if (send_histograms) { if (send_histograms) {
std::string histograms = std::string histograms =
......
...@@ -140,11 +140,9 @@ class FeedbackPrivateSendFeedbackFunction : public UIThreadExtensionFunction { ...@@ -140,11 +140,9 @@ class FeedbackPrivateSendFeedbackFunction : public UIThreadExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
private: private:
void OnAllLogsFetched( void OnAllLogsFetched(bool send_histograms,
scoped_refptr<feedback::FeedbackData> feedback_data, bool send_bluetooth_logs,
bool send_histograms, scoped_refptr<feedback::FeedbackData> feedback_data);
bool send_bluetooth_logs,
std::unique_ptr<FeedbackCommon::SystemLogsMap> sys_logs);
void OnCompleted(api::feedback_private::LandingPageType type, bool success); void OnCompleted(api::feedback_private::LandingPageType type, bool success);
}; };
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
#ifndef EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_DELEGATE_H_ #ifndef EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_DELEGATE_H_
#define EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_DELEGATE_H_ #define EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_DELEGATE_H_
#include "components/feedback/feedback_common.h" #include "base/callback.h"
#include "components/feedback/feedback_data.h"
#include "components/feedback/system_logs/system_logs_fetcher.h" #include "components/feedback/system_logs/system_logs_fetcher.h"
#include "extensions/common/api/feedback_private.h" #include "extensions/common/api/feedback_private.h"
...@@ -31,6 +32,9 @@ class SystemLogsSource; ...@@ -31,6 +32,9 @@ class SystemLogsSource;
namespace extensions { namespace extensions {
using FetchExtraLogsCallback =
base::OnceCallback<void(scoped_refptr<feedback::FeedbackData>)>;
// Delegate class for embedder-specific chrome.feedbackPrivate behavior. // Delegate class for embedder-specific chrome.feedbackPrivate behavior.
class FeedbackPrivateDelegate { class FeedbackPrivateDelegate {
public: public:
...@@ -53,12 +57,13 @@ class FeedbackPrivateDelegate { ...@@ -53,12 +57,13 @@ class FeedbackPrivateDelegate {
virtual std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource( virtual std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource(
api::feedback_private::LogSource source_type) const = 0; api::feedback_private::LogSource source_type) const = 0;
// Takes ownership of |original_sys_logs|, merges Intel Wi-Fi debug logs if // Gets logs that aren't passed to the sendFeedback function, but should be
// they exist, and passes the log map back via |callback|. // included in the feedback report. These currently consist of the Intel Wi-Fi
virtual void FetchAndMergeIwlwifiDumpLogsIfPresent( // debug logs (if they exist).
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs, // Modifies |feedback_data| and passes it on to |callback|.
content::BrowserContext* context, virtual void FetchExtraLogs(
system_logs::SysLogsFetcherCallback callback) const = 0; scoped_refptr<feedback::FeedbackData> feedback_data,
FetchExtraLogsCallback callback) const = 0;
// Unloads the feedback extension from the current profile, should only be // Unloads the feedback extension from the current profile, should only be
// called when feedback is complete for the login profile. // called when feedback is complete for the login profile.
......
...@@ -41,12 +41,11 @@ ShellFeedbackPrivateDelegate::CreateSingleLogSource( ...@@ -41,12 +41,11 @@ ShellFeedbackPrivateDelegate::CreateSingleLogSource(
return nullptr; return nullptr;
} }
void ShellFeedbackPrivateDelegate::FetchAndMergeIwlwifiDumpLogsIfPresent( void ShellFeedbackPrivateDelegate::FetchExtraLogs(
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs, scoped_refptr<feedback::FeedbackData> feedback_data,
content::BrowserContext* context, FetchExtraLogsCallback callback) const {
system_logs::SysLogsFetcherCallback callback) const {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
std::move(callback).Run(std::move(original_sys_logs)); std::move(callback).Run(feedback_data);
} }
void ShellFeedbackPrivateDelegate::UnloadFeedbackExtension( void ShellFeedbackPrivateDelegate::UnloadFeedbackExtension(
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef EXTENSIONS_SHELL_BROWSER_API_FEEDBACK_PRIVATE_SHELL_FEEDBACK_PRIVATE_DELEGATE_H_ #ifndef EXTENSIONS_SHELL_BROWSER_API_FEEDBACK_PRIVATE_SHELL_FEEDBACK_PRIVATE_DELEGATE_H_
#define EXTENSIONS_SHELL_BROWSER_API_FEEDBACK_PRIVATE_SHELL_FEEDBACK_PRIVATE_DELEGATE_H_ #define EXTENSIONS_SHELL_BROWSER_API_FEEDBACK_PRIVATE_SHELL_FEEDBACK_PRIVATE_DELEGATE_H_
#include "components/feedback/feedback_common.h" #include "components/feedback/feedback_data.h"
#include "extensions/browser/api/feedback_private/feedback_private_delegate.h" #include "extensions/browser/api/feedback_private/feedback_private_delegate.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -26,10 +26,8 @@ class ShellFeedbackPrivateDelegate : public FeedbackPrivateDelegate { ...@@ -26,10 +26,8 @@ class ShellFeedbackPrivateDelegate : public FeedbackPrivateDelegate {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource( std::unique_ptr<system_logs::SystemLogsSource> CreateSingleLogSource(
api::feedback_private::LogSource source_type) const override; api::feedback_private::LogSource source_type) const override;
void FetchAndMergeIwlwifiDumpLogsIfPresent( void FetchExtraLogs(scoped_refptr<feedback::FeedbackData> feedback_data,
std::unique_ptr<FeedbackCommon::SystemLogsMap> original_sys_logs, FetchExtraLogsCallback callback) const override;
content::BrowserContext* context,
system_logs::SysLogsFetcherCallback callback) const override;
void UnloadFeedbackExtension(content::BrowserContext* context) const override; void UnloadFeedbackExtension(content::BrowserContext* context) const override;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
std::string GetSignedInUserEmail( std::string GetSignedInUserEmail(
......
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