summaryrefslogtreecommitdiffstats
path: root/extensions/browser/api_test_utils.cc
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-09-10 17:25:54 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-11 00:26:37 +0000
commit259c0a3f44bdd8130c5d835e9f596624a079fbd1 (patch)
tree8c69523a7745aa71e6d67cdedad5b5ce0336b4a9 /extensions/browser/api_test_utils.cc
parent9a1461f5cbacfc7d5c40ac2cd2cc0ec104e9b39c (diff)
downloadchromium_src-259c0a3f44bdd8130c5d835e9f596624a079fbd1.zip
chromium_src-259c0a3f44bdd8130c5d835e9f596624a079fbd1.tar.gz
chromium_src-259c0a3f44bdd8130c5d835e9f596624a079fbd1.tar.bz2
Add scoped_ptr-safe base::Value to Dictionary/List conversion functions.
This change adds two static From() functions to the DictionaryValue and ListValue classes which take a scoped_ptr to a Value and either convert it to a scoped_ptr to a DictionaryValue or ListValue, or return nullptr. These are intended to replace the existing pattern, make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())) with the shorter and safer alternative, base::DictionaryValue::From(value.Pass()) Instances of this pattern in //extensions have been converted as examples. Review URL: https://codereview.chromium.org/1308013005 Cr-Commit-Position: refs/heads/master@{#348294}
Diffstat (limited to 'extensions/browser/api_test_utils.cc')
-rw-r--r--extensions/browser/api_test_utils.cc12
1 files changed, 2 insertions, 10 deletions
diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc
index 587f8e2..47bcb0e 100644
--- a/extensions/browser/api_test_utils.cc
+++ b/extensions/browser/api_test_utils.cc
@@ -24,11 +24,7 @@ scoped_ptr<base::Value> ParseJSON(const std::string& data) {
}
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;
+ return base::ListValue::From(ParseJSON(data));
}
// This helps us be able to wait until an UIThreadExtensionFunction calls
@@ -75,11 +71,7 @@ namespace extensions {
namespace api_test_utils {
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;
+ return base::DictionaryValue::From(ParseJSON(data));
}
bool GetBoolean(const base::DictionaryValue* val, const std::string& key) {