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

Unified Diff: extensions/browser/extension_function.cc

Issue 257333002: Drive extension functions from ExtensionFunction::Run. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix test Created 6 years, 8 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 7e9a19499b49d84a05728609387b98cad2dca407..39df603bae86546ebe8c9556e72aeb953a2c1b95 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -45,7 +45,8 @@ class MultipleArgumentsResponseValue
class ErrorResponseValue : public ExtensionFunction::ResponseValueObject {
public:
ErrorResponseValue(ExtensionFunction* function, const std::string& error) {
- DCHECK_NE("", error);
+ // It would be nice to DCHECK(!error.empty()) but too many legacy extension
+ // function implementations don't set error but signal failure.
function->SetError(error);
}
@@ -232,24 +233,8 @@ ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() {
return scoped_ptr<ResponseActionObject>(new RespondLaterAction());
}
-void ExtensionFunction::Run() {
- if (!RunImpl())
- SendResponse(false);
-}
-
-bool ExtensionFunction::RunImpl() {
- RunImplTypesafe()->Execute();
- return true;
-}
-
-ExtensionFunction::ResponseAction ExtensionFunction::RunImplTypesafe() {
- NOTREACHED()
- << "ExtensionFunctions must override either RunImpl or RunImplTypesafe";
- return RespondNow(NoArguments());
-}
-
-void ExtensionFunction::SendResponseTypesafe(ResponseValue response) {
- SendResponse(response->Apply());
+void ExtensionFunction::Done(ResponseValue result) {
+ SendResponse(result->Apply());
}
bool ExtensionFunction::ShouldSkipQuotaLimiting() const {
@@ -277,6 +262,10 @@ void ExtensionFunction::SendResponseImpl(bool success) {
response_callback_.Run(type, *results_, GetError());
}
+void ExtensionFunction::OnRespondingLater(ResponseValue value) {
+ SendResponse(value->Apply());
+}
+
UIThreadExtensionFunction::UIThreadExtensionFunction()
: render_view_host_(NULL),
render_frame_host_(NULL),
@@ -369,15 +358,19 @@ AsyncExtensionFunction::AsyncExtensionFunction() {
AsyncExtensionFunction::~AsyncExtensionFunction() {
}
+ExtensionFunction::ResponseAction AsyncExtensionFunction::Run() {
+ return RunAsync() ? RespondLater() : RespondNow(Error(error_));
+}
+
SyncExtensionFunction::SyncExtensionFunction() {
}
SyncExtensionFunction::~SyncExtensionFunction() {
}
-bool SyncExtensionFunction::RunImpl() {
- SendResponse(RunSync());
- return true;
+ExtensionFunction::ResponseAction SyncExtensionFunction::Run() {
+ return RespondNow(RunSync() ? MultipleArguments(results_.get())
+ : Error(error_));
}
SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() {
@@ -386,7 +379,7 @@ SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() {
SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() {
}
-bool SyncIOThreadExtensionFunction::RunImpl() {
- SendResponse(RunSync());
- return true;
+ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() {
+ return RespondNow(RunSync() ? MultipleArguments(results_.get())
+ : Error(error_));
}

Powered by Google App Engine
This is Rietveld 408576698