OLD | NEW |
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 Unpacker::~Unpacker() { | 111 Unpacker::~Unpacker() { |
112 } | 112 } |
113 | 113 |
114 base::DictionaryValue* Unpacker::ReadManifest() { | 114 base::DictionaryValue* Unpacker::ReadManifest() { |
115 base::FilePath manifest_path = temp_install_dir_.Append(kManifestFilename); | 115 base::FilePath manifest_path = temp_install_dir_.Append(kManifestFilename); |
116 if (!base::PathExists(manifest_path)) { | 116 if (!base::PathExists(manifest_path)) { |
117 SetError(errors::kInvalidManifest); | 117 SetError(errors::kInvalidManifest); |
118 return NULL; | 118 return NULL; |
119 } | 119 } |
120 | 120 |
121 JSONFileValueSerializer serializer(manifest_path); | 121 JSONFileValueDeserializer deserializer(manifest_path); |
122 std::string error; | 122 std::string error; |
123 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 123 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error)); |
124 if (!root.get()) { | 124 if (!root.get()) { |
125 SetError(error); | 125 SetError(error); |
126 return NULL; | 126 return NULL; |
127 } | 127 } |
128 | 128 |
129 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | 129 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { |
130 SetError(errors::kInvalidManifest); | 130 SetError(errors::kInvalidManifest); |
131 return NULL; | 131 return NULL; |
132 } | 132 } |
133 | 133 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 path.BaseName().LossyDisplayName()))); | 263 path.BaseName().LossyDisplayName()))); |
264 return false; | 264 return false; |
265 } | 265 } |
266 | 266 |
267 internal_data_->decoded_images.push_back(MakeTuple(image_bitmap, path)); | 267 internal_data_->decoded_images.push_back(MakeTuple(image_bitmap, path)); |
268 return true; | 268 return true; |
269 } | 269 } |
270 | 270 |
271 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { | 271 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { |
272 std::string error; | 272 std::string error; |
273 JSONFileValueSerializer serializer(message_path); | 273 JSONFileValueDeserializer deserializer(message_path); |
274 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( | 274 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( |
275 serializer.Deserialize(NULL, &error))); | 275 deserializer.Deserialize(NULL, &error))); |
276 if (!root.get()) { | 276 if (!root.get()) { |
277 base::string16 messages_file = message_path.LossyDisplayName(); | 277 base::string16 messages_file = message_path.LossyDisplayName(); |
278 if (error.empty()) { | 278 if (error.empty()) { |
279 // If file is missing, Deserialize will fail with empty error. | 279 // If file is missing, Deserialize will fail with empty error. |
280 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, | 280 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, |
281 base::UTF16ToUTF8(messages_file).c_str())); | 281 base::UTF16ToUTF8(messages_file).c_str())); |
282 } else { | 282 } else { |
283 SetError(base::StringPrintf( | 283 SetError(base::StringPrintf( |
284 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); | 284 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); |
285 } | 285 } |
(...skipping 19 matching lines...) Expand all Loading... |
305 | 305 |
306 void Unpacker::SetError(const std::string& error) { | 306 void Unpacker::SetError(const std::string& error) { |
307 SetUTF16Error(base::UTF8ToUTF16(error)); | 307 SetUTF16Error(base::UTF8ToUTF16(error)); |
308 } | 308 } |
309 | 309 |
310 void Unpacker::SetUTF16Error(const base::string16& error) { | 310 void Unpacker::SetUTF16Error(const base::string16& error) { |
311 error_message_ = error; | 311 error_message_ = error; |
312 } | 312 } |
313 | 313 |
314 } // namespace extensions | 314 } // namespace extensions |
OLD | NEW |