summaryrefslogtreecommitdiffstats
path: root/extensions/browser/api_test_utils.cc
diff options
context:
space:
mode:
authorestade <estade@chromium.org>2015-05-22 09:30:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-22 16:30:52 +0000
commitb09312bb5ad1bffaad8a09deea395f1aef2053df (patch)
treeea13602ed858503180cd725d1afe6a4ce73a2bd9 /extensions/browser/api_test_utils.cc
parent2d381b0799c9fbbd33fbfa5ccf6610794d454f71 (diff)
downloadchromium_src-b09312bb5ad1bffaad8a09deea395f1aef2053df.zip
chromium_src-b09312bb5ad1bffaad8a09deea395f1aef2053df.tar.gz
chromium_src-b09312bb5ad1bffaad8a09deea395f1aef2053df.tar.bz2
Use scoped_ptrs in JSONReader::Read functions.
There are many callers, so all could not be updated at once. The old version is renamed to JSONReader::DeprecatedRead, and a new version of JSONReader::Read that returns scoped_ptr takes its place. Much of this patch was generated with sed. Some callsites of the form scoped_ptr<Value> value(Read()); have been updated to scoped_ptr<Value> value = Read(); but most Read() calls are simply converted to DeprecatedRead. Actually updating them is a TODO. BUG=none Review URL: https://codereview.chromium.org/1136643005 Cr-Commit-Position: refs/heads/master@{#331120}
Diffstat (limited to 'extensions/browser/api_test_utils.cc')
-rw-r--r--extensions/browser/api_test_utils.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc
index 1aec2af..4affb86 100644
--- a/extensions/browser/api_test_utils.cc
+++ b/extensions/browser/api_test_utils.cc
@@ -30,15 +30,16 @@ class TestFunctionDispatcherDelegate
DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate);
};
-base::Value* ParseJSON(const std::string& data) {
+scoped_ptr<base::Value> ParseJSON(const std::string& data) {
return base::JSONReader::Read(data);
}
-base::ListValue* ParseList(const std::string& data) {
- base::Value* result = ParseJSON(data);
- base::ListValue* list = NULL;
- result->GetAsList(&list);
- return list;
+scoped_ptr<base::ListValue> ParseList(const std::string& data) {
+ scoped_ptr<base::Value> result = ParseJSON(data);
+ scoped_ptr<base::ListValue> list_result;
+ if (result->GetAsList(nullptr))
+ list_result.reset(static_cast<base::ListValue*>(result.release()));
+ return list_result;
}
// This helps us be able to wait until an UIThreadExtensionFunction calls
@@ -84,11 +85,12 @@ namespace extensions {
namespace api_test_utils {
-base::DictionaryValue* ParseDictionary(const std::string& data) {
- base::Value* result = ParseJSON(data);
- base::DictionaryValue* dict = NULL;
- result->GetAsDictionary(&dict);
- return dict;
+scoped_ptr<base::DictionaryValue> ParseDictionary(const std::string& data) {
+ scoped_ptr<base::Value> result = ParseJSON(data);
+ scoped_ptr<base::DictionaryValue> dict_result;
+ if (result->GetAsDictionary(nullptr))
+ dict_result.reset(static_cast<base::DictionaryValue*>(result.release()));
+ return dict_result;
}
bool GetBoolean(const base::DictionaryValue* val, const std::string& key) {
@@ -137,8 +139,8 @@ scoped_refptr<Extension> CreateExtension(
scoped_refptr<Extension> CreateEmptyExtensionWithLocation(
Manifest::Location location) {
- scoped_ptr<base::DictionaryValue> test_extension_value(
- ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}"));
+ scoped_ptr<base::DictionaryValue> test_extension_value =
+ ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}");
return CreateExtension(location, test_extension_value.get(), std::string());
}
@@ -226,7 +228,7 @@ bool RunFunction(UIThreadExtensionFunction* function,
content::BrowserContext* context,
scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags) {
- scoped_ptr<base::ListValue> parsed_args(ParseList(args));
+ scoped_ptr<base::ListValue> parsed_args = ParseList(args);
EXPECT_TRUE(parsed_args.get())
<< "Could not parse extension function arguments: " << args;
return RunFunction(