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

Side by Side Diff: extensions/utility/unpacker.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/utility/unpacker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/utility/unpacker.h" 5 #include "extensions/utility/unpacker.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 extension_dir_(extension_dir), 105 extension_dir_(extension_dir),
106 extension_id_(extension_id), 106 extension_id_(extension_id),
107 location_(location), 107 location_(location),
108 creation_flags_(creation_flags) { 108 creation_flags_(creation_flags) {
109 internal_data_.reset(new InternalData()); 109 internal_data_.reset(new InternalData());
110 } 110 }
111 111
112 Unpacker::~Unpacker() { 112 Unpacker::~Unpacker() {
113 } 113 }
114 114
115 base::DictionaryValue* Unpacker::ReadManifest() { 115 scoped_ptr<base::DictionaryValue> Unpacker::ReadManifest() {
116 base::FilePath manifest_path = extension_dir_.Append(kManifestFilename); 116 base::FilePath manifest_path = extension_dir_.Append(kManifestFilename);
117 if (!base::PathExists(manifest_path)) { 117 if (!base::PathExists(manifest_path)) {
118 SetError(errors::kInvalidManifest); 118 SetError(errors::kInvalidManifest);
119 return NULL; 119 return NULL;
120 } 120 }
121 121
122 JSONFileValueDeserializer deserializer(manifest_path); 122 JSONFileValueDeserializer deserializer(manifest_path);
123 std::string error; 123 std::string error;
124 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error)); 124 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error));
125 if (!root.get()) { 125 if (!root.get()) {
126 SetError(error); 126 SetError(error);
127 return NULL; 127 return NULL;
128 } 128 }
129 129
130 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { 130 if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
131 SetError(errors::kInvalidManifest); 131 SetError(errors::kInvalidManifest);
132 return NULL; 132 return NULL;
133 } 133 }
134 134
135 return static_cast<base::DictionaryValue*>(root.release()); 135 return base::DictionaryValue::From(root.Pass());
136 } 136 }
137 137
138 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) { 138 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) {
139 base::FilePath locales_path = extension_dir_.Append(kLocaleFolder); 139 base::FilePath locales_path = extension_dir_.Append(kLocaleFolder);
140 140
141 // Not all folders under _locales have to be valid locales. 141 // Not all folders under _locales have to be valid locales.
142 base::FileEnumerator locales(locales_path, false, 142 base::FileEnumerator locales(locales_path, false,
143 base::FileEnumerator::DIRECTORIES); 143 base::FileEnumerator::DIRECTORIES);
144 144
145 std::set<std::string> all_locales; 145 std::set<std::string> all_locales;
146 extension_l10n_util::GetAllLocales(&all_locales); 146 extension_l10n_util::GetAllLocales(&all_locales);
147 base::FilePath locale_path; 147 base::FilePath locale_path;
148 while (!(locale_path = locales.Next()).empty()) { 148 while (!(locale_path = locales.Next()).empty()) {
149 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path, 149 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path,
150 all_locales)) 150 all_locales))
151 continue; 151 continue;
152 152
153 base::FilePath messages_path = locale_path.Append(kMessagesFilename); 153 base::FilePath messages_path = locale_path.Append(kMessagesFilename);
154 154
155 if (!ReadMessageCatalog(messages_path)) 155 if (!ReadMessageCatalog(messages_path))
156 return false; 156 return false;
157 } 157 }
158 158
159 return true; 159 return true;
160 } 160 }
161 161
162 bool Unpacker::Run() { 162 bool Unpacker::Run() {
163 // Parse the manifest. 163 // Parse the manifest.
164 parsed_manifest_.reset(ReadManifest()); 164 parsed_manifest_ = ReadManifest();
165 if (!parsed_manifest_.get()) 165 if (!parsed_manifest_.get())
166 return false; // Error was already reported. 166 return false; // Error was already reported.
167 167
168 std::string error; 168 std::string error;
169 scoped_refptr<Extension> extension( 169 scoped_refptr<Extension> extension(
170 Extension::Create(extension_dir_, location_, *parsed_manifest_, 170 Extension::Create(extension_dir_, location_, *parsed_manifest_,
171 creation_flags_, extension_id_, &error)); 171 creation_flags_, extension_id_, &error));
172 if (!extension.get()) { 172 if (!extension.get()) {
173 SetError(error); 173 SetError(error);
174 return false; 174 return false;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return false; 246 return false;
247 } 247 }
248 248
249 internal_data_->decoded_images.push_back(base::MakeTuple(image_bitmap, path)); 249 internal_data_->decoded_images.push_back(base::MakeTuple(image_bitmap, path));
250 return true; 250 return true;
251 } 251 }
252 252
253 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { 253 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) {
254 std::string error; 254 std::string error;
255 JSONFileValueDeserializer deserializer(message_path); 255 JSONFileValueDeserializer deserializer(message_path);
256 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( 256 scoped_ptr<base::DictionaryValue> root = base::DictionaryValue::From(
257 deserializer.Deserialize(NULL, &error))); 257 make_scoped_ptr(deserializer.Deserialize(NULL, &error)));
258 if (!root.get()) { 258 if (!root.get()) {
259 base::string16 messages_file = message_path.LossyDisplayName(); 259 base::string16 messages_file = message_path.LossyDisplayName();
260 if (error.empty()) { 260 if (error.empty()) {
261 // If file is missing, Deserialize will fail with empty error. 261 // If file is missing, Deserialize will fail with empty error.
262 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, 262 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing,
263 base::UTF16ToUTF8(messages_file).c_str())); 263 base::UTF16ToUTF8(messages_file).c_str()));
264 } else { 264 } else {
265 SetError(base::StringPrintf( 265 SetError(base::StringPrintf(
266 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); 266 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str()));
267 } 267 }
(...skipping 19 matching lines...) Expand all
287 287
288 void Unpacker::SetError(const std::string& error) { 288 void Unpacker::SetError(const std::string& error) {
289 SetUTF16Error(base::UTF8ToUTF16(error)); 289 SetUTF16Error(base::UTF8ToUTF16(error));
290 } 290 }
291 291
292 void Unpacker::SetUTF16Error(const base::string16& error) { 292 void Unpacker::SetUTF16Error(const base::string16& error) {
293 error_message_ = error; 293 error_message_ = error;
294 } 294 }
295 295
296 } // namespace extensions 296 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/utility/unpacker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698