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 // 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 <stdint.h> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/cpu.h" | 13 #include "base/cpu.h" |
13 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/process/kill.h" | 18 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
19 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
| 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
22 #include "base/version.h" | 25 #include "base/version.h" |
23 #include "base/win/registry.h" | 26 #include "base/win/registry.h" |
| 27 #include "base/win/win_util.h" |
24 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
25 #include "chrome/installer/setup/setup_constants.h" | 29 #include "chrome/installer/setup/setup_constants.h" |
| 30 #include "chrome/installer/setup/update_active_setup_version_work_item.h" |
| 31 #include "chrome/installer/util/app_registration_data.h" |
26 #include "chrome/installer/util/app_registration_data.h" | 32 #include "chrome/installer/util/app_registration_data.h" |
27 #include "chrome/installer/util/copy_tree_work_item.h" | 33 #include "chrome/installer/util/copy_tree_work_item.h" |
28 #include "chrome/installer/util/google_update_constants.h" | 34 #include "chrome/installer/util/google_update_constants.h" |
| 35 #include "chrome/installer/util/install_util.h" |
29 #include "chrome/installer/util/installation_state.h" | 36 #include "chrome/installer/util/installation_state.h" |
30 #include "chrome/installer/util/installer_state.h" | 37 #include "chrome/installer/util/installer_state.h" |
31 #include "chrome/installer/util/master_preferences.h" | 38 #include "chrome/installer/util/master_preferences.h" |
32 #include "chrome/installer/util/util_constants.h" | 39 #include "chrome/installer/util/util_constants.h" |
33 #include "chrome/installer/util/work_item.h" | 40 #include "chrome/installer/util/work_item.h" |
34 #include "courgette/courgette.h" | 41 #include "courgette/courgette.h" |
35 #include "courgette/third_party/bsdiff.h" | 42 #include "courgette/third_party/bsdiff.h" |
36 #include "third_party/bspatch/mbspatch.h" | 43 #include "third_party/bspatch/mbspatch.h" |
37 | 44 |
38 namespace installer { | 45 namespace installer { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 95 |
89 // Returns true if product |type| cam be meaningfully installed without the | 96 // Returns true if product |type| cam be meaningfully installed without the |
90 // --multi-install flag. | 97 // --multi-install flag. |
91 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 98 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
92 return (type == BrowserDistribution::CHROME_BROWSER || | 99 return (type == BrowserDistribution::CHROME_BROWSER || |
93 type == BrowserDistribution::CHROME_FRAME); | 100 type == BrowserDistribution::CHROME_FRAME); |
94 } | 101 } |
95 | 102 |
96 } // namespace | 103 } // namespace |
97 | 104 |
| 105 bool UpdateLastOSUpgradeHandledByActiveSetup(BrowserDistribution* dist) { |
| 106 // FIRST: Find the value of the latest OS upgrade registered in the Active |
| 107 // Setup version (bumped on every major OS upgrade), defaults to 0 if no OS |
| 108 // upgrade was ever encountered by this install. |
| 109 DWORD latest_os_upgrade = 0; |
| 110 |
| 111 { |
| 112 const base::string16 active_setup_key_path( |
| 113 InstallUtil::GetActiveSetupPath(dist)); |
| 114 |
| 115 base::win::RegKey active_setup_key; |
| 116 if (active_setup_key.Open(HKEY_LOCAL_MACHINE, active_setup_key_path.c_str(), |
| 117 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 118 base::string16 existing_version; |
| 119 if (active_setup_key.ReadValue(L"Version", |
| 120 &existing_version) == ERROR_SUCCESS) { |
| 121 std::vector<base::string16> version_components = |
| 122 base::SplitString(existing_version, L",", base::TRIM_WHITESPACE, |
| 123 base::SPLIT_WANT_NONEMPTY); |
| 124 uint32_t latest_os_upgrade_uint = 0; |
| 125 if (version_components.size() == 4U && |
| 126 base::StringToUint( |
| 127 version_components[UpdateActiveSetupVersionWorkItem:: |
| 128 VersionComponent::OS_UPGRADES], |
| 129 &latest_os_upgrade_uint)) { |
| 130 latest_os_upgrade = static_cast<DWORD>(latest_os_upgrade_uint); |
| 131 } else { |
| 132 LOG(ERROR) << "Failed to parse OS_UPGRADES component of " |
| 133 << existing_version; |
| 134 } |
| 135 } |
| 136 } |
| 137 } |
| 138 |
| 139 // Whether the read failed or the existing value is 0, do not proceed. |
| 140 if (latest_os_upgrade == 0U) |
| 141 return false; |
| 142 |
| 143 static const wchar_t kLastOSUpgradeHandledRegName[] = L"LastOSUpgradeHandled"; |
| 144 |
| 145 // SECOND: Find out the value of the last OS upgrade handled, defaults to 0 if |
| 146 // none was ever handled. |
| 147 DWORD last_os_upgrade_handled = 0; |
| 148 |
| 149 base::string16 last_upgrade_handled_key_path = |
| 150 dist->GetAppRegistrationData().GetStateMediumKey(); |
| 151 last_upgrade_handled_key_path.push_back(L'\\'); |
| 152 last_upgrade_handled_key_path.append(kLastOSUpgradeHandledRegName); |
| 153 |
| 154 base::string16 user_specific_value; |
| 155 // This should never fail. If it does, the beacon will be written in the key's |
| 156 // default value, which is okay since the majority case is likely a machine |
| 157 // with a single user. |
| 158 if (!base::win::GetUserSidString(&user_specific_value)) |
| 159 NOTREACHED(); |
| 160 |
| 161 base::win::RegKey last_upgrade_key; |
| 162 if (last_upgrade_key.Create( |
| 163 HKEY_LOCAL_MACHINE, last_upgrade_handled_key_path.c_str(), |
| 164 KEY_WOW64_32KEY | KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 165 LOG(ERROR) << "Failed to create LastOSUpgradeHandled value @ " |
| 166 << last_upgrade_handled_key_path; |
| 167 // If the key is not read/writeable, do not proceed as this could result in |
| 168 // handling an OS upgrade twice. |
| 169 return false; |
| 170 } |
| 171 |
| 172 // It's okay for this read to fail (i.e. there is an OS upgrade available but |
| 173 // this user never handled one yet). |
| 174 last_upgrade_key.ReadValueDW(user_specific_value.c_str(), |
| 175 &last_os_upgrade_handled); |
| 176 |
| 177 // THIRD: Figure out whether the latest OS upgrade has been handled already. |
| 178 |
| 179 if (last_os_upgrade_handled >= latest_os_upgrade) { |
| 180 LOG_IF(ERROR, last_os_upgrade_handled > latest_os_upgrade) |
| 181 << "Last OS upgrade handled is somehow ahead of the latest OS upgrade?"; |
| 182 VLOG_IF(1, last_os_upgrade_handled == latest_os_upgrade) |
| 183 << "Latest OS upgrade already handled."; |
| 184 return false; |
| 185 } |
| 186 |
| 187 // At this point |last_os_upgrade_handled < latest_os_upgrade| so, |
| 188 // FOURTH: store the fact that the latest OS upgrade has been handled and |
| 189 // return true for the caller to act accordingly. |
| 190 |
| 191 if (last_upgrade_key.WriteValue(user_specific_value.c_str(), |
| 192 latest_os_upgrade) != ERROR_SUCCESS) { |
| 193 LOG(ERROR) << "Failed to save latest_os_upgrade value (" |
| 194 << latest_os_upgrade << ") to " << last_upgrade_handled_key_path; |
| 195 // Do not proceed if the write fails as this could otherwise result in |
| 196 // handling this OS upgrade multiple times. |
| 197 return false; |
| 198 } |
| 199 |
| 200 return true; |
| 201 } |
| 202 |
98 int CourgettePatchFiles(const base::FilePath& src, | 203 int CourgettePatchFiles(const base::FilePath& src, |
99 const base::FilePath& patch, | 204 const base::FilePath& patch, |
100 const base::FilePath& dest) { | 205 const base::FilePath& dest) { |
101 VLOG(1) << "Applying Courgette patch " << patch.value() | 206 VLOG(1) << "Applying Courgette patch " << patch.value() |
102 << " to file " << src.value() | 207 << " to file " << src.value() |
103 << " and generating file " << dest.value(); | 208 << " and generating file " << dest.value(); |
104 | 209 |
105 if (src.empty() || patch.empty() || dest.empty()) | 210 if (src.empty() || patch.empty() || dest.empty()) |
106 return installer::PATCH_INVALID_ARGUMENTS; | 211 return installer::PATCH_INVALID_ARGUMENTS; |
107 | 212 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } | 617 } |
513 | 618 |
514 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 619 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
515 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 620 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
516 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, | 621 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, |
517 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 622 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
518 } | 623 } |
519 } | 624 } |
520 | 625 |
521 } // namespace installer | 626 } // namespace installer |
OLD | NEW |