Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: chrome/installer/setup/setup_util.cc

Issue 2459583002: Use InstallDetails in setup. (Closed)
Patch Set: another doc comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/setup/setup_main.cc ('k') | chrome/installer/setup/setup_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file declares util functions for setup project. 5 // This file declares util functions for setup project.
6 6
7 #include "chrome/installer/setup/setup_util.h" 7 #include "chrome/installer/setup/setup_util.h"
8 8
9 #include <windows.h> 9 #include <windows.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 13 matching lines...) Expand all
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/macros.h" 25 #include "base/macros.h"
26 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
27 #include "base/metrics/histogram_macros.h" 27 #include "base/metrics/histogram_macros.h"
28 #include "base/numerics/safe_conversions.h" 28 #include "base/numerics/safe_conversions.h"
29 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
30 #include "base/strings/utf_string_conversions.h" 30 #include "base/strings/utf_string_conversions.h"
31 #include "base/version.h" 31 #include "base/version.h"
32 #include "base/win/registry.h" 32 #include "base/win/registry.h"
33 #include "base/win/windows_version.h" 33 #include "base/win/windows_version.h"
34 #include "chrome/install_static/install_details.h"
35 #include "chrome/install_static/install_modes.h"
34 #include "chrome/installer/setup/installer_state.h" 36 #include "chrome/installer/setup/installer_state.h"
35 #include "chrome/installer/setup/setup_constants.h" 37 #include "chrome/installer/setup/setup_constants.h"
36 #include "chrome/installer/setup/user_hive_visitor.h" 38 #include "chrome/installer/setup/user_hive_visitor.h"
37 #include "chrome/installer/util/app_registration_data.h" 39 #include "chrome/installer/util/app_registration_data.h"
38 #include "chrome/installer/util/google_update_constants.h" 40 #include "chrome/installer/util/google_update_constants.h"
39 #include "chrome/installer/util/google_update_settings.h" 41 #include "chrome/installer/util/google_update_settings.h"
40 #include "chrome/installer/util/install_util.h" 42 #include "chrome/installer/util/install_util.h"
41 #include "chrome/installer/util/installation_state.h" 43 #include "chrome/installer/util/installation_state.h"
42 #include "chrome/installer/util/master_preferences.h" 44 #include "chrome/installer/util/master_preferences.h"
43 #include "chrome/installer/util/master_preferences_constants.h" 45 #include "chrome/installer/util/master_preferences_constants.h"
44 #include "chrome/installer/util/non_updating_app_registration_data.h" 46 #include "chrome/installer/util/non_updating_app_registration_data.h"
45 #include "chrome/installer/util/updating_app_registration_data.h" 47 #include "chrome/installer/util/updating_app_registration_data.h"
46 #include "chrome/installer/util/util_constants.h" 48 #include "chrome/installer/util/util_constants.h"
47 #include "courgette/courgette.h" 49 #include "courgette/courgette.h"
48 #include "courgette/third_party/bsdiff/bsdiff.h" 50 #include "courgette/third_party/bsdiff/bsdiff.h"
49 51
50 namespace installer { 52 namespace installer {
51 53
52 namespace { 54 namespace {
53 55
54 // Event log providers registry location. 56 // Event log providers registry location.
55 constexpr wchar_t kEventLogProvidersRegPath[] = 57 constexpr wchar_t kEventLogProvidersRegPath[] =
56 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\"; 58 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\";
57 59
58 // TODO(grt): use install_static::InstallDetails::Get().install_full_name() when
59 // InstallDetails is initialized in the installer.
60 base::string16 InstallFullName() {
61 #if defined(GOOGLE_CHROME_BUILD)
62 base::string16 reg_path(L"Chrome");
63 if (InstallUtil::IsChromeSxSProcess())
64 reg_path.append(L" SxS");
65 return reg_path;
66 #else
67 return base::string16(L"Chromium");
68 #endif
69 }
70
71 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's 60 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's
72 // ClientState key for a user) indicates that Chrome has been used within the 61 // ClientState key for a user) indicates that Chrome has been used within the
73 // last 28 days. 62 // last 28 days.
74 bool IsActivelyUsedIn(HKEY root, const wchar_t* key_path) { 63 bool IsActivelyUsedIn(HKEY root, const wchar_t* key_path) {
75 VLOG(1) << "IsActivelyUsedIn probing " << root << "\\" << key_path; 64 VLOG(1) << "IsActivelyUsedIn probing " << root << "\\" << key_path;
76 int days_ago_last_run = GoogleUpdateSettings::GetLastRunTime(); 65 int days_ago_last_run = GoogleUpdateSettings::GetLastRunTime();
77 if (days_ago_last_run >= 0) { 66 if (days_ago_last_run >= 0) {
78 VLOG(1) << "Found a user that last ran Chrome " << days_ago_last_run 67 VLOG(1) << "Found a user that last ran Chrome " << days_ago_last_run
79 << " days ago."; 68 << " days ago.";
80 return days_ago_last_run <= 28; 69 return days_ago_last_run <= 28;
(...skipping 16 matching lines...) Expand all
97 // Stop the iteration. 86 // Stop the iteration.
98 *is_used = true; 87 *is_used = true;
99 return false; 88 return false;
100 } 89 }
101 90
102 // "The binaries" once referred to the on-disk footprint of Chrome and/or Chrome 91 // "The binaries" once referred to the on-disk footprint of Chrome and/or Chrome
103 // Frame when the products were configured to share such on-disk bits. Support 92 // Frame when the products were configured to share such on-disk bits. Support
104 // for this mode of install was dropped from ToT in December 2016. Remove any 93 // for this mode of install was dropped from ToT in December 2016. Remove any
105 // stray bits in the registry leftover from such installs. 94 // stray bits in the registry leftover from such installs.
106 void RemoveBinariesVersionKey(const InstallerState& installer_state) { 95 void RemoveBinariesVersionKey(const InstallerState& installer_state) {
107 base::string16 path(MakeBinariesRegistrationData()->GetVersionKey()); 96 base::string16 path(install_static::GetBinariesClientsKeyPath());
108 if (base::win::RegKey(installer_state.root_key(), path.c_str(), 97 if (base::win::RegKey(installer_state.root_key(), path.c_str(),
109 KEY_QUERY_VALUE | KEY_WOW64_32KEY) 98 KEY_QUERY_VALUE | KEY_WOW64_32KEY)
110 .Valid()) { 99 .Valid()) {
111 const bool success = InstallUtil::DeleteRegistryKey( 100 const bool success = InstallUtil::DeleteRegistryKey(
112 installer_state.root_key(), path, KEY_WOW64_32KEY); 101 installer_state.root_key(), path, KEY_WOW64_32KEY);
113 UMA_HISTOGRAM_BOOLEAN("Setup.Install.DeleteBinariesClientsKey", success); 102 UMA_HISTOGRAM_BOOLEAN("Setup.Install.DeleteBinariesClientsKey", success);
114 } 103 }
115 } 104 }
116 105
117 // Remove leftover traces of multi-install Chrome Frame, if present. Once upon a 106 // Remove leftover traces of multi-install Chrome Frame, if present. Once upon a
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 680
692 base::SparseHistogram::FactoryGet( 681 base::SparseHistogram::FactoryGet(
693 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name, 682 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name,
694 base::HistogramBase::kUmaTargetedHistogramFlag) 683 base::HistogramBase::kUmaTargetedHistogramFlag)
695 ->Add(status); 684 ->Add(status);
696 } 685 }
697 686
698 void RegisterEventLogProvider(const base::FilePath& install_directory, 687 void RegisterEventLogProvider(const base::FilePath& install_directory,
699 const base::Version& version) { 688 const base::Version& version) {
700 base::string16 reg_path(kEventLogProvidersRegPath); 689 base::string16 reg_path(kEventLogProvidersRegPath);
701 reg_path.append(InstallFullName()); 690 reg_path.append(install_static::InstallDetails::Get().install_full_name());
702 VLOG(1) << "Registering Chrome's event log provider at " << reg_path; 691 VLOG(1) << "Registering Chrome's event log provider at " << reg_path;
703 692
704 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 693 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
705 work_item_list->set_log_message("Register event log provider"); 694 work_item_list->set_log_message("Register event log provider");
706 695
707 work_item_list->AddCreateRegKeyWorkItem(HKEY_LOCAL_MACHINE, reg_path, 696 work_item_list->AddCreateRegKeyWorkItem(HKEY_LOCAL_MACHINE, reg_path,
708 WorkItem::kWow64Default); 697 WorkItem::kWow64Default);
709 // Speicifes the number of event categories defined in the dll. 698 // Speicifes the number of event categories defined in the dll.
710 work_item_list->AddSetRegValueWorkItem( 699 work_item_list->AddSetRegValueWorkItem(
711 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default, L"CategoryCount", 700 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default, L"CategoryCount",
(...skipping 19 matching lines...) Expand all
731 } 720 }
732 721
733 // if the operation fails we log the error but still continue because none of 722 // if the operation fails we log the error but still continue because none of
734 // these are critical for the proper operation of the browser. 723 // these are critical for the proper operation of the browser.
735 if (!work_item_list->Do()) 724 if (!work_item_list->Do())
736 work_item_list->Rollback(); 725 work_item_list->Rollback();
737 } 726 }
738 727
739 void DeRegisterEventLogProvider() { 728 void DeRegisterEventLogProvider() {
740 base::string16 reg_path(kEventLogProvidersRegPath); 729 base::string16 reg_path(kEventLogProvidersRegPath);
741 reg_path.append(InstallFullName()); 730 reg_path.append(install_static::InstallDetails::Get().install_full_name());
742 731
743 // TODO(http://crbug.com/668120): If the Event Viewer is open the provider dll 732 // TODO(http://crbug.com/668120): If the Event Viewer is open the provider dll
744 // will fail to get deleted. This doesn't fail the uninstallation altogether 733 // will fail to get deleted. This doesn't fail the uninstallation altogether
745 // but leaves files behind. 734 // but leaves files behind.
746 InstallUtil::DeleteRegistryKey(HKEY_LOCAL_MACHINE, reg_path, 735 InstallUtil::DeleteRegistryKey(HKEY_LOCAL_MACHINE, reg_path,
747 WorkItem::kWow64Default); 736 WorkItem::kWow64Default);
748 } 737 }
749 738
750 std::unique_ptr<AppRegistrationData> MakeBinariesRegistrationData() { 739 std::unique_ptr<AppRegistrationData> MakeBinariesRegistrationData() {
751 #if defined(GOOGLE_CHROME_BUILD) 740 if (install_static::kUseGoogleUpdateIntegration) {
752 return base::MakeUnique<UpdatingAppRegistrationData>( 741 return base::MakeUnique<UpdatingAppRegistrationData>(
753 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"); 742 install_static::kBinariesAppGuid);
754 #else 743 }
755 return base::MakeUnique<NonUpdatingAppRegistrationData>( 744 return base::MakeUnique<NonUpdatingAppRegistrationData>(
756 L"Software\\Chromium Binaries"); 745 base::string16(L"Software\\").append(install_static::kBinariesPathName));
757 #endif
758 } 746 }
759 747
760 bool AreBinariesInstalled(const InstallerState& installer_state) { 748 bool AreBinariesInstalled(const InstallerState& installer_state) {
761 if (InstallUtil::IsChromeSxSProcess()) 749 if (!install_static::InstallDetails::Get().supported_multi_install())
762 return false; 750 return false;
763 751
764 base::win::RegKey key; 752 base::win::RegKey key;
765 base::string16 pv; 753 base::string16 pv;
766 754
767 // True if the "pv" value exists and isn't empty. 755 // True if the "pv" value exists and isn't empty.
768 return key.Open(installer_state.root_key(), 756 return key.Open(installer_state.root_key(),
769 MakeBinariesRegistrationData()->GetVersionKey().c_str(), 757 install_static::GetBinariesClientsKeyPath().c_str(),
770 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && 758 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
771 key.ReadValue(google_update::kRegVersionField, &pv) == ERROR_SUCCESS && 759 key.ReadValue(google_update::kRegVersionField, &pv) == ERROR_SUCCESS &&
772 !pv.empty(); 760 !pv.empty();
773 } 761 }
774 762
775 void DoLegacyCleanups(const InstallerState& installer_state, 763 void DoLegacyCleanups(const InstallerState& installer_state,
776 InstallStatus install_status) { 764 InstallStatus install_status) {
777 // Do no harm if the install didn't succeed. 765 // Do no harm if the install didn't succeed.
778 if (InstallUtil::GetInstallReturnCode(install_status)) 766 if (InstallUtil::GetInstallReturnCode(install_status))
779 return; 767 return;
780 768
781 // The cleanups below only apply to normal Chrome, not side-by-side (canary). 769 // The cleanups below only apply to normal Chrome, not side-by-side (canary).
782 if (InstallUtil::IsChromeSxSProcess()) 770 if (!install_static::InstallDetails::Get().is_primary_mode())
783 return; 771 return;
784 772
785 RemoveBinariesVersionKey(installer_state); 773 RemoveBinariesVersionKey(installer_state);
786 RemoveMultiChromeFrame(installer_state); 774 RemoveMultiChromeFrame(installer_state);
787 RemoveAppLauncherVersionKey(installer_state); 775 RemoveAppLauncherVersionKey(installer_state);
788 RemoveAppHostExe(installer_state); 776 RemoveAppHostExe(installer_state);
789 RemoveLegacyChromeAppCommands(installer_state); 777 RemoveLegacyChromeAppCommands(installer_state);
790 } 778 }
791 779
792 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) 780 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 812 }
825 813
826 ScopedTokenPrivilege::~ScopedTokenPrivilege() { 814 ScopedTokenPrivilege::~ScopedTokenPrivilege() {
827 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { 815 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) {
828 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, 816 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_,
829 sizeof(TOKEN_PRIVILEGES), NULL, NULL); 817 sizeof(TOKEN_PRIVILEGES), NULL, NULL);
830 } 818 }
831 } 819 }
832 820
833 } // namespace installer 821 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/setup_main.cc ('k') | chrome/installer/setup/setup_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698