| 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 "chrome/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 Extension::InstallWarning::FORMAT_TEXT, | 412 Extension::InstallWarning::FORMAT_TEXT, |
| 413 l10n_util::GetStringFUTF8( | 413 l10n_util::GetStringFUTF8( |
| 414 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, | 414 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, |
| 415 private_keys[i].LossyDisplayName()))); | 415 private_keys[i].LossyDisplayName()))); |
| 416 } | 416 } |
| 417 // Only warn; don't block loading the extension. | 417 // Only warn; don't block loading the extension. |
| 418 } | 418 } |
| 419 return true; | 419 return true; |
| 420 } | 420 } |
| 421 | 421 |
| 422 void GarbageCollectExtensions( |
| 423 const FilePath& install_directory, |
| 424 const std::map<std::string, FilePath>& extension_paths) { |
| 425 // Nothing to clean up if it doesn't exist. |
| 426 if (!file_util::DirectoryExists(install_directory)) |
| 427 return; |
| 428 |
| 429 DVLOG(1) << "Garbage collecting extensions..."; |
| 430 file_util::FileEnumerator enumerator(install_directory, |
| 431 false, // Not recursive. |
| 432 file_util::FileEnumerator::DIRECTORIES); |
| 433 FilePath extension_path; |
| 434 for (extension_path = enumerator.Next(); !extension_path.value().empty(); |
| 435 extension_path = enumerator.Next()) { |
| 436 std::string extension_id; |
| 437 |
| 438 FilePath basename = extension_path.BaseName(); |
| 439 if (IsStringASCII(basename.value())) { |
| 440 extension_id = UTF16ToASCII(basename.LossyDisplayName()); |
| 441 if (!Extension::IdIsValid(extension_id)) |
| 442 extension_id.clear(); |
| 443 } |
| 444 |
| 445 // Delete directories that aren't valid IDs. |
| 446 if (extension_id.empty()) { |
| 447 DLOG(WARNING) << "Invalid extension ID encountered in extensions " |
| 448 "directory: " << basename.value(); |
| 449 DVLOG(1) << "Deleting invalid extension directory " |
| 450 << extension_path.value() << "."; |
| 451 file_util::Delete(extension_path, true); // Recursive. |
| 452 continue; |
| 453 } |
| 454 |
| 455 std::map<std::string, FilePath>::const_iterator iter = |
| 456 extension_paths.find(extension_id); |
| 457 |
| 458 // If there is no entry in the prefs file, just delete the directory and |
| 459 // move on. This can legitimately happen when an uninstall does not |
| 460 // complete, for example, when a plugin is in use at uninstall time. |
| 461 if (iter == extension_paths.end()) { |
| 462 DVLOG(1) << "Deleting unreferenced install for directory " |
| 463 << extension_path.LossyDisplayName() << "."; |
| 464 file_util::Delete(extension_path, true); // Recursive. |
| 465 continue; |
| 466 } |
| 467 |
| 468 // Clean up old version directories. |
| 469 file_util::FileEnumerator versions_enumerator( |
| 470 extension_path, |
| 471 false, // Not recursive. |
| 472 file_util::FileEnumerator::DIRECTORIES); |
| 473 for (FilePath version_dir = versions_enumerator.Next(); |
| 474 !version_dir.value().empty(); |
| 475 version_dir = versions_enumerator.Next()) { |
| 476 if (version_dir.BaseName() != iter->second.BaseName()) { |
| 477 DVLOG(1) << "Deleting old version for directory " |
| 478 << version_dir.LossyDisplayName() << "."; |
| 479 file_util::Delete(version_dir, true); // Recursive. |
| 480 } |
| 481 } |
| 482 } |
| 483 } |
| 484 |
| 422 ExtensionMessageBundle* LoadExtensionMessageBundle( | 485 ExtensionMessageBundle* LoadExtensionMessageBundle( |
| 423 const FilePath& extension_path, | 486 const FilePath& extension_path, |
| 424 const std::string& default_locale, | 487 const std::string& default_locale, |
| 425 std::string* error) { | 488 std::string* error) { |
| 426 error->clear(); | 489 error->clear(); |
| 427 // Load locale information if available. | 490 // Load locale information if available. |
| 428 FilePath locale_path = extension_path.Append( | 491 FilePath locale_path = extension_path.Append( |
| 429 Extension::kLocaleFolder); | 492 Extension::kLocaleFolder); |
| 430 if (!file_util::PathExists(locale_path)) | 493 if (!file_util::PathExists(locale_path)) |
| 431 return NULL; | 494 return NULL; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 return temp_path; | 772 return temp_path; |
| 710 | 773 |
| 711 return FilePath(); | 774 return FilePath(); |
| 712 } | 775 } |
| 713 | 776 |
| 714 void DeleteFile(const FilePath& path, bool recursive) { | 777 void DeleteFile(const FilePath& path, bool recursive) { |
| 715 file_util::Delete(path, recursive); | 778 file_util::Delete(path, recursive); |
| 716 } | 779 } |
| 717 | 780 |
| 718 } // namespace extension_file_util | 781 } // namespace extension_file_util |
| OLD | NEW |