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