| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 for (int i = 0; i < kMaxAttempts; ++i) { | 63 for (int i = 0; i < kMaxAttempts; ++i) { |
| 64 FilePath candidate = extension_dir.AppendASCII( | 64 FilePath candidate = extension_dir.AppendASCII( |
| 65 base::StringPrintf("%s_%u", version.c_str(), i)); | 65 base::StringPrintf("%s_%u", version.c_str(), i)); |
| 66 if (!file_util::PathExists(candidate)) { | 66 if (!file_util::PathExists(candidate)) { |
| 67 version_dir = candidate; | 67 version_dir = candidate; |
| 68 break; | 68 break; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (version_dir.empty()) { | 72 if (version_dir.empty()) { |
| 73 LOG(ERROR) << "Could not find a home for extension " << id << " with " | 73 DLOG(ERROR) << "Could not find a home for extension " << id << " with " |
| 74 << "version " << version << "."; | 74 << "version " << version << "."; |
| 75 return FilePath(); | 75 return FilePath(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!file_util::Move(unpacked_source_dir, version_dir)) | 78 if (!file_util::Move(unpacked_source_dir, version_dir)) |
| 79 return FilePath(); | 79 return FilePath(); |
| 80 | 80 |
| 81 return version_dir; | 81 return version_dir; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void UninstallExtension(const FilePath& extensions_dir, | 84 void UninstallExtension(const FilePath& extensions_dir, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return true; | 307 return true; |
| 308 } | 308 } |
| 309 | 309 |
| 310 void GarbageCollectExtensions( | 310 void GarbageCollectExtensions( |
| 311 const FilePath& install_directory, | 311 const FilePath& install_directory, |
| 312 const std::map<std::string, FilePath>& extension_paths) { | 312 const std::map<std::string, FilePath>& extension_paths) { |
| 313 // Nothing to clean up if it doesn't exist. | 313 // Nothing to clean up if it doesn't exist. |
| 314 if (!file_util::DirectoryExists(install_directory)) | 314 if (!file_util::DirectoryExists(install_directory)) |
| 315 return; | 315 return; |
| 316 | 316 |
| 317 VLOG(1) << "Garbage collecting extensions..."; | 317 DVLOG(1) << "Garbage collecting extensions..."; |
| 318 file_util::FileEnumerator enumerator(install_directory, | 318 file_util::FileEnumerator enumerator(install_directory, |
| 319 false, // Not recursive. | 319 false, // Not recursive. |
| 320 file_util::FileEnumerator::DIRECTORIES); | 320 file_util::FileEnumerator::DIRECTORIES); |
| 321 FilePath extension_path; | 321 FilePath extension_path; |
| 322 for (extension_path = enumerator.Next(); !extension_path.value().empty(); | 322 for (extension_path = enumerator.Next(); !extension_path.value().empty(); |
| 323 extension_path = enumerator.Next()) { | 323 extension_path = enumerator.Next()) { |
| 324 std::string extension_id; | 324 std::string extension_id; |
| 325 | 325 |
| 326 FilePath basename = extension_path.BaseName(); | 326 FilePath basename = extension_path.BaseName(); |
| 327 if (IsStringASCII(basename.value())) { | 327 if (IsStringASCII(basename.value())) { |
| 328 extension_id = UTF16ToASCII(basename.LossyDisplayName()); | 328 extension_id = UTF16ToASCII(basename.LossyDisplayName()); |
| 329 if (!Extension::IdIsValid(extension_id)) | 329 if (!Extension::IdIsValid(extension_id)) |
| 330 extension_id.clear(); | 330 extension_id.clear(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Delete directories that aren't valid IDs. | 333 // Delete directories that aren't valid IDs. |
| 334 if (extension_id.empty()) { | 334 if (extension_id.empty()) { |
| 335 LOG(WARNING) << "Invalid extension ID encountered in extensions " | 335 DLOG(WARNING) << "Invalid extension ID encountered in extensions " |
| 336 "directory: " << basename.value(); | 336 "directory: " << basename.value(); |
| 337 VLOG(1) << "Deleting invalid extension directory " | 337 DVLOG(1) << "Deleting invalid extension directory " |
| 338 << extension_path.value() << "."; | 338 << extension_path.value() << "."; |
| 339 file_util::Delete(extension_path, true); // Recursive. | 339 file_util::Delete(extension_path, true); // Recursive. |
| 340 continue; | 340 continue; |
| 341 } | 341 } |
| 342 | 342 |
| 343 std::map<std::string, FilePath>::const_iterator iter = | 343 std::map<std::string, FilePath>::const_iterator iter = |
| 344 extension_paths.find(extension_id); | 344 extension_paths.find(extension_id); |
| 345 | 345 |
| 346 // If there is no entry in the prefs file, just delete the directory and | 346 // If there is no entry in the prefs file, just delete the directory and |
| 347 // move on. This can legitimately happen when an uninstall does not | 347 // move on. This can legitimately happen when an uninstall does not |
| 348 // complete, for example, when a plugin is in use at uninstall time. | 348 // complete, for example, when a plugin is in use at uninstall time. |
| 349 if (iter == extension_paths.end()) { | 349 if (iter == extension_paths.end()) { |
| 350 VLOG(1) << "Deleting unreferenced install for directory " | 350 DVLOG(1) << "Deleting unreferenced install for directory " |
| 351 << extension_path.LossyDisplayName() << "."; | 351 << extension_path.LossyDisplayName() << "."; |
| 352 file_util::Delete(extension_path, true); // Recursive. | 352 file_util::Delete(extension_path, true); // Recursive. |
| 353 continue; | 353 continue; |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Clean up old version directories. | 356 // Clean up old version directories. |
| 357 file_util::FileEnumerator versions_enumerator( | 357 file_util::FileEnumerator versions_enumerator( |
| 358 extension_path, | 358 extension_path, |
| 359 false, // Not recursive. | 359 false, // Not recursive. |
| 360 file_util::FileEnumerator::DIRECTORIES); | 360 file_util::FileEnumerator::DIRECTORIES); |
| 361 for (FilePath version_dir = versions_enumerator.Next(); | 361 for (FilePath version_dir = versions_enumerator.Next(); |
| 362 !version_dir.value().empty(); | 362 !version_dir.value().empty(); |
| 363 version_dir = versions_enumerator.Next()) { | 363 version_dir = versions_enumerator.Next()) { |
| 364 if (version_dir.BaseName() != iter->second.BaseName()) { | 364 if (version_dir.BaseName() != iter->second.BaseName()) { |
| 365 VLOG(1) << "Deleting old version for directory " | 365 DVLOG(1) << "Deleting old version for directory " |
| 366 << version_dir.LossyDisplayName() << "."; | 366 << version_dir.LossyDisplayName() << "."; |
| 367 file_util::Delete(version_dir, true); // Recursive. | 367 file_util::Delete(version_dir, true); // Recursive. |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 ExtensionMessageBundle* LoadExtensionMessageBundle( | 373 ExtensionMessageBundle* LoadExtensionMessageBundle( |
| 374 const FilePath& extension_path, | 374 const FilePath& extension_path, |
| 375 const std::string& default_locale, | 375 const std::string& default_locale, |
| 376 std::string* error) { | 376 std::string* error) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 return temp_path; | 639 return temp_path; |
| 640 | 640 |
| 641 return FilePath(); | 641 return FilePath(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void DeleteFile(const FilePath& path, bool recursive) { | 644 void DeleteFile(const FilePath& path, bool recursive) { |
| 645 file_util::Delete(path, recursive); | 645 file_util::Delete(path, recursive); |
| 646 } | 646 } |
| 647 | 647 |
| 648 } // namespace extension_file_util | 648 } // namespace extension_file_util |
| OLD | NEW |