Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 9817018: Cleaning Up Extensions When Local Content Removed (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated with newest master Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 // Check children of extension root to see if any of them start with _ and is 360 // Check children of extension root to see if any of them start with _ and is
361 // not on the reserved list. 361 // not on the reserved list.
362 if (!CheckForIllegalFilenames(extension->path(), error)) { 362 if (!CheckForIllegalFilenames(extension->path(), error)) {
363 return false; 363 return false;
364 } 364 }
365 365
366 return true; 366 return true;
367 } 367 }
368 368
369 void GarbageCollectExtensions(
370 const FilePath& install_directory,
371 const std::map<std::string, FilePath>& extension_paths) {
372 // Nothing to clean up if it doesn't exist.
373 if (!file_util::DirectoryExists(install_directory))
374 return;
375
376 DVLOG(1) << "Garbage collecting extensions...";
377 file_util::FileEnumerator enumerator(install_directory,
378 false, // Not recursive.
379 file_util::FileEnumerator::DIRECTORIES);
380 FilePath extension_path;
381 for (extension_path = enumerator.Next(); !extension_path.value().empty();
382 extension_path = enumerator.Next()) {
383 std::string extension_id;
384
385 FilePath basename = extension_path.BaseName();
386 if (IsStringASCII(basename.value())) {
387 extension_id = UTF16ToASCII(basename.LossyDisplayName());
388 if (!Extension::IdIsValid(extension_id))
389 extension_id.clear();
390 }
391
392 // Delete directories that aren't valid IDs.
393 if (extension_id.empty()) {
394 DLOG(WARNING) << "Invalid extension ID encountered in extensions "
395 "directory: " << basename.value();
396 DVLOG(1) << "Deleting invalid extension directory "
397 << extension_path.value() << ".";
398 file_util::Delete(extension_path, true); // Recursive.
399 continue;
400 }
401
402 std::map<std::string, FilePath>::const_iterator iter =
403 extension_paths.find(extension_id);
404
405 // If there is no entry in the prefs file, just delete the directory and
406 // move on. This can legitimately happen when an uninstall does not
407 // complete, for example, when a plugin is in use at uninstall time.
408 if (iter == extension_paths.end()) {
409 DVLOG(1) << "Deleting unreferenced install for directory "
410 << extension_path.LossyDisplayName() << ".";
411 file_util::Delete(extension_path, true); // Recursive.
412 continue;
413 }
414
415 // Clean up old version directories.
416 file_util::FileEnumerator versions_enumerator(
417 extension_path,
418 false, // Not recursive.
419 file_util::FileEnumerator::DIRECTORIES);
420 for (FilePath version_dir = versions_enumerator.Next();
421 !version_dir.value().empty();
422 version_dir = versions_enumerator.Next()) {
423 if (version_dir.BaseName() != iter->second.BaseName()) {
424 DVLOG(1) << "Deleting old version for directory "
425 << version_dir.LossyDisplayName() << ".";
426 file_util::Delete(version_dir, true); // Recursive.
427 }
428 }
429 }
430 }
431
432 ExtensionMessageBundle* LoadExtensionMessageBundle( 369 ExtensionMessageBundle* LoadExtensionMessageBundle(
433 const FilePath& extension_path, 370 const FilePath& extension_path,
434 const std::string& default_locale, 371 const std::string& default_locale,
435 std::string* error) { 372 std::string* error) {
436 error->clear(); 373 error->clear();
437 // Load locale information if available. 374 // Load locale information if available.
438 FilePath locale_path = extension_path.Append(Extension::kLocaleFolder); 375 FilePath locale_path = extension_path.Append(Extension::kLocaleFolder);
439 if (!file_util::PathExists(locale_path)) 376 if (!file_util::PathExists(locale_path))
440 return NULL; 377 return NULL;
441 378
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 return temp_path; 634 return temp_path;
698 635
699 return FilePath(); 636 return FilePath();
700 } 637 }
701 638
702 void DeleteFile(const FilePath& path, bool recursive) { 639 void DeleteFile(const FilePath& path, bool recursive) {
703 file_util::Delete(path, recursive); 640 file_util::Delete(path, recursive);
704 } 641 }
705 642
706 } // namespace extension_file_util 643 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | chrome/common/extensions/extension_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698