| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" | 
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 283   return true; | 283   return true; | 
| 284 } | 284 } | 
| 285 | 285 | 
| 286 void GarbageCollectExtensions( | 286 void GarbageCollectExtensions( | 
| 287     const FilePath& install_directory, | 287     const FilePath& install_directory, | 
| 288     const std::map<std::string, FilePath>& extension_paths) { | 288     const std::map<std::string, FilePath>& extension_paths) { | 
| 289   // Nothing to clean up if it doesn't exist. | 289   // Nothing to clean up if it doesn't exist. | 
| 290   if (!file_util::DirectoryExists(install_directory)) | 290   if (!file_util::DirectoryExists(install_directory)) | 
| 291     return; | 291     return; | 
| 292 | 292 | 
| 293   LOG(INFO) << "Garbage collecting extensions..."; | 293   VLOG(1) << "Garbage collecting extensions..."; | 
| 294   file_util::FileEnumerator enumerator(install_directory, | 294   file_util::FileEnumerator enumerator(install_directory, | 
| 295                                        false,  // Not recursive. | 295                                        false,  // Not recursive. | 
| 296                                        file_util::FileEnumerator::DIRECTORIES); | 296                                        file_util::FileEnumerator::DIRECTORIES); | 
| 297   FilePath extension_path; | 297   FilePath extension_path; | 
| 298   for (extension_path = enumerator.Next(); !extension_path.value().empty(); | 298   for (extension_path = enumerator.Next(); !extension_path.value().empty(); | 
| 299        extension_path = enumerator.Next()) { | 299        extension_path = enumerator.Next()) { | 
| 300     std::string extension_id = WideToASCII( | 300     std::string extension_id = WideToASCII( | 
| 301         extension_path.BaseName().ToWStringHack()); | 301         extension_path.BaseName().ToWStringHack()); | 
| 302 | 302 | 
| 303     // Delete directories that aren't valid IDs. | 303     // Delete directories that aren't valid IDs. | 
| 304     if (!Extension::IdIsValid(extension_id)) { | 304     if (!Extension::IdIsValid(extension_id)) { | 
| 305       LOG(WARNING) << "Invalid extension ID encountered in extensions " | 305       LOG(WARNING) << "Invalid extension ID encountered in extensions " | 
| 306                       "directory: " << extension_id; | 306                       "directory: " << extension_id; | 
| 307       LOG(INFO) << "Deleting invalid extension directory " | 307       VLOG(1) << "Deleting invalid extension directory " | 
| 308                 << WideToASCII(extension_path.ToWStringHack()) << "."; | 308               << WideToASCII(extension_path.ToWStringHack()) << "."; | 
| 309       file_util::Delete(extension_path, true);  // Recursive. | 309       file_util::Delete(extension_path, true);  // Recursive. | 
| 310       continue; | 310       continue; | 
| 311     } | 311     } | 
| 312 | 312 | 
| 313     std::map<std::string, FilePath>::const_iterator iter = | 313     std::map<std::string, FilePath>::const_iterator iter = | 
| 314         extension_paths.find(extension_id); | 314         extension_paths.find(extension_id); | 
| 315 | 315 | 
| 316     // If there is no entry in the prefs file, just delete the directory and | 316     // If there is no entry in the prefs file, just delete the directory and | 
| 317     // move on. This can legitimately happen when an uninstall does not | 317     // move on. This can legitimately happen when an uninstall does not | 
| 318     // complete, for example, when a plugin is in use at uninstall time. | 318     // complete, for example, when a plugin is in use at uninstall time. | 
| 319     if (iter == extension_paths.end()) { | 319     if (iter == extension_paths.end()) { | 
| 320       LOG(INFO) << "Deleting unreferenced install for directory " | 320       VLOG(1) << "Deleting unreferenced install for directory " | 
| 321                 << WideToASCII(extension_path.ToWStringHack()) << "."; | 321               << WideToASCII(extension_path.ToWStringHack()) << "."; | 
| 322       file_util::Delete(extension_path, true);  // Recursive. | 322       file_util::Delete(extension_path, true);  // Recursive. | 
| 323       continue; | 323       continue; | 
| 324     } | 324     } | 
| 325 | 325 | 
| 326     // Clean up old version directories. | 326     // Clean up old version directories. | 
| 327     file_util::FileEnumerator versions_enumerator( | 327     file_util::FileEnumerator versions_enumerator( | 
| 328         extension_path, | 328         extension_path, | 
| 329         false,  // Not recursive. | 329         false,  // Not recursive. | 
| 330         file_util::FileEnumerator::DIRECTORIES); | 330         file_util::FileEnumerator::DIRECTORIES); | 
| 331     for (FilePath version_dir = versions_enumerator.Next(); | 331     for (FilePath version_dir = versions_enumerator.Next(); | 
| 332          !version_dir.value().empty(); | 332          !version_dir.value().empty(); | 
| 333          version_dir = versions_enumerator.Next()) { | 333          version_dir = versions_enumerator.Next()) { | 
| 334       if (version_dir.BaseName() != iter->second.BaseName()) { | 334       if (version_dir.BaseName() != iter->second.BaseName()) { | 
| 335         LOG(INFO) << "Deleting old version for directory " | 335         VLOG(1) << "Deleting old version for directory " | 
| 336                   << WideToASCII(version_dir.ToWStringHack()) << "."; | 336                 << WideToASCII(version_dir.ToWStringHack()) << "."; | 
| 337         file_util::Delete(version_dir, true);  // Recursive. | 337         file_util::Delete(version_dir, true);  // Recursive. | 
| 338       } | 338       } | 
| 339     } | 339     } | 
| 340   } | 340   } | 
| 341 } | 341 } | 
| 342 | 342 | 
| 343 ExtensionMessageBundle* LoadExtensionMessageBundle( | 343 ExtensionMessageBundle* LoadExtensionMessageBundle( | 
| 344     const FilePath& extension_path, | 344     const FilePath& extension_path, | 
| 345     const std::string& default_locale, | 345     const std::string& default_locale, | 
| 346     std::string* error) { | 346     std::string* error) { | 
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 516   // It's still possible for someone to construct an annoying URL whose path | 516   // It's still possible for someone to construct an annoying URL whose path | 
| 517   // would still wind up not being considered relative at this point. | 517   // would still wind up not being considered relative at this point. | 
| 518   // For example: chrome-extension://id/c:////foo.html | 518   // For example: chrome-extension://id/c:////foo.html | 
| 519   if (path.IsAbsolute()) | 519   if (path.IsAbsolute()) | 
| 520     return FilePath(); | 520     return FilePath(); | 
| 521 | 521 | 
| 522   return path; | 522   return path; | 
| 523 } | 523 } | 
| 524 | 524 | 
| 525 }  // namespace extension_file_util | 525 }  // namespace extension_file_util | 
| OLD | NEW | 
|---|