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

Side by Side Diff: extensions/common/file_util.cc

Issue 1308013005: Add scoped_ptr-safe base::Value to Dictionary/List conversion functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made conversions static members. Created 5 years, 3 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
« no previous file with comments | « extensions/common/file_util.h ('k') | extensions/common/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/common/file_util.h" 5 #include "extensions/common/file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int flags, 187 int flags,
188 std::string* error) { 188 std::string* error) {
189 return LoadExtension(extension_path, std::string(), location, flags, error); 189 return LoadExtension(extension_path, std::string(), location, flags, error);
190 } 190 }
191 191
192 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, 192 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
193 const std::string& extension_id, 193 const std::string& extension_id,
194 Manifest::Location location, 194 Manifest::Location location,
195 int flags, 195 int flags,
196 std::string* error) { 196 std::string* error) {
197 scoped_ptr<base::DictionaryValue> manifest( 197 scoped_ptr<base::DictionaryValue> manifest =
198 LoadManifest(extension_path, error)); 198 LoadManifest(extension_path, error);
199 if (!manifest.get()) 199 if (!manifest.get())
200 return NULL; 200 return NULL;
201 if (!extension_l10n_util::LocalizeExtension( 201 if (!extension_l10n_util::LocalizeExtension(
202 extension_path, manifest.get(), error)) { 202 extension_path, manifest.get(), error)) {
203 return NULL; 203 return NULL;
204 } 204 }
205 205
206 scoped_refptr<Extension> extension(Extension::Create( 206 scoped_refptr<Extension> extension(Extension::Create(
207 extension_path, location, *manifest, flags, extension_id, error)); 207 extension_path, location, *manifest, flags, extension_id, error));
208 if (!extension.get()) 208 if (!extension.get())
209 return NULL; 209 return NULL;
210 210
211 std::vector<InstallWarning> warnings; 211 std::vector<InstallWarning> warnings;
212 if (!ValidateExtension(extension.get(), error, &warnings)) 212 if (!ValidateExtension(extension.get(), error, &warnings))
213 return NULL; 213 return NULL;
214 extension->AddInstallWarnings(warnings); 214 extension->AddInstallWarnings(warnings);
215 215
216 return extension; 216 return extension;
217 } 217 }
218 218
219 base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, 219 scoped_ptr<base::DictionaryValue> LoadManifest(
220 std::string* error) { 220 const base::FilePath& extension_path,
221 std::string* error) {
221 return LoadManifest(extension_path, kManifestFilename, error); 222 return LoadManifest(extension_path, kManifestFilename, error);
222 } 223 }
223 224
224 base::DictionaryValue* LoadManifest( 225 scoped_ptr<base::DictionaryValue> LoadManifest(
225 const base::FilePath& extension_path, 226 const base::FilePath& extension_path,
226 const base::FilePath::CharType* manifest_filename, 227 const base::FilePath::CharType* manifest_filename,
227 std::string* error) { 228 std::string* error) {
228 base::FilePath manifest_path = extension_path.Append(manifest_filename); 229 base::FilePath manifest_path = extension_path.Append(manifest_filename);
229 if (!base::PathExists(manifest_path)) { 230 if (!base::PathExists(manifest_path)) {
230 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); 231 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
231 return NULL; 232 return NULL;
232 } 233 }
233 234
234 JSONFileValueDeserializer deserializer(manifest_path); 235 JSONFileValueDeserializer deserializer(manifest_path);
(...skipping 10 matching lines...) Expand all
245 "%s %s", manifest_errors::kManifestParseError, error->c_str()); 246 "%s %s", manifest_errors::kManifestParseError, error->c_str());
246 } 247 }
247 return NULL; 248 return NULL;
248 } 249 }
249 250
250 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { 251 if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
251 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); 252 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID);
252 return NULL; 253 return NULL;
253 } 254 }
254 255
255 return static_cast<base::DictionaryValue*>(root.release()); 256 return base::DictionaryValue::From(root.Pass());
256 } 257 }
257 258
258 bool ValidateExtension(const Extension* extension, 259 bool ValidateExtension(const Extension* extension,
259 std::string* error, 260 std::string* error,
260 std::vector<InstallWarning>* warnings) { 261 std::vector<InstallWarning>* warnings) {
261 // Ask registered manifest handlers to validate their paths. 262 // Ask registered manifest handlers to validate their paths.
262 if (!ManifestHandler::ValidateExtension(extension, error, warnings)) 263 if (!ManifestHandler::ValidateExtension(extension, error, warnings))
263 return false; 264 return false;
264 265
265 // Check children of extension root to see if any of them start with _ and is 266 // Check children of extension root to see if any of them start with _ and is
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { 603 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) {
603 return extension_path.Append(kMetadataFolder) 604 return extension_path.Append(kMetadataFolder)
604 .Append(kVerifiedContentsFilename); 605 .Append(kVerifiedContentsFilename);
605 } 606 }
606 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { 607 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) {
607 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); 608 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename);
608 } 609 }
609 610
610 } // namespace file_util 611 } // namespace file_util
611 } // namespace extensions 612 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/file_util.h ('k') | extensions/common/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698