summaryrefslogtreecommitdiffstats
path: root/extensions/browser/extension_function.cc
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-03 03:41:43 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-03 03:41:43 +0000
commita0c91a9ffb1db127cf1f06e285b208a544ed4567 (patch)
treefe0e8f09a1c04cab35592cd46f9c01c045f95681 /extensions/browser/extension_function.cc
parent68d3f6bbacbde53e968ae36ae3e4231ea1a8be4b (diff)
downloadchromium_src-a0c91a9ffb1db127cf1f06e285b208a544ed4567.zip
chromium_src-a0c91a9ffb1db127cf1f06e285b208a544ed4567.tar.gz
chromium_src-a0c91a9ffb1db127cf1f06e285b208a544ed4567.tar.bz2
Drive extension functions from ExtensionFunction::Run. The
SyncExtensionFunction and AsyncExtensionFunction derivates now expose RunSync and RunAsync respectively. New extension function implementations should just implement Run directly. BUG=365732 R=rockot@chromium.org TBR=dmazzoni@chromium.org Review URL: https://codereview.chromium.org/257333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268033 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/extension_function.cc')
-rw-r--r--extensions/browser/extension_function.cc47
1 files changed, 21 insertions, 26 deletions
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index 7e9a194..470ae55 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -34,7 +34,9 @@ class MultipleArgumentsResponseValue
} else {
function->SetResultList(make_scoped_ptr(result));
}
- DCHECK_EQ("", function->GetError());
+ // It would be nice to DCHECK(error.empty()) but some legacy extension
+ // function implementations... I'm looking at chrome.input.ime... do this
+ // for some reason.
}
virtual ~MultipleArgumentsResponseValue() {}
@@ -45,7 +47,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 +235,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::Respond(ResponseValue result) {
+ SendResponse(result->Apply());
}
bool ExtensionFunction::ShouldSkipQuotaLimiting() const {
@@ -277,6 +264,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 +360,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 +381,7 @@ SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() {
SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() {
}
-bool SyncIOThreadExtensionFunction::RunImpl() {
- SendResponse(RunSync());
- return true;
+ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() {
+ return RespondNow(RunSync() ? MultipleArguments(results_.get())
+ : Error(error_));
}