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/installer/util/installer_state.h" | 5 #include "chrome/installer/util/installer_state.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 target_path().AppendASCII(current_version->GetString()) | 592 target_path().AppendASCII(current_version->GetString()) |
593 .Append(kChromeFrameDll)); | 593 .Append(kChromeFrameDll)); |
594 in_use = file_util::PathExists(cf_install_path) && | 594 in_use = file_util::PathExists(cf_install_path) && |
595 IsFileInUse(cf_install_path); | 595 IsFileInUse(cf_install_path); |
596 } | 596 } |
597 return in_use; | 597 return in_use; |
598 } | 598 } |
599 | 599 |
600 base::FilePath InstallerState::GetInstallerDirectory( | 600 base::FilePath InstallerState::GetInstallerDirectory( |
601 const Version& version) const { | 601 const Version& version) const { |
602 return target_path().Append(ASCIIToWide(version.GetString())) | 602 return target_path().Append(base::ASCIIToWide(version.GetString())) |
603 .Append(kInstallerDir); | 603 .Append(kInstallerDir); |
604 } | 604 } |
605 | 605 |
606 // static | 606 // static |
607 bool InstallerState::IsFileInUse(const base::FilePath& file) { | 607 bool InstallerState::IsFileInUse(const base::FilePath& file) { |
608 // Call CreateFile with a share mode of 0 which should cause this to fail | 608 // Call CreateFile with a share mode of 0 which should cause this to fail |
609 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. | 609 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. |
610 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), | 610 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), |
611 GENERIC_WRITE, 0, NULL, | 611 GENERIC_WRITE, 0, NULL, |
612 OPEN_EXISTING, 0, 0)).IsValid(); | 612 OPEN_EXISTING, 0, 0)).IsValid(); |
613 } | 613 } |
614 | 614 |
615 void InstallerState::GetExistingExeVersions( | 615 void InstallerState::GetExistingExeVersions( |
616 std::set<std::string>* existing_versions) const { | 616 std::set<std::string>* existing_versions) const { |
617 | 617 |
618 static const wchar_t* const kChromeFilenames[] = { | 618 static const wchar_t* const kChromeFilenames[] = { |
619 installer::kChromeExe, | 619 installer::kChromeExe, |
620 installer::kChromeNewExe, | 620 installer::kChromeNewExe, |
621 installer::kChromeOldExe, | 621 installer::kChromeOldExe, |
622 }; | 622 }; |
623 | 623 |
624 for (int i = 0; i < arraysize(kChromeFilenames); ++i) { | 624 for (int i = 0; i < arraysize(kChromeFilenames); ++i) { |
625 base::FilePath chrome_exe(target_path().Append(kChromeFilenames[i])); | 625 base::FilePath chrome_exe(target_path().Append(kChromeFilenames[i])); |
626 scoped_ptr<FileVersionInfo> file_version_info( | 626 scoped_ptr<FileVersionInfo> file_version_info( |
627 FileVersionInfo::CreateFileVersionInfo(chrome_exe)); | 627 FileVersionInfo::CreateFileVersionInfo(chrome_exe)); |
628 if (file_version_info) { | 628 if (file_version_info) { |
629 string16 version_string = file_version_info->file_version(); | 629 string16 version_string = file_version_info->file_version(); |
630 if (!version_string.empty() && IsStringASCII(version_string)) | 630 if (!version_string.empty() && IsStringASCII(version_string)) |
631 existing_versions->insert(WideToASCII(version_string)); | 631 existing_versions->insert(base::WideToASCII(version_string)); |
632 } | 632 } |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 void InstallerState::RemoveOldVersionDirectories( | 636 void InstallerState::RemoveOldVersionDirectories( |
637 const Version& new_version, | 637 const Version& new_version, |
638 Version* existing_version, | 638 Version* existing_version, |
639 const base::FilePath& temp_path) const { | 639 const base::FilePath& temp_path) const { |
640 Version version; | 640 Version version; |
641 std::vector<base::FilePath> key_files; | 641 std::vector<base::FilePath> key_files; |
642 scoped_ptr<WorkItem> item; | 642 scoped_ptr<WorkItem> item; |
643 | 643 |
644 std::set<std::string> existing_version_strings; | 644 std::set<std::string> existing_version_strings; |
645 existing_version_strings.insert(new_version.GetString()); | 645 existing_version_strings.insert(new_version.GetString()); |
646 if (existing_version) | 646 if (existing_version) |
647 existing_version_strings.insert(existing_version->GetString()); | 647 existing_version_strings.insert(existing_version->GetString()); |
648 | 648 |
649 // Make sure not to delete any version dir that is "referenced" by an existing | 649 // Make sure not to delete any version dir that is "referenced" by an existing |
650 // Chrome executable. | 650 // Chrome executable. |
651 GetExistingExeVersions(&existing_version_strings); | 651 GetExistingExeVersions(&existing_version_strings); |
652 | 652 |
653 // Try to delete all directories that are not in the set we care to keep. | 653 // Try to delete all directories that are not in the set we care to keep. |
654 file_util::FileEnumerator version_enum(target_path(), false, | 654 file_util::FileEnumerator version_enum(target_path(), false, |
655 file_util::FileEnumerator::DIRECTORIES); | 655 file_util::FileEnumerator::DIRECTORIES); |
656 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 656 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
657 next_version = version_enum.Next()) { | 657 next_version = version_enum.Next()) { |
658 base::FilePath dir_name(next_version.BaseName()); | 658 base::FilePath dir_name(next_version.BaseName()); |
659 version = Version(WideToASCII(dir_name.value())); | 659 version = Version(base::WideToASCII(dir_name.value())); |
660 // Delete the version folder if it is less than the new version and not | 660 // Delete the version folder if it is less than the new version and not |
661 // equal to the old version (if we have an old version). | 661 // equal to the old version (if we have an old version). |
662 if (version.IsValid() && | 662 if (version.IsValid() && |
663 existing_version_strings.count(version.GetString()) == 0) { | 663 existing_version_strings.count(version.GetString()) == 0) { |
664 // Note: temporarily log old version deletion at ERROR level to make it | 664 // Note: temporarily log old version deletion at ERROR level to make it |
665 // more likely we see this in the installer log. | 665 // more likely we see this in the installer log. |
666 LOG(ERROR) << "Deleting old version directory: " << next_version.value(); | 666 LOG(ERROR) << "Deleting old version directory: " << next_version.value(); |
667 | 667 |
668 // Attempt to recursively delete the old version dir. | 668 // Attempt to recursively delete the old version dir. |
669 bool delete_succeeded = file_util::Delete(next_version, true); | 669 bool delete_succeeded = file_util::Delete(next_version, true); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 } | 792 } |
793 if (!install_list->Do()) | 793 if (!install_list->Do()) |
794 LOG(ERROR) << "Failed to record installer error information in registry."; | 794 LOG(ERROR) << "Failed to record installer error information in registry."; |
795 } | 795 } |
796 | 796 |
797 bool InstallerState::RequiresActiveSetup() const { | 797 bool InstallerState::RequiresActiveSetup() const { |
798 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); | 798 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); |
799 } | 799 } |
800 | 800 |
801 } // namespace installer | 801 } // namespace installer |
OLD | NEW |