Commit b3f01cba authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Convert SystemInfoProvider to OnceCallback

There are two methods in this class taking a callback.

 - StartQueryInfo stores the callback in a queue and then calls them
   when a system query is done. The callbacks are always cleared after
   calling so these can be made OnceCallback.

 - InitializeProvider simply calls the given Closure and the only
   override in StorageInfoProvider passes it to
   StorageMonitor::EnsureInitialized which takes it as a OnceClosure so
   this is also safe to make OnceClosure.

And we remove GetStorageFreeSpaceCallback since it's no longer used
anywhere.

Bug: 1152268
Change-Id: Ifa05987ef60c57046df4f1ee4753957a061e0edb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597575Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839117}
parent f35dcfbb
......@@ -19,7 +19,7 @@ SystemCpuGetInfoFunction::~SystemCpuGetInfoFunction() {
ExtensionFunction::ResponseAction SystemCpuGetInfoFunction::Run() {
CpuInfoProvider::Get()->StartQueryInfo(
base::Bind(&SystemCpuGetInfoFunction::OnGetCpuInfoCompleted, this));
base::BindOnce(&SystemCpuGetInfoFunction::OnGetCpuInfoCompleted, this));
return did_respond() ? AlreadyResponded() : RespondLater();
}
......
......@@ -27,32 +27,31 @@ void SystemInfoProvider::PrepareQueryOnUIThread() {
}
void SystemInfoProvider::InitializeProvider(
const base::Closure& do_query_info_callback) {
do_query_info_callback.Run();
base::OnceClosure do_query_info_callback) {
std::move(do_query_info_callback).Run();
}
void SystemInfoProvider::StartQueryInfo(
const QueryInfoCompletionCallback& callback) {
void SystemInfoProvider::StartQueryInfo(QueryInfoCompletionCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!callback.is_null());
callbacks_.push(callback);
callbacks_.push(std::move(callback));
if (is_waiting_for_completion_)
return;
is_waiting_for_completion_ = true;
InitializeProvider(
base::Bind(&SystemInfoProvider::StartQueryInfoPostInitialization, this));
InitializeProvider(base::BindOnce(
&SystemInfoProvider::StartQueryInfoPostInitialization, this));
}
void SystemInfoProvider::OnQueryCompleted(bool success) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
while (!callbacks_.empty()) {
QueryInfoCompletionCallback callback = callbacks_.front();
callback.Run(success);
QueryInfoCompletionCallback callback = std::move(callbacks_.front());
std::move(callback).Run(success);
callbacks_.pop();
}
......
......@@ -38,7 +38,7 @@ class SystemInfoProvider
// Callback type for completing to get information. The argument indicates
// whether its contents are valid, for example, no error occurs in querying
// the information.
using QueryInfoCompletionCallback = base::Callback<void(bool)>;
using QueryInfoCompletionCallback = base::OnceCallback<void(bool)>;
using CallbackQueue = base::queue<QueryInfoCompletionCallback>;
SystemInfoProvider();
......@@ -55,7 +55,7 @@ class SystemInfoProvider
// directly or indirectly.
//
// Sample usage please refer to StorageInfoProvider.
virtual void InitializeProvider(const base::Closure& do_query_info_callback);
virtual void InitializeProvider(base::OnceClosure do_query_info_callback);
// Start to query the system information. Should be called on UI thread.
// The |callback| will get called once the query is completed.
......@@ -63,7 +63,7 @@ class SystemInfoProvider
// If the parameter |callback| itself calls StartQueryInfo(callback2),
// callback2 will be called immediately rather than triggering another call to
// the system.
void StartQueryInfo(const QueryInfoCompletionCallback& callback);
void StartQueryInfo(QueryInfoCompletionCallback callback);
protected:
virtual ~SystemInfoProvider();
......
......@@ -18,8 +18,8 @@ SystemMemoryGetInfoFunction::~SystemMemoryGetInfoFunction() {
}
ExtensionFunction::ResponseAction SystemMemoryGetInfoFunction::Run() {
MemoryInfoProvider::Get()->StartQueryInfo(
base::Bind(&SystemMemoryGetInfoFunction::OnGetMemoryInfoCompleted, this));
MemoryInfoProvider::Get()->StartQueryInfo(base::BindOnce(
&SystemMemoryGetInfoFunction::OnGetMemoryInfoCompleted, this));
// StartQueryInfo responds asynchronously.
return RespondLater();
}
......
......@@ -58,12 +58,13 @@ void StorageInfoProvider::PrepareQueryOnUIThread() {
}
void StorageInfoProvider::InitializeProvider(
const base::Closure& do_query_info_callback) {
base::OnceClosure do_query_info_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Register the |do_query_info_callback| callback to StorageMonitor.
// See the comments of StorageMonitor::EnsureInitialized about when the
// callback gets run.
StorageMonitor::GetInstance()->EnsureInitialized(do_query_info_callback);
StorageMonitor::GetInstance()->EnsureInitialized(
std::move(do_query_info_callback));
}
bool StorageInfoProvider::QueryInfo() {
......
......@@ -32,15 +32,12 @@ typedef std::vector<api::system_storage::StorageUnitInfo> StorageUnitInfoList;
class StorageInfoProvider : public SystemInfoProvider {
public:
typedef base::Callback<void(const std::string&, double)>
GetStorageFreeSpaceCallback;
// Get the single shared instance of StorageInfoProvider.
static StorageInfoProvider* Get();
// SystemInfoProvider implementations
void PrepareQueryOnUIThread() override;
void InitializeProvider(const base::Closure& do_query_info_callback) override;
void InitializeProvider(base::OnceClosure do_query_info_callback) override;
virtual double GetStorageFreeSpaceFromTransientIdAsync(
const std::string& transient_id);
......
......@@ -25,7 +25,7 @@ SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() {
}
ExtensionFunction::ResponseAction SystemStorageGetInfoFunction::Run() {
StorageInfoProvider::Get()->StartQueryInfo(base::Bind(
StorageInfoProvider::Get()->StartQueryInfo(base::BindOnce(
&SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, this));
return RespondLater();
}
......
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