| 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 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/version.h" | 18 #include "base/version.h" |
| 19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 20 #include "chrome/installer/util/copy_tree_work_item.h" | 20 #include "chrome/installer/util/copy_tree_work_item.h" |
| 21 #include "chrome/installer/util/installation_state.h" | 21 #include "chrome/installer/util/installation_state.h" |
| 22 #include "chrome/installer/util/installer_state.h" | 22 #include "chrome/installer/util/installer_state.h" |
| 23 #include "chrome/installer/util/master_preferences.h" | 23 #include "chrome/installer/util/master_preferences.h" |
| 24 #include "chrome/installer/util/util_constants.h" | 24 #include "chrome/installer/util/util_constants.h" |
| 25 #include "chrome/installer/util/work_item.h" | 25 #include "chrome/installer/util/work_item.h" |
| 26 #include "courgette/courgette.h" | 26 #include "courgette/courgette.h" |
| 27 #include "courgette/third_party/bsdiff.h" | |
| 28 #include "third_party/bspatch/mbspatch.h" | 27 #include "third_party/bspatch/mbspatch.h" |
| 29 | 28 |
| 30 namespace installer { | 29 namespace installer { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // Launches |setup_exe| with |command_line|, save --install-archive and its | 33 // Launches |setup_exe| with |command_line|, save --install-archive and its |
| 35 // value if present. Returns false if the process failed to launch. Otherwise, | 34 // value if present. Returns false if the process failed to launch. Otherwise, |
| 36 // waits indefinitely for it to exit and populates |exit_code| as expected. On | 35 // waits indefinitely for it to exit and populates |exit_code| as expected. On |
| 37 // the off chance that waiting itself fails, |exit_code| is set to | 36 // the off chance that waiting itself fails, |exit_code| is set to |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 79 |
| 81 // Returns true if product |type| cam be meaningfully installed without the | 80 // Returns true if product |type| cam be meaningfully installed without the |
| 82 // --multi-install flag. | 81 // --multi-install flag. |
| 83 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 82 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
| 84 return (type == BrowserDistribution::CHROME_BROWSER || | 83 return (type == BrowserDistribution::CHROME_BROWSER || |
| 85 type == BrowserDistribution::CHROME_FRAME); | 84 type == BrowserDistribution::CHROME_FRAME); |
| 86 } | 85 } |
| 87 | 86 |
| 88 } // namespace | 87 } // namespace |
| 89 | 88 |
| 90 int CourgettePatchFiles(const base::FilePath& src, | |
| 91 const base::FilePath& patch, | |
| 92 const base::FilePath& dest) { | |
| 93 VLOG(1) << "Applying Courgette patch " << patch.value() | |
| 94 << " to file " << src.value() | |
| 95 << " and generating file " << dest.value(); | |
| 96 | |
| 97 if (src.empty() || patch.empty() || dest.empty()) | |
| 98 return installer::PATCH_INVALID_ARGUMENTS; | |
| 99 | |
| 100 const courgette::Status patch_status = | |
| 101 courgette::ApplyEnsemblePatch(src.value().c_str(), | |
| 102 patch.value().c_str(), | |
| 103 dest.value().c_str()); | |
| 104 const int exit_code = (patch_status != courgette::C_OK) ? | |
| 105 static_cast<int>(patch_status) + kCourgetteErrorOffset : 0; | |
| 106 | |
| 107 LOG_IF(ERROR, exit_code) | |
| 108 << "Failed to apply Courgette patch " << patch.value() | |
| 109 << " to file " << src.value() << " and generating file " << dest.value() | |
| 110 << ". err=" << exit_code; | |
| 111 | |
| 112 return exit_code; | |
| 113 } | |
| 114 | |
| 115 int BsdiffPatchFiles(const base::FilePath& src, | |
| 116 const base::FilePath& patch, | |
| 117 const base::FilePath& dest) { | |
| 118 VLOG(1) << "Applying bsdiff patch " << patch.value() | |
| 119 << " to file " << src.value() | |
| 120 << " and generating file " << dest.value(); | |
| 121 | |
| 122 if (src.empty() || patch.empty() || dest.empty()) | |
| 123 return installer::PATCH_INVALID_ARGUMENTS; | |
| 124 | |
| 125 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); | |
| 126 const int exit_code = patch_status != OK ? | |
| 127 patch_status + kBsdiffErrorOffset : 0; | |
| 128 | |
| 129 LOG_IF(ERROR, exit_code) | |
| 130 << "Failed to apply bsdiff patch " << patch.value() | |
| 131 << " to file " << src.value() << " and generating file " << dest.value() | |
| 132 << ". err=" << exit_code; | |
| 133 | |
| 134 return exit_code; | |
| 135 } | |
| 136 | |
| 137 int ApplyDiffPatch(const base::FilePath& src, | 89 int ApplyDiffPatch(const base::FilePath& src, |
| 138 const base::FilePath& patch, | 90 const base::FilePath& patch, |
| 139 const base::FilePath& dest, | 91 const base::FilePath& dest, |
| 140 const InstallerState* installer_state) { | 92 const InstallerState* installer_state) { |
| 141 VLOG(1) << "Applying patch " << patch.value() << " to file " | 93 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() |
| 142 << src.value() << " and generating file " << dest.value(); | 94 << " and generating file " << dest.value(); |
| 143 | 95 |
| 144 if (installer_state != NULL) | 96 if (installer_state != NULL) |
| 145 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 97 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
| 146 | 98 |
| 147 // Try Courgette first. Courgette checks the patch file first and fails | 99 // Try Courgette first. Courgette checks the patch file first and fails |
| 148 // quickly if the patch file does not have a valid Courgette header. | 100 // quickly if the patch file does not have a valid Courgette header. |
| 149 courgette::Status patch_status = | 101 courgette::Status patch_status = |
| 150 courgette::ApplyEnsemblePatch(src.value().c_str(), | 102 courgette::ApplyEnsemblePatch(src.value().c_str(), |
| 151 patch.value().c_str(), | 103 patch.value().c_str(), |
| 152 dest.value().c_str()); | 104 dest.value().c_str()); |
| 153 if (patch_status == courgette::C_OK) | 105 if (patch_status == courgette::C_OK) |
| 154 return 0; | 106 return 0; |
| 155 | 107 |
| 156 LOG(ERROR) | 108 VLOG(1) << "Failed to apply patch " << patch.value() |
| 157 << "Failed to apply patch " << patch.value() | 109 << " using courgette. err=" << patch_status; |
| 158 << " to file " << src.value() << " and generating file " << dest.value() | |
| 159 << " using courgette. err=" << patch_status; | |
| 160 | 110 |
| 161 // If we ran out of memory or disk space, then these are likely the errors | 111 // If we ran out of memory or disk space, then these are likely the errors |
| 162 // we will see. If we run into them, return an error and stay on the | 112 // we will see. If we run into them, return an error and stay on the |
| 163 // 'ENSEMBLE_PATCHING' update stage. | 113 // 'ENSEMBLE_PATCHING' update stage. |
| 164 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 114 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
| 165 patch_status == courgette::C_STREAM_ERROR) { | 115 patch_status == courgette::C_STREAM_ERROR) { |
| 166 return MEM_ERROR; | 116 return MEM_ERROR; |
| 167 } | 117 } |
| 168 | 118 |
| 169 if (installer_state != NULL) | 119 if (installer_state != NULL) |
| 170 installer_state->UpdateStage(installer::BINARY_PATCHING); | 120 installer_state->UpdateStage(installer::BINARY_PATCHING); |
| 171 | 121 |
| 172 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), | 122 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), |
| 173 patch.value().c_str(), | 123 dest.value().c_str()); |
| 174 dest.value().c_str()); | |
| 175 | |
| 176 LOG_IF(ERROR, binary_patch_status != OK) | |
| 177 << "Failed to apply patch " << patch.value() | |
| 178 << " to file " << src.value() << " and generating file " << dest.value() | |
| 179 << " using bsdiff. err=" << binary_patch_status; | |
| 180 | |
| 181 return binary_patch_status; | |
| 182 } | 124 } |
| 183 | 125 |
| 184 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 126 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
| 185 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 127 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
| 186 Version* version = NULL; | 128 Version* version = NULL; |
| 187 base::FileEnumerator version_enum(chrome_path, false, | 129 base::FileEnumerator version_enum(chrome_path, false, |
| 188 base::FileEnumerator::DIRECTORIES); | 130 base::FileEnumerator::DIRECTORIES); |
| 189 // TODO(tommi): The version directory really should match the version of | 131 // TODO(tommi): The version directory really should match the version of |
| 190 // setup.exe. To begin with, we should at least DCHECK that that's true. | 132 // setup.exe. To begin with, we should at least DCHECK that that's true. |
| 191 | 133 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 362 } |
| 421 | 363 |
| 422 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 423 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 424 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 425 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 426 } | 368 } |
| 427 } | 369 } |
| 428 | 370 |
| 429 } // namespace installer | 371 } // namespace installer |
| OLD | NEW |