Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Unified Diff: chrome/browser/extensions/convert_user_script.cc

Issue 2811673002: Reland: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Workaround with std::move Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/convert_user_script.cc
diff --git a/chrome/browser/extensions/convert_user_script.cc b/chrome/browser/extensions/convert_user_script.cc
index bc0362807d7166502b8be90d7ae8d5c6cac236b1..4ecbe013e659ddff7e0b5f93a5e9cbf8011774b6 100644
--- a/chrome/browser/extensions/convert_user_script.cc
+++ b/chrome/browser/extensions/convert_user_script.cc
@@ -16,8 +16,10 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/common/chrome_paths.h"
#include "crypto/sha2.h"
#include "extensions/browser/extension_user_script_loader.h"
@@ -104,12 +106,12 @@ scoped_refptr<Extension> ConvertUserScriptToExtension(
root->SetString(keys::kPublicKey, key);
root->SetBoolean(keys::kConvertedFromUserScript, true);
- base::ListValue* js_files = new base::ListValue();
+ auto js_files = base::MakeUnique<base::ListValue>();
js_files->AppendString("script.js");
// If the script provides its own match patterns, we use those. Otherwise, we
// generate some using the include globs.
- base::ListValue* matches = new base::ListValue();
+ auto matches = base::MakeUnique<base::ListValue>();
if (!script.url_patterns().is_empty()) {
for (URLPatternSet::const_iterator i = script.url_patterns().begin();
i != script.url_patterns().end(); ++i) {
@@ -122,7 +124,7 @@ scoped_refptr<Extension> ConvertUserScriptToExtension(
}
// Read the exclude matches, if any are present.
- base::ListValue* exclude_matches = new base::ListValue();
+ auto exclude_matches = base::MakeUnique<base::ListValue>();
if (!script.exclude_url_patterns().is_empty()) {
for (URLPatternSet::const_iterator i =
script.exclude_url_patterns().begin();
@@ -131,21 +133,20 @@ scoped_refptr<Extension> ConvertUserScriptToExtension(
}
}
- base::ListValue* includes = new base::ListValue();
+ auto includes = base::MakeUnique<base::ListValue>();
for (size_t i = 0; i < script.globs().size(); ++i)
includes->AppendString(script.globs().at(i));
- base::ListValue* excludes = new base::ListValue();
+ auto excludes = base::MakeUnique<base::ListValue>();
for (size_t i = 0; i < script.exclude_globs().size(); ++i)
excludes->AppendString(script.exclude_globs().at(i));
- std::unique_ptr<base::DictionaryValue> content_script(
- new base::DictionaryValue());
- content_script->Set(keys::kMatches, matches);
- content_script->Set(keys::kExcludeMatches, exclude_matches);
- content_script->Set(keys::kIncludeGlobs, includes);
- content_script->Set(keys::kExcludeGlobs, excludes);
- content_script->Set(keys::kJs, js_files);
+ auto content_script = base::MakeUnique<base::DictionaryValue>();
+ content_script->Set(keys::kMatches, std::move(matches));
+ content_script->Set(keys::kExcludeMatches, std::move(exclude_matches));
+ content_script->Set(keys::kIncludeGlobs, std::move(includes));
+ content_script->Set(keys::kExcludeGlobs, std::move(excludes));
+ content_script->Set(keys::kJs, std::move(js_files));
if (script.run_location() == UserScript::DOCUMENT_START)
content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart);
@@ -155,10 +156,10 @@ scoped_refptr<Extension> ConvertUserScriptToExtension(
// This is the default, but store it just in case we change that.
content_script->SetString(keys::kRunAt, values::kRunAtDocumentIdle);
- base::ListValue* content_scripts = new base::ListValue();
+ auto content_scripts = base::MakeUnique<base::ListValue>();
content_scripts->Append(std::move(content_script));
- root->Set(keys::kContentScripts, content_scripts);
+ root->Set(keys::kContentScripts, std::move(content_scripts));
base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename);
JSONFileValueSerializer serializer(manifest_path);

Powered by Google App Engine
This is Rietveld 408576698