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 | |
485 ExtensionMessageBundle* LoadExtensionMessageBundle( | 422 ExtensionMessageBundle* LoadExtensionMessageBundle( |
486 const FilePath& extension_path, | 423 const FilePath& extension_path, |
487 const std::string& default_locale, | 424 const std::string& default_locale, |
488 std::string* error) { | 425 std::string* error) { |
489 error->clear(); | 426 error->clear(); |
490 // Load locale information if available. | 427 // Load locale information if available. |
491 FilePath locale_path = extension_path.Append( | 428 FilePath locale_path = extension_path.Append( |
492 Extension::kLocaleFolder); | 429 Extension::kLocaleFolder); |
493 if (!file_util::PathExists(locale_path)) | 430 if (!file_util::PathExists(locale_path)) |
494 return NULL; | 431 return NULL; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 return temp_path; | 709 return temp_path; |
773 | 710 |
774 return FilePath(); | 711 return FilePath(); |
775 } | 712 } |
776 | 713 |
777 void DeleteFile(const FilePath& path, bool recursive) { | 714 void DeleteFile(const FilePath& path, bool recursive) { |
778 file_util::Delete(path, recursive); | 715 file_util::Delete(path, recursive); |
779 } | 716 } |
780 | 717 |
781 } // namespace extension_file_util | 718 } // namespace extension_file_util |
OLD | NEW |