Commit 67fa5148 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Migrate SysLogsSourceCallback to OnceCallbacks

base::Callback has been deprecated in favor of base::OnceCallback and
base::RepeatingCallback. In the case of SysLogsSourceCallback it turns
out that it is sufficient to always use base::OnceCallback.
For this reason, all base::Bind calls are replaced with base::BindOnce.
As base::OnceCallback does not have a copy-constructor to protect the
single-call semantics, the value is std::move()ed in a couple of places.
This also means that callbacks need to be passed by value instead
of const-reference. See docs/callback.md for more details.

TBR=rdevlin.cronin@chromium.org

Bug: 787554, 714018
Change-Id: I557c4600b2d927d74345dceb6946b82b711c1cbc
Reviewed-on: https://chromium-review.googlesource.com/808706
Commit-Queue: Dominic Battré <battre@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarSimon Que <sque@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523848}
parent 449cb549
...@@ -98,7 +98,7 @@ CommandLineLogSource::CommandLineLogSource() : SystemLogsSource("CommandLine") { ...@@ -98,7 +98,7 @@ CommandLineLogSource::CommandLineLogSource() : SystemLogsSource("CommandLine") {
CommandLineLogSource::~CommandLineLogSource() { CommandLineLogSource::~CommandLineLogSource() {
} }
void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { void CommandLineLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -107,7 +107,7 @@ void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -107,7 +107,7 @@ void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) {
base::PostTaskWithTraitsAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::BindOnce(&ExecuteCommandLines, response_ptr), base::BindOnce(&ExecuteCommandLines, response_ptr),
base::BindOnce(callback, std::move(response))); base::BindOnce(std::move(callback), std::move(response)));
} }
} // namespace system_logs } // namespace system_logs
...@@ -18,7 +18,7 @@ class CommandLineLogSource : public SystemLogsSource { ...@@ -18,7 +18,7 @@ class CommandLineLogSource : public SystemLogsSource {
~CommandLineLogSource() override; ~CommandLineLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(CommandLineLogSource); DISALLOW_COPY_AND_ASSIGN(CommandLineLogSource);
......
...@@ -20,7 +20,7 @@ DBusLogSource::DBusLogSource() : SystemLogsSource("DBus") { ...@@ -20,7 +20,7 @@ DBusLogSource::DBusLogSource() : SystemLogsSource("DBus") {
DBusLogSource::~DBusLogSource() { DBusLogSource::~DBusLogSource() {
} }
void DBusLogSource::Fetch(const SysLogsSourceCallback& callback) { void DBusLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -31,7 +31,7 @@ void DBusLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -31,7 +31,7 @@ void DBusLogSource::Fetch(const SysLogsSourceCallback& callback) {
response->emplace(kDBusLogEntryLong, dbus::statistics::GetAsString( response->emplace(kDBusLogEntryLong, dbus::statistics::GetAsString(
dbus::statistics::SHOW_METHOD, dbus::statistics::SHOW_METHOD,
dbus::statistics::FORMAT_TOTALS)); dbus::statistics::FORMAT_TOTALS));
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
} // namespace system_logs } // namespace system_logs
...@@ -17,7 +17,7 @@ class DBusLogSource : public SystemLogsSource { ...@@ -17,7 +17,7 @@ class DBusLogSource : public SystemLogsSource {
~DBusLogSource() override; ~DBusLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& request) override; void Fetch(SysLogsSourceCallback request) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(DBusLogSource); DISALLOW_COPY_AND_ASSIGN(DBusLogSource);
......
...@@ -42,12 +42,12 @@ DebugDaemonLogSource::DebugDaemonLogSource(bool scrub) ...@@ -42,12 +42,12 @@ DebugDaemonLogSource::DebugDaemonLogSource(bool scrub)
DebugDaemonLogSource::~DebugDaemonLogSource() {} DebugDaemonLogSource::~DebugDaemonLogSource() {}
void DebugDaemonLogSource::Fetch(const SysLogsSourceCallback& callback) { void DebugDaemonLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
DCHECK(callback_.is_null()); DCHECK(callback_.is_null());
callback_ = callback; callback_ = std::move(callback);
chromeos::DebugDaemonClient* client = chromeos::DebugDaemonClient* client =
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
...@@ -153,7 +153,8 @@ void DebugDaemonLogSource::OnGetUserLogFiles( ...@@ -153,7 +153,8 @@ void DebugDaemonLogSource::OnGetUserLogFiles(
(*response_)[kUserLogFileKeyName] = kNotAvailable; (*response_)[kUserLogFileKeyName] = kNotAvailable;
auto response = std::make_unique<SystemLogsResponse>(); auto response = std::make_unique<SystemLogsResponse>();
std::swap(response, response_); std::swap(response, response_);
callback_.Run(std::move(response)); DCHECK(!callback_.is_null());
std::move(callback_).Run(std::move(response));
} }
} }
...@@ -186,7 +187,8 @@ void DebugDaemonLogSource::MergeUserLogFilesResponse( ...@@ -186,7 +187,8 @@ void DebugDaemonLogSource::MergeUserLogFilesResponse(
response_->insert(response->begin(), response->end()); response_->insert(response->begin(), response->end());
auto response_to_return = std::make_unique<SystemLogsResponse>(); auto response_to_return = std::make_unique<SystemLogsResponse>();
std::swap(response_to_return, response_); std::swap(response_to_return, response_);
callback_.Run(std::move(response_to_return)); DCHECK(!callback_.is_null());
std::move(callback_).Run(std::move(response_to_return));
} }
void DebugDaemonLogSource::RequestCompleted() { void DebugDaemonLogSource::RequestCompleted() {
......
...@@ -28,7 +28,7 @@ class DebugDaemonLogSource : public SystemLogsSource { ...@@ -28,7 +28,7 @@ class DebugDaemonLogSource : public SystemLogsSource {
// Fetches logs from the daemon over dbus. After the fetch is complete, the // Fetches logs from the daemon over dbus. After the fetch is complete, the
// results will be forwarded to the request supplied to the constructor and // results will be forwarded to the request supplied to the constructor and
// this instance will free itself. // this instance will free itself.
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
typedef std::map<std::string, std::string> KeyValueMap; typedef std::map<std::string, std::string> KeyValueMap;
......
...@@ -19,7 +19,7 @@ DeviceEventLogSource::DeviceEventLogSource() : SystemLogsSource("DeviceEvent") { ...@@ -19,7 +19,7 @@ DeviceEventLogSource::DeviceEventLogSource() : SystemLogsSource("DeviceEvent") {
DeviceEventLogSource::~DeviceEventLogSource() { DeviceEventLogSource::~DeviceEventLogSource() {
} }
void DeviceEventLogSource::Fetch(const SysLogsSourceCallback& callback) { void DeviceEventLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -31,7 +31,7 @@ void DeviceEventLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -31,7 +31,7 @@ void DeviceEventLogSource::Fetch(const SysLogsSourceCallback& callback) {
(*response)[kDeviceEventLogEntry] = device_event_log::GetAsString( (*response)[kDeviceEventLogEntry] = device_event_log::GetAsString(
device_event_log::OLDEST_FIRST, "time,file,type,level", "non-network", device_event_log::OLDEST_FIRST, "time,file,type,level", "non-network",
device_event_log::LOG_LEVEL_DEBUG, kMaxDeviceEventsForAboutSystem); device_event_log::LOG_LEVEL_DEBUG, kMaxDeviceEventsForAboutSystem);
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
} // namespace system_logs } // namespace system_logs
...@@ -17,7 +17,7 @@ class DeviceEventLogSource : public SystemLogsSource { ...@@ -17,7 +17,7 @@ class DeviceEventLogSource : public SystemLogsSource {
~DeviceEventLogSource() override; ~DeviceEventLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& request) override; void Fetch(SysLogsSourceCallback request) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(DeviceEventLogSource); DISALLOW_COPY_AND_ASSIGN(DeviceEventLogSource);
......
...@@ -16,7 +16,7 @@ LsbReleaseLogSource::LsbReleaseLogSource() : SystemLogsSource("LsbRelease") { ...@@ -16,7 +16,7 @@ LsbReleaseLogSource::LsbReleaseLogSource() : SystemLogsSource("LsbRelease") {
LsbReleaseLogSource::~LsbReleaseLogSource() { LsbReleaseLogSource::~LsbReleaseLogSource() {
} }
void LsbReleaseLogSource::Fetch(const SysLogsSourceCallback& callback) { void LsbReleaseLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
auto response = std::make_unique<SystemLogsResponse>(); auto response = std::make_unique<SystemLogsResponse>();
const base::SysInfo::LsbReleaseMap& lsb_map = const base::SysInfo::LsbReleaseMap& lsb_map =
...@@ -25,7 +25,7 @@ void LsbReleaseLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -25,7 +25,7 @@ void LsbReleaseLogSource::Fetch(const SysLogsSourceCallback& callback) {
iter != lsb_map.end(); ++iter) { iter != lsb_map.end(); ++iter) {
(*response)[iter->first] = iter->second; (*response)[iter->first] = iter->second;
} }
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
} // namespace system_logs } // namespace system_logs
...@@ -16,7 +16,7 @@ class LsbReleaseLogSource : public SystemLogsSource { ...@@ -16,7 +16,7 @@ class LsbReleaseLogSource : public SystemLogsSource {
~LsbReleaseLogSource() override; ~LsbReleaseLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(LsbReleaseLogSource); DISALLOW_COPY_AND_ASSIGN(LsbReleaseLogSource);
......
...@@ -43,22 +43,22 @@ SingleDebugDaemonLogSource::SingleDebugDaemonLogSource( ...@@ -43,22 +43,22 @@ SingleDebugDaemonLogSource::SingleDebugDaemonLogSource(
SingleDebugDaemonLogSource::~SingleDebugDaemonLogSource() {} SingleDebugDaemonLogSource::~SingleDebugDaemonLogSource() {}
void SingleDebugDaemonLogSource::Fetch(const SysLogsSourceCallback& callback) { void SingleDebugDaemonLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
chromeos::DebugDaemonClient* client = chromeos::DebugDaemonClient* client =
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
client->GetLog( client->GetLog(source_name(),
source_name(), base::BindOnce(&SingleDebugDaemonLogSource::OnFetchComplete,
base::BindOnce(&SingleDebugDaemonLogSource::OnFetchComplete, weak_ptr_factory_.GetWeakPtr(), source_name(),
weak_ptr_factory_.GetWeakPtr(), source_name(), callback)); std::move(callback)));
} }
void SingleDebugDaemonLogSource::OnFetchComplete( void SingleDebugDaemonLogSource::OnFetchComplete(
const std::string& log_name, const std::string& log_name,
const SysLogsSourceCallback& callback, SysLogsSourceCallback callback,
base::Optional<std::string> result) const { base::Optional<std::string> result) const {
// |result| and |response| are the same type, but |result| is passed in from // |result| and |response| are the same type, but |result| is passed in from
// DebugDaemonClient, which does not use the SystemLogsResponse alias. // DebugDaemonClient, which does not use the SystemLogsResponse alias.
...@@ -67,7 +67,7 @@ void SingleDebugDaemonLogSource::OnFetchComplete( ...@@ -67,7 +67,7 @@ void SingleDebugDaemonLogSource::OnFetchComplete(
if (result.has_value()) if (result.has_value())
response->emplace(log_name, result.value()); response->emplace(log_name, result.value());
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
} // namespace system_logs } // namespace system_logs
...@@ -40,12 +40,12 @@ class SingleDebugDaemonLogSource : public SystemLogsSource { ...@@ -40,12 +40,12 @@ class SingleDebugDaemonLogSource : public SystemLogsSource {
~SingleDebugDaemonLogSource() override; ~SingleDebugDaemonLogSource() override;
// system_logs::SystemLogsSource: // system_logs::SystemLogsSource:
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
// Callback for handling response from DebugDaemonClient. // Callback for handling response from DebugDaemonClient.
void OnFetchComplete(const std::string& log_name, void OnFetchComplete(const std::string& log_name,
const SysLogsSourceCallback& callback, SysLogsSourceCallback callback,
base::Optional<std::string> result) const; base::Optional<std::string> result) const;
base::WeakPtrFactory<SingleDebugDaemonLogSource> weak_ptr_factory_; base::WeakPtrFactory<SingleDebugDaemonLogSource> weak_ptr_factory_;
......
...@@ -26,9 +26,6 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test { ...@@ -26,9 +26,6 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test {
SingleDebugDaemonLogSourceTest() SingleDebugDaemonLogSourceTest()
: scoped_task_environment_( : scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI), base::test::ScopedTaskEnvironment::MainThreadType::UI),
fetch_callback_(
base::Bind(&SingleDebugDaemonLogSourceTest::OnFetchComplete,
base::Unretained(this))),
num_callback_calls_(0) {} num_callback_calls_(0) {}
void SetUp() override { void SetUp() override {
...@@ -44,8 +41,9 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test { ...@@ -44,8 +41,9 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test {
} }
protected: protected:
const SysLogsSourceCallback& fetch_callback() const { SysLogsSourceCallback fetch_callback() {
return fetch_callback_; return base::BindOnce(&SingleDebugDaemonLogSourceTest::OnFetchComplete,
base::Unretained(this));
} }
int num_callback_calls() const { return num_callback_calls_; } int num_callback_calls() const { return num_callback_calls_; }
...@@ -67,10 +65,6 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test { ...@@ -67,10 +65,6 @@ class SingleDebugDaemonLogSourceTest : public ::testing::Test {
// |scoped_task_environment_| in order to use the MessageLoop it created. // |scoped_task_environment_| in order to use the MessageLoop it created.
content::TestBrowserThreadBundle browser_thread_bundle_; content::TestBrowserThreadBundle browser_thread_bundle_;
// Pre-made callback object for passing OnFetchComplete() to an asynchronous
// function.
const SysLogsSourceCallback fetch_callback_;
// Used to verify that OnFetchComplete was called the correct number of times. // Used to verify that OnFetchComplete was called the correct number of times.
int num_callback_calls_; int num_callback_calls_;
......
...@@ -93,7 +93,7 @@ void SingleLogFileLogSource::SetChromeStartTimeForTesting( ...@@ -93,7 +93,7 @@ void SingleLogFileLogSource::SetChromeStartTimeForTesting(
g_chrome_start_time_for_test = start_time; g_chrome_start_time_for_test = start_time;
} }
void SingleLogFileLogSource::Fetch(const SysLogsSourceCallback& callback) { void SingleLogFileLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -105,7 +105,7 @@ void SingleLogFileLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -105,7 +105,7 @@ void SingleLogFileLogSource::Fetch(const SysLogsSourceCallback& callback) {
base::BindOnce(&SingleLogFileLogSource::ReadFile, base::BindOnce(&SingleLogFileLogSource::ReadFile,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
kMaxNumAllowedLogRotationsDuringFileRead, response_ptr), kMaxNumAllowedLogRotationsDuringFileRead, response_ptr),
base::BindOnce(callback, std::move(response))); base::BindOnce(std::move(callback), std::move(response)));
} }
base::FilePath SingleLogFileLogSource::GetLogFilePath() const { base::FilePath SingleLogFileLogSource::GetLogFilePath() const {
......
...@@ -57,7 +57,7 @@ class SingleLogFileLogSource : public SystemLogsSource { ...@@ -57,7 +57,7 @@ class SingleLogFileLogSource : public SystemLogsSource {
static void SetChromeStartTimeForTesting(const base::Time* start_time); static void SetChromeStartTimeForTesting(const base::Time* start_time);
// system_logs::SystemLogsSource: // system_logs::SystemLogsSource:
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
friend class SingleLogFileLogSourceTest; friend class SingleLogFileLogSourceTest;
......
...@@ -17,7 +17,7 @@ class TouchLogSource : public SystemLogsSource { ...@@ -17,7 +17,7 @@ class TouchLogSource : public SystemLogsSource {
private: private:
// Overridden from SystemLogsSource: // Overridden from SystemLogsSource:
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
DISALLOW_COPY_AND_ASSIGN(TouchLogSource); DISALLOW_COPY_AND_ASSIGN(TouchLogSource);
}; };
......
...@@ -136,7 +136,7 @@ void PackEventLog(system_logs::SystemLogsResponse* response, ...@@ -136,7 +136,7 @@ void PackEventLog(system_logs::SystemLogsResponse* response,
// This is the end of the whole touch log collection process. // This is the end of the whole touch log collection process.
void OnEventLogCollected( void OnEventLogCollected(
std::unique_ptr<system_logs::SystemLogsResponse> response, std::unique_ptr<system_logs::SystemLogsResponse> response,
const system_logs::SysLogsSourceCallback& callback, system_logs::SysLogsSourceCallback callback,
const std::vector<base::FilePath>& log_paths) { const std::vector<base::FilePath>& log_paths) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -144,7 +144,7 @@ void OnEventLogCollected( ...@@ -144,7 +144,7 @@ void OnEventLogCollected(
base::PostTaskWithTraitsAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::BindOnce(&PackEventLog, response_ptr, log_paths), base::BindOnce(&PackEventLog, response_ptr, log_paths),
base::BindOnce(callback, std::move(response))); base::BindOnce(std::move(callback), std::move(response)));
} }
// Callback for handing the outcome of GetTouchDeviceStatus(). // Callback for handing the outcome of GetTouchDeviceStatus().
...@@ -153,7 +153,7 @@ void OnEventLogCollected( ...@@ -153,7 +153,7 @@ void OnEventLogCollected(
// collect touch event logs. // collect touch event logs.
void OnStatusLogCollected( void OnStatusLogCollected(
std::unique_ptr<system_logs::SystemLogsResponse> response, std::unique_ptr<system_logs::SystemLogsResponse> response,
const system_logs::SysLogsSourceCallback& callback, system_logs::SysLogsSourceCallback callback,
const std::string& log) { const std::string& log) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
(*response)[kDeviceStatusLogDataKey] = log; (*response)[kDeviceStatusLogDataKey] = log;
...@@ -163,8 +163,8 @@ void OnStatusLogCollected( ...@@ -163,8 +163,8 @@ void OnStatusLogCollected(
ui::InputDeviceControllerClient* input_device_controller_client = ui::InputDeviceControllerClient* input_device_controller_client =
g_browser_process->platform_part()->GetInputDeviceControllerClient(); g_browser_process->platform_part()->GetInputDeviceControllerClient();
input_device_controller_client->GetTouchEventLog( input_device_controller_client->GetTouchEventLog(
kBaseLogPath, kBaseLogPath, base::BindOnce(&OnEventLogCollected, std::move(response),
base::BindOnce(&OnEventLogCollected, std::move(response), callback)); std::move(callback)));
} }
// Collect touch HUD debug logs. This needs to be done on the UI thread. // Collect touch HUD debug logs. This needs to be done on the UI thread.
...@@ -184,7 +184,7 @@ void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { ...@@ -184,7 +184,7 @@ void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) {
namespace system_logs { namespace system_logs {
void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) { void TouchLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -194,8 +194,8 @@ void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -194,8 +194,8 @@ void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) {
// Collect touch device status logs. // Collect touch device status logs.
ui::InputDeviceControllerClient* input_device_controller_client = ui::InputDeviceControllerClient* input_device_controller_client =
g_browser_process->platform_part()->GetInputDeviceControllerClient(); g_browser_process->platform_part()->GetInputDeviceControllerClient();
input_device_controller_client->GetTouchDeviceStatus( input_device_controller_client->GetTouchDeviceStatus(base::BindOnce(
base::BindOnce(&OnStatusLogCollected, std::move(response), callback)); &OnStatusLogCollected, std::move(response), std::move(callback)));
} }
} // namespace system_logs } // namespace system_logs
...@@ -111,7 +111,7 @@ ChromeInternalLogSource::ChromeInternalLogSource() ...@@ -111,7 +111,7 @@ ChromeInternalLogSource::ChromeInternalLogSource()
ChromeInternalLogSource::~ChromeInternalLogSource() { ChromeInternalLogSource::~ChromeInternalLogSource() {
} }
void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) { void ChromeInternalLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -156,10 +156,10 @@ void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -156,10 +156,10 @@ void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) {
base::PostTaskWithTraitsAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::BindOnce(&GetEntriesAsync, response_ptr), base::BindOnce(&GetEntriesAsync, response_ptr),
base::BindOnce(callback, std::move(response))); base::BindOnce(std::move(callback), std::move(response)));
#else #else
// On other platforms, we're done. Invoke the callback. // On other platforms, we're done. Invoke the callback.
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} }
......
...@@ -18,7 +18,7 @@ class ChromeInternalLogSource : public SystemLogsSource { ...@@ -18,7 +18,7 @@ class ChromeInternalLogSource : public SystemLogsSource {
~ChromeInternalLogSource() override; ~ChromeInternalLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& request) override; void Fetch(SysLogsSourceCallback request) override;
private: private:
void PopulateSyncLogs(SystemLogsResponse* response); void PopulateSyncLogs(SystemLogsResponse* response);
......
...@@ -33,10 +33,11 @@ CrashIdsSource::CrashIdsSource() ...@@ -33,10 +33,11 @@ CrashIdsSource::CrashIdsSource()
CrashIdsSource::~CrashIdsSource() {} CrashIdsSource::~CrashIdsSource() {}
void CrashIdsSource::Fetch(const SysLogsSourceCallback& callback) { void CrashIdsSource::Fetch(SysLogsSourceCallback callback) {
// Unretained since we own these callbacks. // Unretained since we own these callbacks.
pending_requests_.emplace_back(base::Bind( pending_requests_.emplace_back(
&CrashIdsSource::RespondWithCrashIds, base::Unretained(this), callback)); base::BindOnce(&CrashIdsSource::RespondWithCrashIds,
base::Unretained(this), std::move(callback)));
if (pending_crash_list_loading_) if (pending_crash_list_loading_)
return; return;
...@@ -70,19 +71,18 @@ void CrashIdsSource::OnUploadListAvailable() { ...@@ -70,19 +71,18 @@ void CrashIdsSource::OnUploadListAvailable() {
} }
} }
for (const auto& request : pending_requests_) for (auto& request : pending_requests_)
request.Run(); std::move(request).Run();
pending_requests_.clear(); pending_requests_.clear();
} }
void CrashIdsSource::RespondWithCrashIds( void CrashIdsSource::RespondWithCrashIds(SysLogsSourceCallback callback) const {
const SysLogsSourceCallback& callback) const {
auto response = std::make_unique<SystemLogsResponse>(); auto response = std::make_unique<SystemLogsResponse>();
(*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_; (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_;
// We must respond anyways. // We must respond anyways.
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
} // namespace system_logs } // namespace system_logs
...@@ -20,11 +20,11 @@ class CrashIdsSource : public SystemLogsSource { ...@@ -20,11 +20,11 @@ class CrashIdsSource : public SystemLogsSource {
~CrashIdsSource() override; ~CrashIdsSource() override;
// SystemLogsSource: // SystemLogsSource:
void Fetch(const SysLogsSourceCallback& callback) override; void Fetch(SysLogsSourceCallback callback) override;
private: private:
void OnUploadListAvailable(); void OnUploadListAvailable();
void RespondWithCrashIds(const SysLogsSourceCallback& callback) const; void RespondWithCrashIds(SysLogsSourceCallback callback) const;
scoped_refptr<UploadList> crash_upload_list_; scoped_refptr<UploadList> crash_upload_list_;
...@@ -33,7 +33,7 @@ class CrashIdsSource : public SystemLogsSource { ...@@ -33,7 +33,7 @@ class CrashIdsSource : public SystemLogsSource {
// Contains any pending fetch requests waiting for the crash upload list to // Contains any pending fetch requests waiting for the crash upload list to
// finish loading. // finish loading.
std::vector<base::Closure> pending_requests_; std::vector<base::OnceClosure> pending_requests_;
// True if the crash list is currently being loaded. // True if the crash list is currently being loaded.
bool pending_crash_list_loading_; bool pending_crash_list_loading_;
......
...@@ -13,8 +13,8 @@ namespace system_logs { ...@@ -13,8 +13,8 @@ namespace system_logs {
// Reads Chrome memory usage. // Reads Chrome memory usage.
class SystemLogsMemoryHandler : public MemoryDetails { class SystemLogsMemoryHandler : public MemoryDetails {
public: public:
explicit SystemLogsMemoryHandler(const SysLogsSourceCallback& callback) explicit SystemLogsMemoryHandler(SysLogsSourceCallback callback)
: callback_(callback) {} : callback_(std::move(callback)) {}
// Sends the data to the callback. // Sends the data to the callback.
// MemoryDetails override. // MemoryDetails override.
...@@ -23,7 +23,8 @@ class SystemLogsMemoryHandler : public MemoryDetails { ...@@ -23,7 +23,8 @@ class SystemLogsMemoryHandler : public MemoryDetails {
auto response = std::make_unique<SystemLogsResponse>(); auto response = std::make_unique<SystemLogsResponse>();
(*response)["mem_usage"] = ToLogString(); (*response)["mem_usage"] = ToLogString();
callback_.Run(std::move(response)); DCHECK(!callback_.is_null());
std::move(callback_).Run(std::move(response));
} }
private: private:
...@@ -40,12 +41,12 @@ MemoryDetailsLogSource::MemoryDetailsLogSource() ...@@ -40,12 +41,12 @@ MemoryDetailsLogSource::MemoryDetailsLogSource()
MemoryDetailsLogSource::~MemoryDetailsLogSource() { MemoryDetailsLogSource::~MemoryDetailsLogSource() {
} }
void MemoryDetailsLogSource::Fetch(const SysLogsSourceCallback& callback) { void MemoryDetailsLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
scoped_refptr<SystemLogsMemoryHandler> scoped_refptr<SystemLogsMemoryHandler> handler(
handler(new SystemLogsMemoryHandler(callback)); new SystemLogsMemoryHandler(std::move(callback)));
handler->StartFetch(); handler->StartFetch();
} }
......
...@@ -17,7 +17,7 @@ class MemoryDetailsLogSource : public SystemLogsSource { ...@@ -17,7 +17,7 @@ class MemoryDetailsLogSource : public SystemLogsSource {
~MemoryDetailsLogSource() override; ~MemoryDetailsLogSource() override;
// SystemLogsSource override. // SystemLogsSource override.
void Fetch(const SysLogsSourceCallback& request) override; void Fetch(SysLogsSourceCallback request) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(MemoryDetailsLogSource); DISALLOW_COPY_AND_ASSIGN(MemoryDetailsLogSource);
......
...@@ -71,12 +71,12 @@ void SystemLogsFetcher::AddSource(std::unique_ptr<SystemLogsSource> source) { ...@@ -71,12 +71,12 @@ void SystemLogsFetcher::AddSource(std::unique_ptr<SystemLogsSource> source) {
num_pending_requests_++; num_pending_requests_++;
} }
void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) { void SystemLogsFetcher::Fetch(SysLogsFetcherCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(callback_.is_null()); DCHECK(callback_.is_null());
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
callback_ = callback; callback_ = std::move(callback);
for (size_t i = 0; i < data_sources_.size(); ++i) { for (size_t i = 0; i < data_sources_.size(); ++i) {
VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name(); VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name();
data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::OnFetched, data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::OnFetched,
...@@ -122,7 +122,9 @@ void SystemLogsFetcher::AddResponse( ...@@ -122,7 +122,9 @@ void SystemLogsFetcher::AddResponse(
if (num_pending_requests_ > 0) if (num_pending_requests_ > 0)
return; return;
callback_.Run(std::move(response_)); DCHECK(!callback_.is_null());
std::move(callback_).Run(std::move(response_));
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
} }
......
...@@ -24,7 +24,7 @@ namespace system_logs { ...@@ -24,7 +24,7 @@ namespace system_logs {
// Callback that the SystemLogsFetcher uses to return data. // Callback that the SystemLogsFetcher uses to return data.
using SysLogsFetcherCallback = using SysLogsFetcherCallback =
base::Callback<void(std::unique_ptr<SystemLogsResponse>)>; base::OnceCallback<void(std::unique_ptr<SystemLogsResponse>)>;
// The SystemLogsFetcher fetches key-value data from a list of log sources. // The SystemLogsFetcher fetches key-value data from a list of log sources.
// //
...@@ -52,7 +52,7 @@ class SystemLogsFetcher { ...@@ -52,7 +52,7 @@ class SystemLogsFetcher {
// Starts the fetch process. After the fetch completes, this instance calls // Starts the fetch process. After the fetch completes, this instance calls
// |callback|, then schedules itself to be deleted. // |callback|, then schedules itself to be deleted.
void Fetch(const SysLogsFetcherCallback& callback); void Fetch(SysLogsFetcherCallback callback);
private: private:
// Callback passed to all the data sources. May call Scrub(), then calls // Callback passed to all the data sources. May call Scrub(), then calls
......
...@@ -17,7 +17,7 @@ using SystemLogsResponse = FeedbackCommon::SystemLogsMap; ...@@ -17,7 +17,7 @@ using SystemLogsResponse = FeedbackCommon::SystemLogsMap;
// Callback that the data sources use to return data. // Callback that the data sources use to return data.
using SysLogsSourceCallback = using SysLogsSourceCallback =
base::Callback<void(std::unique_ptr<SystemLogsResponse>)>; base::OnceCallback<void(std::unique_ptr<SystemLogsResponse>)>;
// The SystemLogsSource provides an interface for the data sources that // The SystemLogsSource provides an interface for the data sources that
// the SystemLogsFetcher class uses to fetch logs and other information. // the SystemLogsFetcher class uses to fetch logs and other information.
...@@ -28,7 +28,7 @@ class SystemLogsSource { ...@@ -28,7 +28,7 @@ class SystemLogsSource {
virtual ~SystemLogsSource(); virtual ~SystemLogsSource();
// Fetches data and passes it by pointer to the callback // Fetches data and passes it by pointer to the callback
virtual void Fetch(const SysLogsSourceCallback& callback) = 0; virtual void Fetch(SysLogsSourceCallback callback) = 0;
const std::string& source_name() const { return source_name_; } const std::string& source_name() const { return source_name_; }
......
...@@ -49,7 +49,7 @@ class TestSingleLogSource : public SystemLogsSource { ...@@ -49,7 +49,7 @@ class TestSingleLogSource : public SystemLogsSource {
// sequence: "a", " bb", " ccc", until 25 spaces followed by 26 z's. After // sequence: "a", " bb", " ccc", until 25 spaces followed by 26 z's. After
// that, it returns |kDummyMacAddress| before repeating the entire process. // that, it returns |kDummyMacAddress| before repeating the entire process.
// It will never return an empty result. // It will never return an empty result.
void Fetch(const system_logs::SysLogsSourceCallback& callback) override { void Fetch(system_logs::SysLogsSourceCallback callback) override {
std::string result = GetNextLogResult(); std::string result = GetNextLogResult();
DCHECK_GT(result.size(), 0U); DCHECK_GT(result.size(), 0U);
...@@ -60,7 +60,7 @@ class TestSingleLogSource : public SystemLogsSource { ...@@ -60,7 +60,7 @@ class TestSingleLogSource : public SystemLogsSource {
// log sources actually work. Instead, simulate the asynchronous operation // log sources actually work. Instead, simulate the asynchronous operation
// of a SystemLogsSource by invoking the callback separately. // of a SystemLogsSource by invoking the callback separately.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, std::move(result_map))); FROM_HERE, base::BindOnce(std::move(callback), std::move(result_map)));
} }
private: private:
......
...@@ -86,10 +86,9 @@ void LogSourceAccessManager::SetRateLimitingTimeoutForTesting( ...@@ -86,10 +86,9 @@ void LogSourceAccessManager::SetRateLimitingTimeoutForTesting(
g_rate_limiting_timeout = timeout; g_rate_limiting_timeout = timeout;
} }
bool LogSourceAccessManager::FetchFromSource( bool LogSourceAccessManager::FetchFromSource(const ReadLogSourceParams& params,
const ReadLogSourceParams& params, const std::string& extension_id,
const std::string& extension_id, ReadLogSourceCallback callback) {
const ReadLogSourceCallback& callback) {
int requested_resource_id = int requested_resource_id =
params.reader_id ? *params.reader_id : kInvalidResourceId; params.reader_id ? *params.reader_id : kInvalidResourceId;
ApiResourceManager<LogSourceResource>* resource_manager = ApiResourceManager<LogSourceResource>* resource_manager =
...@@ -113,7 +112,7 @@ bool LogSourceAccessManager::FetchFromSource( ...@@ -113,7 +112,7 @@ bool LogSourceAccessManager::FetchFromSource(
// perspective, there is no new data. There is no need for the caller to keep // perspective, there is no new data. There is no need for the caller to keep
// track of the time since last access. // track of the time since last access.
if (!UpdateSourceAccessTime(resource_id)) { if (!UpdateSourceAccessTime(resource_id)) {
callback.Run( std::move(callback).Run(
std::make_unique<api::feedback_private::ReadLogSourceResult>()); std::make_unique<api::feedback_private::ReadLogSourceResult>());
return true; return true;
} }
...@@ -124,9 +123,10 @@ bool LogSourceAccessManager::FetchFromSource( ...@@ -124,9 +123,10 @@ bool LogSourceAccessManager::FetchFromSource(
// later access indicates that the source should be closed afterwards. // later access indicates that the source should be closed afterwards.
const bool delete_resource_when_done = !params.incremental; const bool delete_resource_when_done = !params.incremental;
resource->GetLogSource()->Fetch(base::Bind( resource->GetLogSource()->Fetch(
&LogSourceAccessManager::OnFetchComplete, weak_factory_.GetWeakPtr(), base::BindOnce(&LogSourceAccessManager::OnFetchComplete,
extension_id, resource_id, delete_resource_when_done, callback)); weak_factory_.GetWeakPtr(), extension_id, resource_id,
delete_resource_when_done, std::move(callback)));
return true; return true;
} }
...@@ -134,7 +134,7 @@ void LogSourceAccessManager::OnFetchComplete( ...@@ -134,7 +134,7 @@ void LogSourceAccessManager::OnFetchComplete(
const std::string& extension_id, const std::string& extension_id,
ResourceId resource_id, ResourceId resource_id,
bool delete_resource, bool delete_resource,
const ReadLogSourceCallback& callback, ReadLogSourceCallback callback,
std::unique_ptr<SystemLogsResponse> response) { std::unique_ptr<SystemLogsResponse> response) {
auto result = std::make_unique<ReadLogSourceResult>(); auto result = std::make_unique<ReadLogSourceResult>();
...@@ -151,7 +151,7 @@ void LogSourceAccessManager::OnFetchComplete( ...@@ -151,7 +151,7 @@ void LogSourceAccessManager::OnFetchComplete(
FROM_HERE, FROM_HERE,
base::BindOnce(AnonymizeResults, anonymizer_container_, base::BindOnce(AnonymizeResults, anonymizer_container_,
base::Unretained(result_ptr)), base::Unretained(result_ptr)),
base::BindOnce(callback, std::move(result))); base::BindOnce(std::move(callback), std::move(result)));
if (delete_resource) { if (delete_resource) {
// This should also remove the entry from |sources_|. // This should also remove the entry from |sources_|.
......
...@@ -30,7 +30,7 @@ namespace extensions { ...@@ -30,7 +30,7 @@ namespace extensions {
// - A source may not be accessed too frequently by an extension. // - A source may not be accessed too frequently by an extension.
class LogSourceAccessManager { class LogSourceAccessManager {
public: public:
using ReadLogSourceCallback = base::Callback<void( using ReadLogSourceCallback = base::OnceCallback<void(
std::unique_ptr<api::feedback_private::ReadLogSourceResult>)>; std::unique_ptr<api::feedback_private::ReadLogSourceResult>)>;
explicit LogSourceAccessManager(content::BrowserContext* context); explicit LogSourceAccessManager(content::BrowserContext* context);
...@@ -52,7 +52,7 @@ class LogSourceAccessManager { ...@@ -52,7 +52,7 @@ class LogSourceAccessManager {
// feedback_private.idl for more info about the actual parameters. // feedback_private.idl for more info about the actual parameters.
bool FetchFromSource(const api::feedback_private::ReadLogSourceParams& params, bool FetchFromSource(const api::feedback_private::ReadLogSourceParams& params,
const std::string& extension_id, const std::string& extension_id,
const ReadLogSourceCallback& callback); ReadLogSourceCallback callback);
// Each log source may not have more than this number of readers accessing it, // Each log source may not have more than this number of readers accessing it,
// regardless of extension. // regardless of extension.
...@@ -111,7 +111,7 @@ class LogSourceAccessManager { ...@@ -111,7 +111,7 @@ class LogSourceAccessManager {
const std::string& extension_id, const std::string& extension_id,
ResourceId resource_id, ResourceId resource_id,
bool delete_source, bool delete_source,
const ReadLogSourceCallback& callback, ReadLogSourceCallback callback,
std::unique_ptr<system_logs::SystemLogsResponse> response); std::unique_ptr<system_logs::SystemLogsResponse> response);
// Removes an existing log source handle indicated by |id| from // Removes an existing log source handle indicated by |id| from
......
...@@ -21,6 +21,8 @@ using api::feedback_private::ReadLogSourceParams; ...@@ -21,6 +21,8 @@ using api::feedback_private::ReadLogSourceParams;
constexpr int kMaxReadersPerSource = constexpr int kMaxReadersPerSource =
LogSourceAccessManager::kMaxReadersPerSource; LogSourceAccessManager::kMaxReadersPerSource;
void DummyCallback(std::unique_ptr<ReadLogSourceResult>) {}
} // namespace } // namespace
using LogSourceAccessManagerTest = FeedbackPrivateApiUnittestBase; using LogSourceAccessManagerTest = FeedbackPrivateApiUnittestBase;
...@@ -31,10 +33,6 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) { ...@@ -31,10 +33,6 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) {
LogSourceAccessManager manager(browser_context()); LogSourceAccessManager manager(browser_context());
// Create a dummy callback to pass to FetchFromSource().
LogSourceAccessManager::ReadLogSourceCallback callback =
base::Bind([](std::unique_ptr<ReadLogSourceResult>) {});
const std::string extension_id = "extension"; const std::string extension_id = "extension";
// Open 10 readers for LOG_SOURCE_MESSAGES from the same extension. // Open 10 readers for LOG_SOURCE_MESSAGES from the same extension.
...@@ -42,8 +40,8 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) { ...@@ -42,8 +40,8 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) {
messages_params.incremental = false; messages_params.incremental = false;
messages_params.source = LOG_SOURCE_MESSAGES; messages_params.source = LOG_SOURCE_MESSAGES;
for (size_t i = 0; i < kMaxReadersPerSource; ++i) { for (size_t i = 0; i < kMaxReadersPerSource; ++i) {
EXPECT_TRUE( EXPECT_TRUE(manager.FetchFromSource(messages_params, extension_id,
manager.FetchFromSource(messages_params, extension_id, callback)) base::BindOnce(&DummyCallback)))
<< base::StringPrintf("Unable to read from log source with i=%zu", i); << base::StringPrintf("Unable to read from log source with i=%zu", i);
EXPECT_EQ(i + 1, EXPECT_EQ(i + 1,
manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
...@@ -55,8 +53,8 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) { ...@@ -55,8 +53,8 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) {
ui_latest_params.incremental = false; ui_latest_params.incremental = false;
ui_latest_params.source = LOG_SOURCE_UILATEST; ui_latest_params.source = LOG_SOURCE_UILATEST;
for (size_t i = 0; i < kMaxReadersPerSource; ++i) { for (size_t i = 0; i < kMaxReadersPerSource; ++i) {
EXPECT_TRUE( EXPECT_TRUE(manager.FetchFromSource(ui_latest_params, extension_id,
manager.FetchFromSource(ui_latest_params, extension_id, callback)) base::BindOnce(&DummyCallback)))
<< base::StringPrintf("Unable to read from log source with i=%zu", i); << base::StringPrintf("Unable to read from log source with i=%zu", i);
EXPECT_EQ(i + 1, EXPECT_EQ(i + 1,
manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST)); manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST));
...@@ -64,10 +62,10 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) { ...@@ -64,10 +62,10 @@ TEST_F(LogSourceAccessManagerTest, MaxNumberOfOpenLogSourcesSameExtension) {
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
// Can't open more readers for LOG_SOURCE_MESSAGES or LOG_SOURCE_UILATEST. // Can't open more readers for LOG_SOURCE_MESSAGES or LOG_SOURCE_UILATEST.
EXPECT_FALSE( EXPECT_FALSE(manager.FetchFromSource(messages_params, extension_id,
manager.FetchFromSource(messages_params, extension_id, callback)); base::BindOnce(&DummyCallback)));
EXPECT_FALSE( EXPECT_FALSE(manager.FetchFromSource(ui_latest_params, extension_id,
manager.FetchFromSource(ui_latest_params, extension_id, callback)); base::BindOnce(&DummyCallback)));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST));
...@@ -82,10 +80,6 @@ TEST_F(LogSourceAccessManagerTest, ...@@ -82,10 +80,6 @@ TEST_F(LogSourceAccessManagerTest,
LogSourceAccessManager manager(browser_context()); LogSourceAccessManager manager(browser_context());
// Create a dummy callback to pass to FetchFromSource().
LogSourceAccessManager::ReadLogSourceCallback callback =
base::Bind([](std::unique_ptr<ReadLogSourceResult>) {});
int count = 0; int count = 0;
// Open 10 readers for LOG_SOURCE_MESSAGES from different extensions. // Open 10 readers for LOG_SOURCE_MESSAGES from different extensions.
...@@ -94,7 +88,8 @@ TEST_F(LogSourceAccessManagerTest, ...@@ -94,7 +88,8 @@ TEST_F(LogSourceAccessManagerTest,
messages_params.source = LOG_SOURCE_MESSAGES; messages_params.source = LOG_SOURCE_MESSAGES;
for (size_t i = 0; i < kMaxReadersPerSource; ++i, ++count) { for (size_t i = 0; i < kMaxReadersPerSource; ++i, ++count) {
EXPECT_TRUE(manager.FetchFromSource( EXPECT_TRUE(manager.FetchFromSource(
messages_params, base::StringPrintf("extension %d", count), callback)) messages_params, base::StringPrintf("extension %d", count),
base::BindOnce(&DummyCallback)))
<< base::StringPrintf( << base::StringPrintf(
"Unable to read from log source with i=%zu and count=%d", i, "Unable to read from log source with i=%zu and count=%d", i,
count); count);
...@@ -109,7 +104,8 @@ TEST_F(LogSourceAccessManagerTest, ...@@ -109,7 +104,8 @@ TEST_F(LogSourceAccessManagerTest,
ui_latest_params.source = LOG_SOURCE_UILATEST; ui_latest_params.source = LOG_SOURCE_UILATEST;
for (size_t i = 0; i < kMaxReadersPerSource; ++i, ++count) { for (size_t i = 0; i < kMaxReadersPerSource; ++i, ++count) {
EXPECT_TRUE(manager.FetchFromSource( EXPECT_TRUE(manager.FetchFromSource(
ui_latest_params, base::StringPrintf("extension %d", count), callback)) ui_latest_params, base::StringPrintf("extension %d", count),
base::BindOnce(&DummyCallback)))
<< base::StringPrintf( << base::StringPrintf(
"Unable to read from log source with i=%zu and count=%d", i, "Unable to read from log source with i=%zu and count=%d", i,
count); count);
...@@ -120,13 +116,15 @@ TEST_F(LogSourceAccessManagerTest, ...@@ -120,13 +116,15 @@ TEST_F(LogSourceAccessManagerTest,
// Can't open more readers for LOG_SOURCE_MESSAGES. // Can't open more readers for LOG_SOURCE_MESSAGES.
EXPECT_FALSE(manager.FetchFromSource( EXPECT_FALSE(manager.FetchFromSource(
messages_params, base::StringPrintf("extension %d", count), callback)); messages_params, base::StringPrintf("extension %d", count),
base::BindOnce(&DummyCallback)));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST));
// Can't open more readers for LOG_SOURCE_UILATEST. // Can't open more readers for LOG_SOURCE_UILATEST.
EXPECT_FALSE(manager.FetchFromSource( EXPECT_FALSE(manager.FetchFromSource(
ui_latest_params, base::StringPrintf("extension %d", count), callback)); ui_latest_params, base::StringPrintf("extension %d", count),
base::BindOnce(&DummyCallback)));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST)); EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST));
......
...@@ -32,7 +32,7 @@ BasicLogSource::BasicLogSource(content::BrowserContext* browser_context) ...@@ -32,7 +32,7 @@ BasicLogSource::BasicLogSource(content::BrowserContext* browser_context)
BasicLogSource::~BasicLogSource() = default; BasicLogSource::~BasicLogSource() = default;
void BasicLogSource::Fetch(const SysLogsSourceCallback& callback) { void BasicLogSource::Fetch(SysLogsSourceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -41,7 +41,7 @@ void BasicLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -41,7 +41,7 @@ void BasicLogSource::Fetch(const SysLogsSourceCallback& callback) {
PopulateVersionStrings(response.get()); PopulateVersionStrings(response.get());
PopulateExtensionInfoLogs(response.get()); PopulateExtensionInfoLogs(response.get());
callback.Run(std::move(response)); std::move(callback).Run(std::move(response));
} }
void BasicLogSource::PopulateVersionStrings(SystemLogsResponse* response) { void BasicLogSource::PopulateVersionStrings(SystemLogsResponse* response) {
......
...@@ -21,7 +21,7 @@ class BasicLogSource : public SystemLogsSource { ...@@ -21,7 +21,7 @@ class BasicLogSource : public SystemLogsSource {
~BasicLogSource() override; ~BasicLogSource() override;
// SystemLogsSource: // SystemLogsSource:
void Fetch(const SysLogsSourceCallback& request) override; void Fetch(SysLogsSourceCallback request) override;
private: private:
void PopulateVersionStrings(SystemLogsResponse* response); void PopulateVersionStrings(SystemLogsResponse* response);
......
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