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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 // Check children of extension root to see if any of them start with _ and is | 350 // Check children of extension root to see if any of them start with _ and is |
351 // not on the reserved list. | 351 // not on the reserved list. |
352 if (!CheckForIllegalFilenames(extension->path(), error)) { | 352 if (!CheckForIllegalFilenames(extension->path(), error)) { |
353 return false; | 353 return false; |
354 } | 354 } |
355 | 355 |
356 return true; | 356 return true; |
357 } | 357 } |
358 | 358 |
359 void GarbageCollectExtensions( | |
360 const FilePath& install_directory, | |
361 const std::map<std::string, FilePath>& extension_paths) { | |
362 // Nothing to clean up if it doesn't exist. | |
363 if (!file_util::DirectoryExists(install_directory)) | |
364 return; | |
365 | |
366 DVLOG(1) << "Garbage collecting extensions..."; | |
367 file_util::FileEnumerator enumerator(install_directory, | |
368 false, // Not recursive. | |
369 file_util::FileEnumerator::DIRECTORIES); | |
370 FilePath extension_path; | |
371 for (extension_path = enumerator.Next(); !extension_path.value().empty(); | |
372 extension_path = enumerator.Next()) { | |
373 std::string extension_id; | |
374 | |
375 FilePath basename = extension_path.BaseName(); | |
376 if (IsStringASCII(basename.value())) { | |
377 extension_id = UTF16ToASCII(basename.LossyDisplayName()); | |
378 if (!Extension::IdIsValid(extension_id)) | |
379 extension_id.clear(); | |
380 } | |
381 | |
382 // Delete directories that aren't valid IDs. | |
383 if (extension_id.empty()) { | |
384 DLOG(WARNING) << "Invalid extension ID encountered in extensions " | |
385 "directory: " << basename.value(); | |
386 DVLOG(1) << "Deleting invalid extension directory " | |
387 << extension_path.value() << "."; | |
388 file_util::Delete(extension_path, true); // Recursive. | |
389 continue; | |
390 } | |
391 | |
392 std::map<std::string, FilePath>::const_iterator iter = | |
393 extension_paths.find(extension_id); | |
394 | |
395 // If there is no entry in the prefs file, just delete the directory and | |
396 // move on. This can legitimately happen when an uninstall does not | |
397 // complete, for example, when a plugin is in use at uninstall time. | |
398 if (iter == extension_paths.end()) { | |
399 DVLOG(1) << "Deleting unreferenced install for directory " | |
400 << extension_path.LossyDisplayName() << "."; | |
401 file_util::Delete(extension_path, true); // Recursive. | |
402 continue; | |
403 } | |
404 | |
405 // Clean up old version directories. | |
406 file_util::FileEnumerator versions_enumerator( | |
407 extension_path, | |
408 false, // Not recursive. | |
409 file_util::FileEnumerator::DIRECTORIES); | |
410 for (FilePath version_dir = versions_enumerator.Next(); | |
411 !version_dir.value().empty(); | |
412 version_dir = versions_enumerator.Next()) { | |
413 if (version_dir.BaseName() != iter->second.BaseName()) { | |
414 DVLOG(1) << "Deleting old version for directory " | |
415 << version_dir.LossyDisplayName() << "."; | |
416 file_util::Delete(version_dir, true); // Recursive. | |
417 } | |
418 } | |
419 } | |
420 } | |
421 | |
422 ExtensionMessageBundle* LoadExtensionMessageBundle( | 359 ExtensionMessageBundle* LoadExtensionMessageBundle( |
423 const FilePath& extension_path, | 360 const FilePath& extension_path, |
424 const std::string& default_locale, | 361 const std::string& default_locale, |
425 std::string* error) { | 362 std::string* error) { |
426 error->clear(); | 363 error->clear(); |
427 // Load locale information if available. | 364 // Load locale information if available. |
428 FilePath locale_path = extension_path.Append(Extension::kLocaleFolder); | 365 FilePath locale_path = extension_path.Append(Extension::kLocaleFolder); |
429 if (!file_util::PathExists(locale_path)) | 366 if (!file_util::PathExists(locale_path)) |
430 return NULL; | 367 return NULL; |
431 | 368 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 return temp_path; | 624 return temp_path; |
688 | 625 |
689 return FilePath(); | 626 return FilePath(); |
690 } | 627 } |
691 | 628 |
692 void DeleteFile(const FilePath& path, bool recursive) { | 629 void DeleteFile(const FilePath& path, bool recursive) { |
693 file_util::Delete(path, recursive); | 630 file_util::Delete(path, recursive); |
694 } | 631 } |
695 | 632 |
696 } // namespace extension_file_util | 633 } // namespace extension_file_util |
OLD | NEW |