Commit 32f22508 authored by kalman@chromium.org's avatar kalman@chromium.org

Make ExtensionFunction::ArgumentList (PKA MultipleArguments) take a scoped_ptr

rather than a raw pointer, because it plays better with the JSON schema compiler
generated code. Also add a TwoArguments method, and rename SingleArgument to
OneArgument to be consistent with that.

BUG=365732
R=rockot@chromium.org

Review URL: https://codereview.chromium.org/291453002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271757 0039d316-1c4b-4281-b951-d872f2087c98
parent d7dc7e54
...@@ -67,7 +67,7 @@ ExtensionFunction::ResponseAction ShellCreateWindowFunction::Run() { ...@@ -67,7 +67,7 @@ ExtensionFunction::ResponseAction ShellCreateWindowFunction::Run() {
app_window->LoadURL(url); app_window->LoadURL(url);
// Create the reply to send to the renderer. // Create the reply to send to the renderer.
return RespondNow(SingleArgument(CreateResult(app_window))); return RespondNow(OneArgument(CreateResult(app_window)));
} }
} // namespace apps } // namespace apps
...@@ -76,10 +76,9 @@ AutomationInternalEnableCurrentTabFunction::Run() { ...@@ -76,10 +76,9 @@ AutomationInternalEnableCurrentTabFunction::Run() {
return RespondNow(Error("Could not enable accessibility for active tab")); return RespondNow(Error("Could not enable accessibility for active tab"));
AutomationWebContentsObserver::CreateForWebContents(contents); AutomationWebContentsObserver::CreateForWebContents(contents);
rwh->EnableTreeOnlyAccessibilityMode(); rwh->EnableTreeOnlyAccessibilityMode();
scoped_ptr<base::ListValue> results = return RespondNow(
api::automation_internal::EnableCurrentTab::Results::Create( ArgumentList(api::automation_internal::EnableCurrentTab::Results::Create(
rwh->GetProcess()->GetID(), rwh->GetRoutingID()); rwh->GetProcess()->GetID(), rwh->GetRoutingID())));
return RespondNow(MultipleArguments(results.release()));
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
......
...@@ -275,7 +275,7 @@ ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() { ...@@ -275,7 +275,7 @@ ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() {
infos->Append(account_info.ToValue().release()); infos->Append(account_info.ToValue().release());
} }
return RespondNow(SingleArgument(infos)); return RespondNow(OneArgument(infos));
} }
IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction()
......
...@@ -131,8 +131,7 @@ ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() { ...@@ -131,8 +131,7 @@ ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() {
ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {} ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {}
ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() { ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() {
return RespondNow(RunSync() ? MultipleArguments(results_.get()) return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_));
: Error(error_));
} }
// static // static
......
...@@ -460,14 +460,12 @@ ExtensionFunction::ResponseAction RuntimeRequestUpdateCheckFunction::Run() { ...@@ -460,14 +460,12 @@ ExtensionFunction::ResponseAction RuntimeRequestUpdateCheckFunction::Run() {
void RuntimeRequestUpdateCheckFunction::CheckComplete( void RuntimeRequestUpdateCheckFunction::CheckComplete(
const RuntimeAPIDelegate::UpdateCheckResult& result) { const RuntimeAPIDelegate::UpdateCheckResult& result) {
if (result.success) { if (result.success) {
base::ListValue* results = new base::ListValue;
results->AppendString(result.response);
base::DictionaryValue* details = new base::DictionaryValue; base::DictionaryValue* details = new base::DictionaryValue;
results->Append(details);
details->SetString("version", result.version); details->SetString("version", result.version);
Respond(MultipleArguments(results)); Respond(TwoArguments(new base::StringValue(result.response), details));
} else { } else {
Respond(SingleArgument(new base::StringValue(result.response))); // HMM(kalman): Why does !success not imply Error()?
Respond(OneArgument(new base::StringValue(result.response)));
} }
} }
...@@ -489,8 +487,8 @@ ExtensionFunction::ResponseAction RuntimeGetPlatformInfoFunction::Run() { ...@@ -489,8 +487,8 @@ ExtensionFunction::ResponseAction RuntimeGetPlatformInfoFunction::Run() {
->GetPlatformInfo(&info)) { ->GetPlatformInfo(&info)) {
return RespondNow(Error(kPlatformInfoUnavailable)); return RespondNow(Error(kPlatformInfoUnavailable));
} }
return RespondNow(MultipleArguments( return RespondNow(
runtime::GetPlatformInfo::Results::Create(info).release())); ArgumentList(runtime::GetPlatformInfo::Results::Create(info)));
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
...@@ -511,7 +509,7 @@ RuntimeGetPackageDirectoryEntryFunction::Run() { ...@@ -511,7 +509,7 @@ RuntimeGetPackageDirectoryEntryFunction::Run() {
base::DictionaryValue* dict = new base::DictionaryValue(); base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("fileSystemId", filesystem_id); dict->SetString("fileSystemId", filesystem_id);
dict->SetString("baseName", relative_path); dict->SetString("baseName", relative_path);
return RespondNow(SingleArgument(dict)); return RespondNow(OneArgument(dict));
} }
} // namespace extensions } // namespace extensions
...@@ -78,7 +78,7 @@ ExtensionFunction::ResponseValue SettingsFunction::UseReadResult( ...@@ -78,7 +78,7 @@ ExtensionFunction::ResponseValue SettingsFunction::UseReadResult(
base::DictionaryValue* dict = new base::DictionaryValue(); base::DictionaryValue* dict = new base::DictionaryValue();
dict->Swap(&result->settings()); dict->Swap(&result->settings());
return SingleArgument(dict); return OneArgument(dict);
} }
ExtensionFunction::ResponseValue SettingsFunction::UseWriteResult( ExtensionFunction::ResponseValue SettingsFunction::UseWriteResult(
...@@ -249,7 +249,7 @@ StorageStorageAreaGetBytesInUseFunction::RunWithStorage(ValueStore* storage) { ...@@ -249,7 +249,7 @@ StorageStorageAreaGetBytesInUseFunction::RunWithStorage(ValueStore* storage) {
return BadMessage(); return BadMessage();
} }
return SingleArgument( return OneArgument(
new base::FundamentalValue(static_cast<int>(bytes_in_use))); new base::FundamentalValue(static_cast<int>(bytes_in_use)));
} }
......
...@@ -24,30 +24,30 @@ using extensions::Feature; ...@@ -24,30 +24,30 @@ using extensions::Feature;
namespace { namespace {
class MultipleArgumentsResponseValue class ArgumentListResponseValue
: public ExtensionFunction::ResponseValueObject { : public ExtensionFunction::ResponseValueObject {
public: public:
MultipleArgumentsResponseValue(const std::string& function_name, ArgumentListResponseValue(const std::string& function_name,
const char* title, const char* title,
ExtensionFunction* function, ExtensionFunction* function,
base::ListValue* result) scoped_ptr<base::ListValue> result)
: function_name_(function_name), title_(title) { : function_name_(function_name), title_(title) {
if (function->GetResultList()) { if (function->GetResultList()) {
DCHECK_EQ(function->GetResultList(), result) DCHECK_EQ(function->GetResultList(), result.get())
<< "The result set on this function (" << function_name_ << ") " << "The result set on this function (" << function_name_ << ") "
<< "either by calling SetResult() or directly modifying |result_| is " << "either by calling SetResult() or directly modifying |result_| is "
<< "different to the one passed to " << title_ << "(). " << "different to the one passed to " << title_ << "(). "
<< "The best way to fix this problem is to exclusively use " << title_ << "The best way to fix this problem is to exclusively use " << title_
<< "(). SetResult() and |result_| are deprecated."; << "(). SetResult() and |result_| are deprecated.";
} else { } else {
function->SetResultList(make_scoped_ptr(result)); function->SetResultList(result.Pass());
} }
// It would be nice to DCHECK(error.empty()) but some legacy extension // It would be nice to DCHECK(error.empty()) but some legacy extension
// function implementations... I'm looking at chrome.input.ime... do this // function implementations... I'm looking at chrome.input.ime... do this
// for some reason. // for some reason.
} }
virtual ~MultipleArgumentsResponseValue() {} virtual ~ArgumentListResponseValue() {}
virtual bool Apply() OVERRIDE { return true; } virtual bool Apply() OVERRIDE { return true; }
...@@ -222,22 +222,32 @@ void ExtensionFunction::SetError(const std::string& error) { ...@@ -222,22 +222,32 @@ void ExtensionFunction::SetError(const std::string& error) {
} }
ExtensionFunction::ResponseValue ExtensionFunction::NoArguments() { ExtensionFunction::ResponseValue ExtensionFunction::NoArguments() {
return ResponseValue(new MultipleArgumentsResponseValue( return ResponseValue(new ArgumentListResponseValue(
name(), "NoArguments", this, new base::ListValue())); name(), "NoArguments", this, make_scoped_ptr(new base::ListValue())));
} }
ExtensionFunction::ResponseValue ExtensionFunction::SingleArgument( ExtensionFunction::ResponseValue ExtensionFunction::OneArgument(
base::Value* arg) { base::Value* arg) {
base::ListValue* args = new base::ListValue(); scoped_ptr<base::ListValue> args(new base::ListValue());
args->Append(arg); args->Append(arg);
return ResponseValue( return ResponseValue(
new MultipleArgumentsResponseValue(name(), "SingleArgument", this, args)); new ArgumentListResponseValue(name(), "OneArgument", this, args.Pass()));
} }
ExtensionFunction::ResponseValue ExtensionFunction::MultipleArguments( ExtensionFunction::ResponseValue ExtensionFunction::TwoArguments(
base::ListValue* args) { base::Value* arg1,
return ResponseValue(new MultipleArgumentsResponseValue( base::Value* arg2) {
name(), "MultipleArguments", this, args)); scoped_ptr<base::ListValue> args(new base::ListValue());
args->Append(arg1);
args->Append(arg2);
return ResponseValue(
new ArgumentListResponseValue(name(), "TwoArguments", this, args.Pass()));
}
ExtensionFunction::ResponseValue ExtensionFunction::ArgumentList(
scoped_ptr<base::ListValue> args) {
return ResponseValue(
new ArgumentListResponseValue(name(), "ArgumentList", this, args.Pass()));
} }
ExtensionFunction::ResponseValue ExtensionFunction::Error( ExtensionFunction::ResponseValue ExtensionFunction::Error(
...@@ -407,8 +417,7 @@ SyncExtensionFunction::~SyncExtensionFunction() { ...@@ -407,8 +417,7 @@ SyncExtensionFunction::~SyncExtensionFunction() {
} }
ExtensionFunction::ResponseAction SyncExtensionFunction::Run() { ExtensionFunction::ResponseAction SyncExtensionFunction::Run() {
return RespondNow(RunSync() ? MultipleArguments(results_.get()) return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_));
: Error(error_));
} }
// static // static
...@@ -423,8 +432,7 @@ SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { ...@@ -423,8 +432,7 @@ SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() {
} }
ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() {
return RespondNow(RunSync() ? MultipleArguments(results_.get()) return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_));
: Error(error_));
} }
// static // static
......
...@@ -115,7 +115,7 @@ class ExtensionFunction ...@@ -115,7 +115,7 @@ class ExtensionFunction
// The result of a function call. // The result of a function call.
// //
// Use NoArguments(), SingleArgument(), MultipleArguments(), or Error() // Use NoArguments(), OneArgument(), ArgumentList(), or Error()
// rather than this class directly. // rather than this class directly.
class ResponseValueObject { class ResponseValueObject {
public: public:
...@@ -142,8 +142,8 @@ class ExtensionFunction ...@@ -142,8 +142,8 @@ class ExtensionFunction
// //
// Typical return values might be: // Typical return values might be:
// * RespondNow(NoArguments()) // * RespondNow(NoArguments())
// * RespondNow(SingleArgument(42)) // * RespondNow(OneArgument(42))
// * RespondNow(MultipleArguments(my_result.ToValue())) // * RespondNow(ArgumentList(my_result.ToValue()))
// * RespondNow(Error("Warp core breach")) // * RespondNow(Error("Warp core breach"))
// * RespondLater(), then later, // * RespondLater(), then later,
// * Respond(NoArguments()) // * Respond(NoArguments())
...@@ -248,10 +248,20 @@ class ExtensionFunction ...@@ -248,10 +248,20 @@ class ExtensionFunction
// //
// Success, no arguments to pass to caller // Success, no arguments to pass to caller
ResponseValue NoArguments(); ResponseValue NoArguments();
// Success, a single argument |result| to pass to caller. TAKES OWNERSHIP. // Success, a single argument |arg| to pass to caller. TAKES OWNERSHIP -- a
ResponseValue SingleArgument(base::Value* result); // raw pointer for convenience, since callers usually construct the argument
// Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP. // to this by hand.
ResponseValue MultipleArguments(base::ListValue* results); ResponseValue OneArgument(base::Value* arg);
// Success, two arguments |arg1| and |arg2| to pass to caller. TAKES
// OWNERSHIP -- raw pointers for convenience, since callers usually construct
// the argument to this by hand. Note that use of this function may imply you
// should be using the generated Result struct and ArgumentList.
ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2);
// Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP
// --
// a scoped_ptr<> for convenience, since callers usually get this from the
// result of a ToValue() call on the generated Result struct.
ResponseValue ArgumentList(scoped_ptr<base::ListValue> results);
// Error. chrome.runtime.lastError.message will be set to |error|. // Error. chrome.runtime.lastError.message will be set to |error|.
ResponseValue Error(const std::string& error); ResponseValue Error(const std::string& error);
// Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(). // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment