Skip to content

Commit

Permalink
[Extensions] Cleanup unused fields on AsyncApiFunction
Browse files Browse the repository at this point in the history
AsyncApiFunction should go away entirely. Clean up some low-hanging
fruit in unused fields.

This CL has no behavior change whatsoever.

Bug: 1450946
Change-Id: Ib4c1b0aff6c369fe5e1603d543a9d9a6eee4b115
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4583938
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Auto-Submit: Devlin Cronin <rdevlin.cronin@chromium.org>
Reviewed-by: David Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1152845}
  • Loading branch information
rdcronin authored and Chromium LUCI CQ committed Jun 3, 2023
1 parent d6228b1 commit 8053fe5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
18 changes: 3 additions & 15 deletions extensions/browser/api/async_api_function.cc
Expand Up @@ -24,7 +24,7 @@ AsyncApiFunction::~AsyncApiFunction() = default;
bool AsyncApiFunction::RunAsync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

if (!PrePrepare() || !Prepare()) {
if (!Prepare()) {
return false;
}
bool rv = work_task_runner_->PostTask(
Expand All @@ -33,17 +33,8 @@ bool AsyncApiFunction::RunAsync() {
return true;
}

bool AsyncApiFunction::PrePrepare() {
return true;
}

void AsyncApiFunction::Work() {}

void AsyncApiFunction::AsyncWorkStart() {
Work();
AsyncWorkCompleted();
}

// static
bool AsyncApiFunction::ValidationFailure(AsyncApiFunction* function) {
return false;
Expand Down Expand Up @@ -71,10 +62,6 @@ void AsyncApiFunction::SetResult(base::Value result) {
results_->Append(std::move(result));
}

void AsyncApiFunction::SetResultList(base::Value::List results) {
results_ = std::move(results);
}

void AsyncApiFunction::SetError(const std::string& error) {
error_ = error;
}
Expand All @@ -85,7 +72,8 @@ const std::string& AsyncApiFunction::GetError() const {

void AsyncApiFunction::WorkOnWorkThread() {
DCHECK(work_task_runner_->RunsTasksInCurrentSequence());
AsyncWorkStart();
Work();
AsyncWorkCompleted();
}

void AsyncApiFunction::RespondOnUIThread() {
Expand Down
20 changes: 1 addition & 19 deletions extensions/browser/api/async_api_function.h
Expand Up @@ -14,15 +14,12 @@ namespace extensions {

// AsyncApiFunction provides convenient thread management for APIs that need to
// do essentially all their work on a thread other than the UI thread.
// TODO(crbug.com/1450946): Remove this class entirely.
class AsyncApiFunction : public ExtensionFunction {
protected:
AsyncApiFunction();
~AsyncApiFunction() override;

// Like Prepare(). A useful place to put common work in an ApiFunction
// superclass that multiple API functions want to share.
virtual bool PrePrepare();

// Set up for work (e.g., validate arguments). Guaranteed to happen on UI
// thread.
virtual bool Prepare() = 0;
Expand All @@ -31,10 +28,6 @@ class AsyncApiFunction : public ExtensionFunction {
// |work_task_runner_| if non-null; or on the IO thread otherwise.
virtual void Work();

// Start the asynchronous work. Guraranteed to happen on work thread.
virtual void AsyncWorkStart();

// Respond. Guaranteed to happen on UI thread.
virtual bool Respond() = 0;

// ExtensionFunction:
Expand All @@ -44,23 +37,12 @@ class AsyncApiFunction : public ExtensionFunction {
// ValidationFailure override to match RunAsync().
static bool ValidationFailure(AsyncApiFunction* function);

scoped_refptr<base::SequencedTaskRunner> work_task_runner() const {
return work_task_runner_;
}
void set_work_task_runner(
scoped_refptr<base::SequencedTaskRunner> work_task_runner) {
work_task_runner_ = work_task_runner;
}

// Notify AsyncIOApiFunction that the work is completed
void AsyncWorkCompleted();

// Sets a single Value as the results of the function.
void SetResult(base::Value result);

// Sets multiple Values as the results of the function.
void SetResultList(base::Value::List results);

void SetError(const std::string& error);
const std::string& GetError() const override;

Expand Down

0 comments on commit 8053fe5

Please sign in to comment.