| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 for (size_t i = 0; i < private_keys.size(); ++i) { | 420 for (size_t i = 0; i < private_keys.size(); ++i) { |
| 421 warnings->push_back(l10n_util::GetStringFUTF8( | 421 warnings->push_back(l10n_util::GetStringFUTF8( |
| 422 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, | 422 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, |
| 423 private_keys[i].LossyDisplayName())); | 423 private_keys[i].LossyDisplayName())); |
| 424 } | 424 } |
| 425 // Only warn; don't block loading the extension. | 425 // Only warn; don't block loading the extension. |
| 426 } | 426 } |
| 427 return true; | 427 return true; |
| 428 } | 428 } |
| 429 | 429 |
| 430 void GarbageCollectExtensions( | |
| 431 const FilePath& install_directory, | |
| 432 const std::map<std::string, FilePath>& extension_paths) { | |
| 433 // Nothing to clean up if it doesn't exist. | |
| 434 if (!file_util::DirectoryExists(install_directory)) | |
| 435 return; | |
| 436 | |
| 437 DVLOG(1) << "Garbage collecting extensions..."; | |
| 438 file_util::FileEnumerator enumerator(install_directory, | |
| 439 false, // Not recursive. | |
| 440 file_util::FileEnumerator::DIRECTORIES); | |
| 441 FilePath extension_path; | |
| 442 for (extension_path = enumerator.Next(); !extension_path.value().empty(); | |
| 443 extension_path = enumerator.Next()) { | |
| 444 std::string extension_id; | |
| 445 | |
| 446 FilePath basename = extension_path.BaseName(); | |
| 447 if (IsStringASCII(basename.value())) { | |
| 448 extension_id = UTF16ToASCII(basename.LossyDisplayName()); | |
| 449 if (!Extension::IdIsValid(extension_id)) | |
| 450 extension_id.clear(); | |
| 451 } | |
| 452 | |
| 453 // Delete directories that aren't valid IDs. | |
| 454 if (extension_id.empty()) { | |
| 455 DLOG(WARNING) << "Invalid extension ID encountered in extensions " | |
| 456 "directory: " << basename.value(); | |
| 457 DVLOG(1) << "Deleting invalid extension directory " | |
| 458 << extension_path.value() << "."; | |
| 459 file_util::Delete(extension_path, true); // Recursive. | |
| 460 continue; | |
| 461 } | |
| 462 | |
| 463 std::map<std::string, FilePath>::const_iterator iter = | |
| 464 extension_paths.find(extension_id); | |
| 465 | |
| 466 // If there is no entry in the prefs file, just delete the directory and | |
| 467 // move on. This can legitimately happen when an uninstall does not | |
| 468 // complete, for example, when a plugin is in use at uninstall time. | |
| 469 if (iter == extension_paths.end()) { | |
| 470 DVLOG(1) << "Deleting unreferenced install for directory " | |
| 471 << extension_path.LossyDisplayName() << "."; | |
| 472 file_util::Delete(extension_path, true); // Recursive. | |
| 473 continue; | |
| 474 } | |
| 475 | |
| 476 // Clean up old version directories. | |
| 477 file_util::FileEnumerator versions_enumerator( | |
| 478 extension_path, | |
| 479 false, // Not recursive. | |
| 480 file_util::FileEnumerator::DIRECTORIES); | |
| 481 for (FilePath version_dir = versions_enumerator.Next(); | |
| 482 !version_dir.value().empty(); | |
| 483 version_dir = versions_enumerator.Next()) { | |
| 484 if (version_dir.BaseName() != iter->second.BaseName()) { | |
| 485 DVLOG(1) << "Deleting old version for directory " | |
| 486 << version_dir.LossyDisplayName() << "."; | |
| 487 file_util::Delete(version_dir, true); // Recursive. | |
| 488 } | |
| 489 } | |
| 490 } | |
| 491 } | |
| 492 | |
| 493 ExtensionMessageBundle* LoadExtensionMessageBundle( | 430 ExtensionMessageBundle* LoadExtensionMessageBundle( |
| 494 const FilePath& extension_path, | 431 const FilePath& extension_path, |
| 495 const std::string& default_locale, | 432 const std::string& default_locale, |
| 496 std::string* error) { | 433 std::string* error) { |
| 497 error->clear(); | 434 error->clear(); |
| 498 // Load locale information if available. | 435 // Load locale information if available. |
| 499 FilePath locale_path = extension_path.Append( | 436 FilePath locale_path = extension_path.Append( |
| 500 Extension::kLocaleFolder); | 437 Extension::kLocaleFolder); |
| 501 if (!file_util::PathExists(locale_path)) | 438 if (!file_util::PathExists(locale_path)) |
| 502 return NULL; | 439 return NULL; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 return temp_path; | 717 return temp_path; |
| 781 | 718 |
| 782 return FilePath(); | 719 return FilePath(); |
| 783 } | 720 } |
| 784 | 721 |
| 785 void DeleteFile(const FilePath& path, bool recursive) { | 722 void DeleteFile(const FilePath& path, bool recursive) { |
| 786 file_util::Delete(path, recursive); | 723 file_util::Delete(path, recursive); |
| 787 } | 724 } |
| 788 | 725 |
| 789 } // namespace extension_file_util | 726 } // namespace extension_file_util |
| OLD | NEW |