Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2192)

Unified Diff: extensions/browser/extension_function.cc

Issue 2351823004: [Extensions] Consolidate ExtensionFunction::SendResponse()s (Closed)
Patch Set: ready Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/extension_function.cc
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index 2ae214106f4cff0be94992fc35c3bbe208874b90..91a9a9d509c2ca16c61fddf56ad8ae5f0f6e8049 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -301,7 +301,7 @@ bool ExtensionFunction::HasPermission() {
void ExtensionFunction::OnQuotaExceeded(const std::string& violation_error) {
error_ = violation_error;
- SendResponse(false);
+ SendResponseImpl(false);
}
void ExtensionFunction::SetArgs(const base::ListValue* args) {
@@ -407,7 +407,8 @@ ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() {
ExtensionFunction::ResponseAction ExtensionFunction::RespondNow(
ResponseValue result) {
return ResponseAction(new RespondNowAction(
- std::move(result), base::Bind(&ExtensionFunction::SendResponse, this)));
+ std::move(result),
+ base::Bind(&ExtensionFunction::SendResponseImpl, this)));
}
ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() {
@@ -421,7 +422,7 @@ ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure(
}
void ExtensionFunction::Respond(ResponseValue result) {
- SendResponse(result->Apply());
+ SendResponseImpl(result->Apply());
}
bool ExtensionFunction::PreRunValidation(std::string* error) {
@@ -448,6 +449,8 @@ bool ExtensionFunction::HasOptionalArgument(size_t index) {
void ExtensionFunction::SendResponseImpl(bool success) {
DCHECK(!response_callback_.is_null());
+ DCHECK(!did_respond_) << name_;
+ did_respond_ = true;
ResponseType response = success ? SUCCEEDED : FAILED;
if (bad_message_) {
@@ -462,10 +465,12 @@ void ExtensionFunction::SendResponseImpl(bool success) {
response_callback_.Run(response, *results_, GetError(), histogram_value());
LogUma(success, timer_.Elapsed(), histogram_value_);
+
+ OnResponded();
}
void ExtensionFunction::OnRespondingLater(ResponseValue value) {
lazyboy 2016/09/20 20:21:33 Is OnRespondingLater used still? (I can't find any
Devlin 2016/09/20 21:51:04 Looks like no - good catch!
- SendResponse(value->Apply());
+ SendResponseImpl(value->Apply());
}
UIThreadExtensionFunction::UIThreadExtensionFunction()
@@ -548,11 +553,7 @@ content::WebContents* UIThreadExtensionFunction::GetSenderWebContents() {
content::WebContents::FromRenderFrameHost(render_frame_host_) : nullptr;
}
-void UIThreadExtensionFunction::SendResponse(bool success) {
- DCHECK(!did_respond_) << name_;
- did_respond_ = true;
- SendResponseImpl(success);
-
+void UIThreadExtensionFunction::OnResponded() {
if (!transferred_blob_uuids_.empty()) {
render_frame_host_->Send(
new ExtensionMsg_TransferBlobs(transferred_blob_uuids_));
@@ -590,12 +591,6 @@ void IOThreadExtensionFunction::Destruct() const {
BrowserThread::DeleteOnIOThread::Destruct(this);
}
-void IOThreadExtensionFunction::SendResponse(bool success) {
- DCHECK(!did_respond_) << name_;
- did_respond_ = true;
- SendResponseImpl(success);
-}
-
AsyncExtensionFunction::AsyncExtensionFunction() {
}
@@ -619,3 +614,7 @@ bool AsyncExtensionFunction::ValidationFailure(
AsyncExtensionFunction* function) {
return false;
}
+
+void AsyncExtensionFunction::SendResponse(bool success) {
+ Respond(success ? ArgumentList(std::move(results_)) : Error(error_));
+}

Powered by Google App Engine
This is Rietveld 408576698