OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 return version_dir; | 120 return version_dir; |
121 } | 121 } |
122 | 122 |
123 void UninstallExtension(const base::FilePath& extensions_dir, | 123 void UninstallExtension(const base::FilePath& extensions_dir, |
124 const std::string& id) { | 124 const std::string& id) { |
125 // We don't care about the return value. If this fails (and it can, due to | 125 // We don't care about the return value. If this fails (and it can, due to |
126 // plugins that aren't unloaded yet), it will get cleaned up by | 126 // plugins that aren't unloaded yet), it will get cleaned up by |
127 // ExtensionService::GarbageCollectExtensions. | 127 // ExtensionService::GarbageCollectExtensions. |
128 file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive. | 128 base::Delete(extensions_dir.AppendASCII(id), true); // recursive. |
129 } | 129 } |
130 | 130 |
131 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, | 131 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, |
132 Manifest::Location location, | 132 Manifest::Location location, |
133 int flags, | 133 int flags, |
134 std::string* error) { | 134 std::string* error) { |
135 return LoadExtension(extension_path, std::string(), location, flags, error); | 135 return LoadExtension(extension_path, std::string(), location, flags, error); |
136 } | 136 } |
137 | 137 |
138 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, | 138 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 base::FileEnumerator::DIRECTORIES); | 338 base::FileEnumerator::DIRECTORIES); |
339 base::FilePath extension_path; | 339 base::FilePath extension_path; |
340 for (extension_path = enumerator.Next(); !extension_path.value().empty(); | 340 for (extension_path = enumerator.Next(); !extension_path.value().empty(); |
341 extension_path = enumerator.Next()) { | 341 extension_path = enumerator.Next()) { |
342 std::string extension_id; | 342 std::string extension_id; |
343 | 343 |
344 base::FilePath basename = extension_path.BaseName(); | 344 base::FilePath basename = extension_path.BaseName(); |
345 // Clean up temporary files left if Chrome crashed or quit in the middle | 345 // Clean up temporary files left if Chrome crashed or quit in the middle |
346 // of an extension install. | 346 // of an extension install. |
347 if (basename.value() == kTempDirectoryName) { | 347 if (basename.value() == kTempDirectoryName) { |
348 file_util::Delete(extension_path, true); // Recursive | 348 base::Delete(extension_path, true); // Recursive |
349 continue; | 349 continue; |
350 } | 350 } |
351 | 351 |
352 // Parse directory name as a potential extension ID. | 352 // Parse directory name as a potential extension ID. |
353 if (IsStringASCII(basename.value())) { | 353 if (IsStringASCII(basename.value())) { |
354 extension_id = UTF16ToASCII(basename.LossyDisplayName()); | 354 extension_id = UTF16ToASCII(basename.LossyDisplayName()); |
355 if (!Extension::IdIsValid(extension_id)) | 355 if (!Extension::IdIsValid(extension_id)) |
356 extension_id.clear(); | 356 extension_id.clear(); |
357 } | 357 } |
358 | 358 |
359 // Delete directories that aren't valid IDs. | 359 // Delete directories that aren't valid IDs. |
360 if (extension_id.empty()) { | 360 if (extension_id.empty()) { |
361 DLOG(WARNING) << "Invalid extension ID encountered in extensions " | 361 DLOG(WARNING) << "Invalid extension ID encountered in extensions " |
362 "directory: " << basename.value(); | 362 "directory: " << basename.value(); |
363 DVLOG(1) << "Deleting invalid extension directory " | 363 DVLOG(1) << "Deleting invalid extension directory " |
364 << extension_path.value() << "."; | 364 << extension_path.value() << "."; |
365 file_util::Delete(extension_path, true); // Recursive. | 365 base::Delete(extension_path, true); // Recursive. |
366 continue; | 366 continue; |
367 } | 367 } |
368 | 368 |
369 typedef std::multimap<std::string, base::FilePath>::const_iterator Iter; | 369 typedef std::multimap<std::string, base::FilePath>::const_iterator Iter; |
370 std::pair<Iter, Iter> iter_pair = extension_paths.equal_range(extension_id); | 370 std::pair<Iter, Iter> iter_pair = extension_paths.equal_range(extension_id); |
371 | 371 |
372 // If there is no entry in the prefs file, just delete the directory and | 372 // If there is no entry in the prefs file, just delete the directory and |
373 // move on. This can legitimately happen when an uninstall does not | 373 // move on. This can legitimately happen when an uninstall does not |
374 // complete, for example, when a plugin is in use at uninstall time. | 374 // complete, for example, when a plugin is in use at uninstall time. |
375 if (iter_pair.first == iter_pair.second) { | 375 if (iter_pair.first == iter_pair.second) { |
376 DVLOG(1) << "Deleting unreferenced install for directory " | 376 DVLOG(1) << "Deleting unreferenced install for directory " |
377 << extension_path.LossyDisplayName() << "."; | 377 << extension_path.LossyDisplayName() << "."; |
378 file_util::Delete(extension_path, true); // Recursive. | 378 base::Delete(extension_path, true); // Recursive. |
379 continue; | 379 continue; |
380 } | 380 } |
381 | 381 |
382 // Clean up old version directories. | 382 // Clean up old version directories. |
383 base::FileEnumerator versions_enumerator( | 383 base::FileEnumerator versions_enumerator( |
384 extension_path, | 384 extension_path, |
385 false, // Not recursive. | 385 false, // Not recursive. |
386 base::FileEnumerator::DIRECTORIES); | 386 base::FileEnumerator::DIRECTORIES); |
387 for (base::FilePath version_dir = versions_enumerator.Next(); | 387 for (base::FilePath version_dir = versions_enumerator.Next(); |
388 !version_dir.value().empty(); | 388 !version_dir.value().empty(); |
389 version_dir = versions_enumerator.Next()) { | 389 version_dir = versions_enumerator.Next()) { |
390 bool knownVersion = false; | 390 bool knownVersion = false; |
391 for (Iter it = iter_pair.first; it != iter_pair.second; ++it) | 391 for (Iter it = iter_pair.first; it != iter_pair.second; ++it) |
392 if (version_dir.BaseName() == it->second.BaseName()) { | 392 if (version_dir.BaseName() == it->second.BaseName()) { |
393 knownVersion = true; | 393 knownVersion = true; |
394 break; | 394 break; |
395 } | 395 } |
396 if (!knownVersion) { | 396 if (!knownVersion) { |
397 DVLOG(1) << "Deleting old version for directory " | 397 DVLOG(1) << "Deleting old version for directory " |
398 << version_dir.LossyDisplayName() << "."; | 398 << version_dir.LossyDisplayName() << "."; |
399 file_util::Delete(version_dir, true); // Recursive. | 399 base::Delete(version_dir, true); // Recursive. |
400 } | 400 } |
401 } | 401 } |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 extensions::MessageBundle* LoadMessageBundle( | 405 extensions::MessageBundle* LoadMessageBundle( |
406 const base::FilePath& extension_path, | 406 const base::FilePath& extension_path, |
407 const std::string& default_locale, | 407 const std::string& default_locale, |
408 std::string* error) { | 408 std::string* error) { |
409 error->clear(); | 409 error->clear(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 563 |
564 // Directory doesn't exist, so create it. | 564 // Directory doesn't exist, so create it. |
565 if (!file_util::CreateDirectory(temp_path)) { | 565 if (!file_util::CreateDirectory(temp_path)) { |
566 DLOG(WARNING) << "Couldn't create directory: " << temp_path.value(); | 566 DLOG(WARNING) << "Couldn't create directory: " << temp_path.value(); |
567 return base::FilePath(); | 567 return base::FilePath(); |
568 } | 568 } |
569 return temp_path; | 569 return temp_path; |
570 } | 570 } |
571 | 571 |
572 void DeleteFile(const base::FilePath& path, bool recursive) { | 572 void DeleteFile(const base::FilePath& path, bool recursive) { |
573 file_util::Delete(path, recursive); | 573 base::Delete(path, recursive); |
574 } | 574 } |
575 | 575 |
576 } // namespace extension_file_util | 576 } // namespace extension_file_util |
OLD | NEW |