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

Side by Side Diff: chrome/browser/extensions/convert_user_script.cc

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/convert_user_script.h" 5 #include "chrome/browser/extensions/convert_user_script.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
9 #include <string> 10 #include <string>
11 #include <utility>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/base64.h" 14 #include "base/base64.h"
13 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
16 #include "base/json/json_file_value_serializer.h" 18 #include "base/json/json_file_value_serializer.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 132 }
131 133
132 base::ListValue* includes = new base::ListValue(); 134 base::ListValue* includes = new base::ListValue();
133 for (size_t i = 0; i < script.globs().size(); ++i) 135 for (size_t i = 0; i < script.globs().size(); ++i)
134 includes->AppendString(script.globs().at(i)); 136 includes->AppendString(script.globs().at(i));
135 137
136 base::ListValue* excludes = new base::ListValue(); 138 base::ListValue* excludes = new base::ListValue();
137 for (size_t i = 0; i < script.exclude_globs().size(); ++i) 139 for (size_t i = 0; i < script.exclude_globs().size(); ++i)
138 excludes->AppendString(script.exclude_globs().at(i)); 140 excludes->AppendString(script.exclude_globs().at(i));
139 141
140 base::DictionaryValue* content_script = new base::DictionaryValue(); 142 std::unique_ptr<base::DictionaryValue> content_script(
143 new base::DictionaryValue());
141 content_script->Set(keys::kMatches, matches); 144 content_script->Set(keys::kMatches, matches);
142 content_script->Set(keys::kExcludeMatches, exclude_matches); 145 content_script->Set(keys::kExcludeMatches, exclude_matches);
143 content_script->Set(keys::kIncludeGlobs, includes); 146 content_script->Set(keys::kIncludeGlobs, includes);
144 content_script->Set(keys::kExcludeGlobs, excludes); 147 content_script->Set(keys::kExcludeGlobs, excludes);
145 content_script->Set(keys::kJs, js_files); 148 content_script->Set(keys::kJs, js_files);
146 149
147 if (script.run_location() == UserScript::DOCUMENT_START) 150 if (script.run_location() == UserScript::DOCUMENT_START)
148 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart); 151 content_script->SetString(keys::kRunAt, values::kRunAtDocumentStart);
149 else if (script.run_location() == UserScript::DOCUMENT_END) 152 else if (script.run_location() == UserScript::DOCUMENT_END)
150 content_script->SetString(keys::kRunAt, values::kRunAtDocumentEnd); 153 content_script->SetString(keys::kRunAt, values::kRunAtDocumentEnd);
151 else if (script.run_location() == UserScript::DOCUMENT_IDLE) 154 else if (script.run_location() == UserScript::DOCUMENT_IDLE)
152 // This is the default, but store it just in case we change that. 155 // This is the default, but store it just in case we change that.
153 content_script->SetString(keys::kRunAt, values::kRunAtDocumentIdle); 156 content_script->SetString(keys::kRunAt, values::kRunAtDocumentIdle);
154 157
155 base::ListValue* content_scripts = new base::ListValue(); 158 base::ListValue* content_scripts = new base::ListValue();
156 content_scripts->Append(content_script); 159 content_scripts->Append(std::move(content_script));
157 160
158 root->Set(keys::kContentScripts, content_scripts); 161 root->Set(keys::kContentScripts, content_scripts);
159 162
160 base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename); 163 base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename);
161 JSONFileValueSerializer serializer(manifest_path); 164 JSONFileValueSerializer serializer(manifest_path);
162 if (!serializer.Serialize(*root)) { 165 if (!serializer.Serialize(*root)) {
163 *error = base::ASCIIToUTF16("Could not write JSON."); 166 *error = base::ASCIIToUTF16("Could not write JSON.");
164 return NULL; 167 return NULL;
165 } 168 }
166 169
(...skipping 17 matching lines...) Expand all
184 if (!extension.get()) { 187 if (!extension.get()) {
185 NOTREACHED() << "Could not init extension " << *error; 188 NOTREACHED() << "Could not init extension " << *error;
186 return NULL; 189 return NULL;
187 } 190 }
188 191
189 temp_dir.Take(); // The caller takes ownership of the directory. 192 temp_dir.Take(); // The caller takes ownership of the directory.
190 return extension; 193 return extension;
191 } 194 }
192 195
193 } // namespace extensions 196 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698