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

Unified Diff: chrome/browser/extensions/chrome_extension_function.cc

Issue 2360073002: [Extensions] Isolate ExtensionFunction results_ and error_ (Closed)
Patch Set: errorwithargs 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: chrome/browser/extensions/chrome_extension_function.cc
diff --git a/chrome/browser/extensions/chrome_extension_function.cc b/chrome/browser/extensions/chrome_extension_function.cc
index 9f87083da21b153b82f45b9272c5a60cf12cfd63..d71673a0b44ad92500794f220feaf1e0126605e5 100644
--- a/chrome/browser/extensions/chrome_extension_function.cc
+++ b/chrome/browser/extensions/chrome_extension_function.cc
@@ -42,8 +42,34 @@ ChromeUIThreadExtensionFunction::GetAssociatedWebContents() {
return chrome_details_.GetAssociatedWebContents();
}
+void ChromeUIThreadExtensionFunction::SetError(const std::string& error) {
+ error_ = error;
+}
+
+const std::string& ChromeUIThreadExtensionFunction::GetError() const {
+ return error_.empty() ? UIThreadExtensionFunction::GetError() : error_;
+}
+
void ChromeUIThreadExtensionFunction::SendResponse(bool success) {
- Respond(success ? ArgumentList(std::move(results_)) : Error(error_));
+ ResponseValue response;
+ if (success) {
+ response = ArgumentList(std::move(results_));
+ } else {
+ response = results_ ? ErrorWithArguments(std::move(results_), error_)
+ : Error(error_);
+ }
+ Respond(std::move(response));
+}
+
+void ChromeUIThreadExtensionFunction::SetResult(
+ std::unique_ptr<base::Value> result) {
+ results_.reset(new base::ListValue());
+ results_->Append(std::move(result));
+}
+
+void ChromeUIThreadExtensionFunction::SetResultList(
+ std::unique_ptr<base::ListValue> results) {
+ results_ = std::move(results);
}
ChromeUIThreadExtensionFunction::~ChromeUIThreadExtensionFunction() {
@@ -55,7 +81,13 @@ ChromeAsyncExtensionFunction::ChromeAsyncExtensionFunction() {
ChromeAsyncExtensionFunction::~ChromeAsyncExtensionFunction() {}
ExtensionFunction::ResponseAction ChromeAsyncExtensionFunction::Run() {
- return RunAsync() ? RespondLater() : RespondNow(Error(error_));
+ if (RunAsync())
+ return RespondLater();
+ // TODO(devlin): Track these down and eliminate them if possible. We
+ // shouldn't return results and an error.
+ if (results_)
+ return RespondNow(ErrorWithArguments(std::move(results_), error_));
+ return RespondNow(Error(error_));
}
// static
@@ -70,8 +102,11 @@ ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() {
ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {}
ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() {
- return RespondNow(RunSync() ? ArgumentList(std::move(results_))
- : Error(error_));
+ if (!RunSync()) {
+ DCHECK(!results_);
+ return RespondNow(Error(error_));
+ }
+ return RespondNow(ArgumentList(std::move(results_)));
}
// static

Powered by Google App Engine
This is Rietveld 408576698