| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 VLOG(2) << "It seems that the package is being updated."; | 68 VLOG(2) << "It seems that the package is being updated."; |
| 69 | 69 |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 InstallerState::InstallerState() | 73 InstallerState::InstallerState() |
| 74 : operation_(UNINITIALIZED), | 74 : operation_(UNINITIALIZED), |
| 75 state_type_(BrowserDistribution::CHROME_BROWSER), |
| 75 multi_package_distribution_(NULL), | 76 multi_package_distribution_(NULL), |
| 76 level_(UNKNOWN_LEVEL), | 77 level_(UNKNOWN_LEVEL), |
| 77 package_type_(UNKNOWN_PACKAGE_TYPE), | 78 package_type_(UNKNOWN_PACKAGE_TYPE), |
| 78 state_type_(BrowserDistribution::CHROME_BROWSER), | |
| 79 root_key_(NULL), | 79 root_key_(NULL), |
| 80 msi_(false), | 80 msi_(false), |
| 81 verbose_logging_(false), | 81 verbose_logging_(false), |
| 82 ensure_google_update_present_(false) { | 82 ensure_google_update_present_(false) { |
| 83 } | 83 } |
| 84 | 84 |
| 85 InstallerState::InstallerState(Level level) | 85 InstallerState::InstallerState(Level level) |
| 86 : operation_(UNINITIALIZED), | 86 : operation_(UNINITIALIZED), |
| 87 state_type_(BrowserDistribution::CHROME_BROWSER), |
| 87 multi_package_distribution_(NULL), | 88 multi_package_distribution_(NULL), |
| 88 level_(UNKNOWN_LEVEL), | 89 level_(UNKNOWN_LEVEL), |
| 89 package_type_(UNKNOWN_PACKAGE_TYPE), | 90 package_type_(UNKNOWN_PACKAGE_TYPE), |
| 90 state_type_(BrowserDistribution::CHROME_BROWSER), | |
| 91 root_key_(NULL), | 91 root_key_(NULL), |
| 92 msi_(false), | 92 msi_(false), |
| 93 verbose_logging_(false), | 93 verbose_logging_(false), |
| 94 ensure_google_update_present_(false) { | 94 ensure_google_update_present_(false) { |
| 95 // Use set_level() so that root_key_ is updated properly. | 95 // Use set_level() so that root_key_ is updated properly. |
| 96 set_level(level); | 96 set_level(level); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void InstallerState::Initialize(const CommandLine& command_line, | 99 void InstallerState::Initialize(const CommandLine& command_line, |
| 100 const MasterPreferences& prefs, | 100 const MasterPreferences& prefs, |
| 101 const InstallationState& machine_state) { | 101 const InstallationState& machine_state) { |
| 102 Clear(); |
| 103 |
| 102 bool pref_bool; | 104 bool pref_bool; |
| 103 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) | 105 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) |
| 104 pref_bool = false; | 106 pref_bool = false; |
| 105 set_level(pref_bool ? SYSTEM_LEVEL : USER_LEVEL); | 107 set_level(pref_bool ? SYSTEM_LEVEL : USER_LEVEL); |
| 106 | 108 |
| 107 if (!prefs.GetBool(master_preferences::kVerboseLogging, &verbose_logging_)) | 109 if (!prefs.GetBool(master_preferences::kVerboseLogging, &verbose_logging_)) |
| 108 verbose_logging_ = false; | 110 verbose_logging_ = false; |
| 109 | 111 |
| 110 if (!prefs.GetBool(master_preferences::kMultiInstall, &pref_bool)) | 112 if (!prefs.GetBool(master_preferences::kMultiInstall, &pref_bool)) |
| 111 pref_bool = false; | 113 pref_bool = false; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 593 |
| 592 bool InstallerState::IsChromeFrameRunning( | 594 bool InstallerState::IsChromeFrameRunning( |
| 593 const InstallationState& machine_state) const { | 595 const InstallationState& machine_state) const { |
| 594 return AnyExistsAndIsInUse(machine_state, CHROME_FRAME_DLL); | 596 return AnyExistsAndIsInUse(machine_state, CHROME_FRAME_DLL); |
| 595 } | 597 } |
| 596 | 598 |
| 597 bool InstallerState::AreBinariesInUse( | 599 bool InstallerState::AreBinariesInUse( |
| 598 const InstallationState& machine_state) const { | 600 const InstallationState& machine_state) const { |
| 599 return AnyExistsAndIsInUse( | 601 return AnyExistsAndIsInUse( |
| 600 machine_state, | 602 machine_state, |
| 601 CHROME_FRAME_DLL | CHROME_FRAME_HELPER_EXE | CHROME_DLL); | 603 (CHROME_FRAME_HELPER_EXE | CHROME_FRAME_HELPER_DLL | |
| 604 CHROME_FRAME_DLL | CHROME_DLL)); |
| 602 } | 605 } |
| 603 | 606 |
| 604 base::FilePath InstallerState::GetInstallerDirectory( | 607 base::FilePath InstallerState::GetInstallerDirectory( |
| 605 const Version& version) const { | 608 const Version& version) const { |
| 606 return target_path().Append(ASCIIToWide(version.GetString())) | 609 return target_path().Append(ASCIIToWide(version.GetString())) |
| 607 .Append(kInstallerDir); | 610 .Append(kInstallerDir); |
| 608 } | 611 } |
| 609 | 612 |
| 610 // static | 613 // static |
| 611 bool InstallerState::IsFileInUse(const base::FilePath& file) { | 614 bool InstallerState::IsFileInUse(const base::FilePath& file) { |
| 612 // Call CreateFile with a share mode of 0 which should cause this to fail | 615 // Call CreateFile with a share mode of 0 which should cause this to fail |
| 613 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. | 616 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. |
| 614 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), | 617 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), |
| 615 GENERIC_WRITE, 0, NULL, | 618 GENERIC_WRITE, 0, NULL, |
| 616 OPEN_EXISTING, 0, 0)).IsValid(); | 619 OPEN_EXISTING, 0, 0)).IsValid(); |
| 617 } | 620 } |
| 618 | 621 |
| 622 void InstallerState::Clear() { |
| 623 operation_ = UNINITIALIZED; |
| 624 target_path_.clear(); |
| 625 state_key_.clear(); |
| 626 state_type_ = BrowserDistribution::CHROME_BROWSER; |
| 627 products_.clear(); |
| 628 multi_package_distribution_ = NULL; |
| 629 critical_update_version_ = base::Version(); |
| 630 level_ = UNKNOWN_LEVEL; |
| 631 package_type_ = UNKNOWN_PACKAGE_TYPE; |
| 632 root_key_ = NULL; |
| 633 msi_ = false; |
| 634 verbose_logging_ = false; |
| 635 ensure_google_update_present_ = false; |
| 636 } |
| 637 |
| 619 bool InstallerState::AnyExistsAndIsInUse( | 638 bool InstallerState::AnyExistsAndIsInUse( |
| 620 const InstallationState& machine_state, | 639 const InstallationState& machine_state, |
| 621 uint32 file_bits) const { | 640 uint32 file_bits) const { |
| 622 static const wchar_t* const kBinaryFileNames[] = { | 641 static const wchar_t* const kBinaryFileNames[] = { |
| 642 kChromeDll, |
| 623 kChromeFrameDll, | 643 kChromeFrameDll, |
| 644 kChromeFrameHelperDll, |
| 624 kChromeFrameHelperExe, | 645 kChromeFrameHelperExe, |
| 625 kChromeDll, | |
| 626 }; | 646 }; |
| 627 DCHECK_NE(file_bits, 0U); | 647 DCHECK_NE(file_bits, 0U); |
| 628 DCHECK_LT(file_bits, 1U << NUM_BINARIES); | 648 DCHECK_LT(file_bits, 1U << NUM_BINARIES); |
| 629 COMPILE_ASSERT(CHROME_FRAME_DLL == 1,no_youre_out_of_order); | 649 COMPILE_ASSERT(CHROME_DLL == 1, no_youre_out_of_order); |
| 630 COMPILE_ASSERT(CHROME_FRAME_HELPER_EXE == 2, no_youre_out_of_order); | 650 COMPILE_ASSERT(CHROME_FRAME_DLL == 2, no_youre_out_of_order); |
| 631 COMPILE_ASSERT(CHROME_DLL == 4, no_youre_out_of_order); | 651 COMPILE_ASSERT(CHROME_FRAME_HELPER_DLL == 4, no_youre_out_of_order); |
| 652 COMPILE_ASSERT(CHROME_FRAME_HELPER_EXE == 8, no_youre_out_of_order); |
| 632 | 653 |
| 633 // Check only for the current version (i.e., the version we are upgrading | 654 // Check only for the current version (i.e., the version we are upgrading |
| 634 // _from_). Later versions from pending in-use updates need not be checked | 655 // _from_). Later versions from pending in-use updates need not be checked |
| 635 // since the current version is guaranteed to be in use if any such are. | 656 // since the current version is guaranteed to be in use if any such are. |
| 636 bool in_use = false; | 657 bool in_use = false; |
| 637 scoped_ptr<Version> current_version(GetCurrentVersion(machine_state)); | 658 scoped_ptr<Version> current_version(GetCurrentVersion(machine_state)); |
| 638 if (!current_version) | 659 if (!current_version) |
| 639 return false; | 660 return false; |
| 640 base::FilePath directory( | 661 base::FilePath directory( |
| 641 target_path().AppendASCII(current_version->GetString())); | 662 target_path().AppendASCII(current_version->GetString())); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 } | 847 } |
| 827 if (!install_list->Do()) | 848 if (!install_list->Do()) |
| 828 LOG(ERROR) << "Failed to record installer error information in registry."; | 849 LOG(ERROR) << "Failed to record installer error information in registry."; |
| 829 } | 850 } |
| 830 | 851 |
| 831 bool InstallerState::RequiresActiveSetup() const { | 852 bool InstallerState::RequiresActiveSetup() const { |
| 832 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); | 853 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); |
| 833 } | 854 } |
| 834 | 855 |
| 835 } // namespace installer | 856 } // namespace installer |
| OLD | NEW |