1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/system_logs/iwlwifi_dump_log_source.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/task/thread_pool.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
namespace system_logs {
namespace {
constexpr char kIwlwifiDumpLocation[] = "/var/log/last_iwlwifi_dump";
std::unique_ptr<SystemLogsResponse> CheckExistenceOnBlockingTaskRunner() {
auto result = std::make_unique<SystemLogsResponse>();
if (base::PathExists(base::FilePath(kIwlwifiDumpLocation))) {
result->emplace(
kIwlwifiDumpKey,
l10n_util::GetStringUTF8(IDS_FEEDBACK_IWLWIFI_DEBUG_DUMP_EXPLAINER));
}
return result;
}
std::unique_ptr<SystemLogsResponse> ReadDumpOnBlockingTaskRunner() {
auto result = std::make_unique<SystemLogsResponse>();
std::string contents;
if (base::ReadFileToString(base::FilePath(kIwlwifiDumpLocation), &contents))
result->emplace(kIwlwifiDumpKey, std::move(contents));
return result;
}
} // namespace
IwlwifiDumpChecker::IwlwifiDumpChecker()
: SystemLogsSource("IwlwifiDumpChecker") {}
IwlwifiDumpChecker::~IwlwifiDumpChecker() = default;
void IwlwifiDumpChecker::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null());
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&CheckExistenceOnBlockingTaskRunner), std::move(callback));
}
IwlwifiDumpLogSource::IwlwifiDumpLogSource()
: SystemLogsSource("IwlwifiDump") {}
IwlwifiDumpLogSource::~IwlwifiDumpLogSource() = default;
void IwlwifiDumpLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null());
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&ReadDumpOnBlockingTaskRunner), std::move(callback));
}
bool ContainsIwlwifiLogs(const FeedbackCommon::SystemLogsMap* sys_logs) {
return sys_logs->count(kIwlwifiDumpKey);
}
} // namespace system_logs
|