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-15 00:12:38 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 00:12:38 +0000
commite5be73af099387cb581890e34faf35de72d2d3c4 (patch)
tree7bf7a2eb4513009d0453acaa2fa7eabcacb758f6 /extensions/browser/extension_function.cc
parentd369a53038fb4837bf1c262a73f254dc481abbf7 (diff)
downloadchromium_src-e5be73af099387cb581890e34faf35de72d2d3c4.zip
chromium_src-e5be73af099387cb581890e34faf35de72d2d3c4.tar.gz
chromium_src-e5be73af099387cb581890e34faf35de72d2d3c4.tar.bz2
Improve error message when ExtensionFunction::NoArguments, SingleArgument, and
MultipleArguments disagree with the result set from SetResult or result_. R=rockot@chromium.org Review URL: https://codereview.chromium.org/277653003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270529 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/extension_function.cc')
-rw-r--r--extensions/browser/extension_function.cc32
1 files changed, 23 insertions, 9 deletions
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index f2cc79d..3d6754c 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -27,10 +27,18 @@ namespace {
class MultipleArgumentsResponseValue
: public ExtensionFunction::ResponseValueObject {
public:
- MultipleArgumentsResponseValue(ExtensionFunction* function,
- base::ListValue* result) {
+ MultipleArgumentsResponseValue(const std::string& function_name,
+ const char* title,
+ ExtensionFunction* function,
+ base::ListValue* result)
+ : function_name_(function_name), title_(title) {
if (function->GetResultList()) {
- DCHECK_EQ(function->GetResultList(), result);
+ DCHECK_EQ(function->GetResultList(), result)
+ << "The result set on this function (" << function_name_ << ") "
+ << "either by calling SetResult() or directly modifying |result_| is "
+ << "different to the one passed to " << title_ << "(). "
+ << "The best way to fix this problem is to exclusively use " << title_
+ << "(). SetResult() and |result_| are deprecated.";
} else {
function->SetResultList(make_scoped_ptr(result));
}
@@ -42,6 +50,10 @@ class MultipleArgumentsResponseValue
virtual ~MultipleArgumentsResponseValue() {}
virtual bool Apply() OVERRIDE { return true; }
+
+ private:
+ std::string function_name_;
+ const char* title_;
};
class ErrorResponseValue : public ExtensionFunction::ResponseValueObject {
@@ -210,29 +222,31 @@ void ExtensionFunction::SetError(const std::string& error) {
}
ExtensionFunction::ResponseValue ExtensionFunction::NoArguments() {
- return MultipleArguments(new base::ListValue());
+ return ResponseValue(new MultipleArgumentsResponseValue(
+ name(), "NoArguments", this, new base::ListValue()));
}
ExtensionFunction::ResponseValue ExtensionFunction::SingleArgument(
base::Value* arg) {
base::ListValue* args = new base::ListValue();
args->Append(arg);
- return MultipleArguments(args);
+ return ResponseValue(
+ new MultipleArgumentsResponseValue(name(), "SingleArgument", this, args));
}
ExtensionFunction::ResponseValue ExtensionFunction::MultipleArguments(
base::ListValue* args) {
- return scoped_ptr<ResponseValueObject>(
- new MultipleArgumentsResponseValue(this, args));
+ return ResponseValue(new MultipleArgumentsResponseValue(
+ name(), "MultipleArguments", this, args));
}
ExtensionFunction::ResponseValue ExtensionFunction::Error(
const std::string& error) {
- return scoped_ptr<ResponseValueObject>(new ErrorResponseValue(this, error));
+ return ResponseValue(new ErrorResponseValue(this, error));
}
ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() {
- return scoped_ptr<ResponseValueObject>(new BadMessageResponseValue(this));
+ return ResponseValue(new BadMessageResponseValue(this));
}
ExtensionFunction::ResponseAction ExtensionFunction::RespondNow(