diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 11:37:30 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 11:37:30 +0000 |
commit | 5b50d88191babb2cb1e225434ea20b1b621b90f1 (patch) | |
tree | a405ac3fea79d723b19996cce319ec5f3ad12952 /extensions/browser | |
parent | 8679de141b71ab776e267c8cde013147954bfd8b (diff) | |
download | chromium_src-5b50d88191babb2cb1e225434ea20b1b621b90f1.zip chromium_src-5b50d88191babb2cb1e225434ea20b1b621b90f1.tar.gz chromium_src-5b50d88191babb2cb1e225434ea20b1b621b90f1.tar.bz2 |
Remove the redundancy of both EXTENSION_FUNCTION_VALIDATE and
EXTENSION_FUNCTION_VALIDATE_TYPESAFE; make the former return a
"ValidationFailure" type with an operator for each required type, and delete
the latter.
BUG=365732
R=jyasskin@chromium.org
NOTRY=true
Review URL: https://codereview.chromium.org/269153002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser')
-rw-r--r-- | extensions/browser/api/runtime/runtime_api.cc | 2 | ||||
-rw-r--r-- | extensions/browser/api/storage/storage_api.cc | 7 | ||||
-rw-r--r-- | extensions/browser/extension_function.cc | 27 | ||||
-rw-r--r-- | extensions/browser/extension_function.h | 43 |
4 files changed, 55 insertions, 24 deletions
diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc index 942c3a60d..9dc3feb 100644 --- a/extensions/browser/api/runtime/runtime_api.cc +++ b/extensions/browser/api/runtime/runtime_api.cc @@ -427,7 +427,7 @@ void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { ExtensionFunction::ResponseAction RuntimeSetUninstallURLFunction::Run() { std::string url_string; - EXTENSION_FUNCTION_VALIDATE_TYPESAFE(args_->GetString(0, &url_string)); + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); GURL url(url_string); if (!url.is_valid()) { diff --git a/extensions/browser/api/storage/storage_api.cc b/extensions/browser/api/storage/storage_api.cc index 012fe41..1023236 100644 --- a/extensions/browser/api/storage/storage_api.cc +++ b/extensions/browser/api/storage/storage_api.cc @@ -40,13 +40,12 @@ bool SettingsFunction::ShouldSkipQuotaLimiting() const { ExtensionFunction::ResponseAction SettingsFunction::Run() { std::string settings_namespace_string; - EXTENSION_FUNCTION_VALIDATE_TYPESAFE( - args_->GetString(0, &settings_namespace_string)); + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &settings_namespace_string)); args_->Remove(0, NULL); settings_namespace_ = settings_namespace::FromString(settings_namespace_string); - EXTENSION_FUNCTION_VALIDATE_TYPESAFE(settings_namespace_ != - settings_namespace::INVALID); + EXTENSION_FUNCTION_VALIDATE(settings_namespace_ != + settings_namespace::INVALID); StorageFrontend* frontend = StorageFrontend::Get(browser_context()); if (!frontend->IsStorageEnabled(settings_namespace_)) { diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc index 470ae55..ff7d544 100644 --- a/extensions/browser/extension_function.cc +++ b/extensions/browser/extension_function.cc @@ -227,12 +227,18 @@ ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() { ExtensionFunction::ResponseAction ExtensionFunction::RespondNow( ResponseValue result) { - return scoped_ptr<ResponseActionObject>(new RespondNowAction( + return ResponseAction(new RespondNowAction( result.Pass(), base::Bind(&ExtensionFunction::SendResponse, this))); } ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { - return scoped_ptr<ResponseActionObject>(new RespondLaterAction()); + return ResponseAction(new RespondLaterAction()); +} + +// static +ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( + ExtensionFunction* function) { + return function->RespondNow(function->BadMessage()); } void ExtensionFunction::Respond(ResponseValue result) { @@ -364,6 +370,12 @@ ExtensionFunction::ResponseAction AsyncExtensionFunction::Run() { return RunAsync() ? RespondLater() : RespondNow(Error(error_)); } +// static +bool AsyncExtensionFunction::ValidationFailure( + AsyncExtensionFunction* function) { + return false; +} + SyncExtensionFunction::SyncExtensionFunction() { } @@ -375,6 +387,11 @@ ExtensionFunction::ResponseAction SyncExtensionFunction::Run() { : Error(error_)); } +// static +bool SyncExtensionFunction::ValidationFailure(SyncExtensionFunction* function) { + return false; +} + SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { } @@ -385,3 +402,9 @@ ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { return RespondNow(RunSync() ? MultipleArguments(results_.get()) : Error(error_)); } + +// static +bool SyncIOThreadExtensionFunction::ValidationFailure( + SyncIOThreadExtensionFunction* function) { + return false; +} diff --git a/extensions/browser/extension_function.h b/extensions/browser/extension_function.h index 259b86a..9f8cb71 100644 --- a/extensions/browser/extension_function.h +++ b/extensions/browser/extension_function.h @@ -44,28 +44,23 @@ class ExtensionMessageFilter; class QuotaLimitHeuristic; } -#define EXTENSION_FUNCTION_VALIDATE(test) \ - EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, false) - -#define EXTENSION_FUNCTION_VALIDATE_TYPESAFE(test) \ - EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, RespondNow(BadMessage())) - #ifdef NDEBUG -#define EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, failure) \ - do { \ - if (!(test)) { \ - bad_message_ = true; \ - return (failure); \ - } \ +#define EXTENSION_FUNCTION_VALIDATE(test) \ + do { \ + if (!(test)) { \ + bad_message_ = true; \ + return ValidationFailure(this); \ + } \ } while (0) #else // NDEBUG -#define EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, failure) CHECK(test) +#define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) #endif // NDEBUG -#define EXTENSION_FUNCTION_ERROR(error) do { \ - error_ = error; \ - bad_message_ = true; \ - return false; \ +#define EXTENSION_FUNCTION_ERROR(error) \ + do { \ + error_ = error; \ + bad_message_ = true; \ + return ValidationFailure(this); \ } while (0) // Declares a callable extension function with the given |name|. You must also @@ -259,6 +254,11 @@ class ExtensionFunction // Don't respond now, but promise to call Respond() later. ResponseAction RespondLater(); + // This is the return value of the EXTENSION_FUNCTION_VALIDATE macro, which + // needs to work from Run(), RunAsync(), and RunSync(). The former of those + // has a different return type (ResponseAction) than the latter two (bool). + static ResponseAction ValidationFailure(ExtensionFunction* function); + // If RespondLater() was used, functions must at some point call Respond() // with |result| as their result. void Respond(ResponseValue result); @@ -498,6 +498,9 @@ class AsyncExtensionFunction : public UIThreadExtensionFunction { // to respond immediately with an error. virtual bool RunAsync() = 0; + // ValidationFailure override to match RunAsync(). + static bool ValidationFailure(AsyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; @@ -522,6 +525,9 @@ class SyncExtensionFunction : public UIThreadExtensionFunction { // immediately with success, false to respond immediately with an error. virtual bool RunSync() = 0; + // ValidationFailure override to match RunSync(). + static bool ValidationFailure(SyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; @@ -540,6 +546,9 @@ class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction { // error. virtual bool RunSync() = 0; + // ValidationFailure override to match RunSync(). + static bool ValidationFailure(SyncIOThreadExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; |