| 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" |
| 27 #include "third_party/bspatch/mbspatch.h" | 28 #include "third_party/bspatch/mbspatch.h" |
| 28 | 29 |
| 29 namespace installer { | 30 namespace installer { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // Launches |setup_exe| with |command_line|, save --install-archive and its | 34 // Launches |setup_exe| with |command_line|, save --install-archive and its |
| 34 // value if present. Returns false if the process failed to launch. Otherwise, | 35 // value if present. Returns false if the process failed to launch. Otherwise, |
| 35 // waits indefinitely for it to exit and populates |exit_code| as expected. On | 36 // waits indefinitely for it to exit and populates |exit_code| as expected. On |
| 36 // the off chance that waiting itself fails, |exit_code| is set to | 37 // 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... |
| 79 | 80 |
| 80 // Returns true if product |type| cam be meaningfully installed without the | 81 // Returns true if product |type| cam be meaningfully installed without the |
| 81 // --multi-install flag. | 82 // --multi-install flag. |
| 82 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 83 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
| 83 return (type == BrowserDistribution::CHROME_BROWSER || | 84 return (type == BrowserDistribution::CHROME_BROWSER || |
| 84 type == BrowserDistribution::CHROME_FRAME); | 85 type == BrowserDistribution::CHROME_FRAME); |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 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() << " to file " |
| 94 << src.value() << " and generating file " << dest.value(); |
| 95 |
| 96 if (src.empty() || patch.empty() || dest.empty()) { |
| 97 return installer::PATCH_INVALID_ARGUMENTS; |
| 98 } |
| 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 if (exit_code) { |
| 107 VLOG(1) << "Failed to apply patch " << patch.value() |
| 108 << ". err=" << exit_code; |
| 109 } |
| 110 |
| 111 return exit_code; |
| 112 } |
| 113 |
| 114 int BsdiffPatchFiles(const base::FilePath& src, |
| 115 const base::FilePath& patch, |
| 116 const base::FilePath& dest) { |
| 117 VLOG(1) << "Applying bsdiff patch " << patch.value() << " to file " |
| 118 << src.value() << " and generating file " << dest.value(); |
| 119 |
| 120 if (src.empty() || patch.empty() || dest.empty()) { |
| 121 return installer::PATCH_INVALID_ARGUMENTS; |
| 122 } |
| 123 |
| 124 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); |
| 125 const int exit_code = patch_status ? |
| 126 patch_status + kBsdiffErrorOffset : 0; |
| 127 if (exit_code) { |
| 128 VLOG(1) << "Failed to apply patch " << patch.value() |
| 129 << ". err=" << exit_code; |
| 130 } |
| 131 |
| 132 return exit_code; |
| 133 } |
| 134 |
| 89 int ApplyDiffPatch(const base::FilePath& src, | 135 int ApplyDiffPatch(const base::FilePath& src, |
| 90 const base::FilePath& patch, | 136 const base::FilePath& patch, |
| 91 const base::FilePath& dest, | 137 const base::FilePath& dest, |
| 92 const InstallerState* installer_state) { | 138 const InstallerState* installer_state) { |
| 93 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() | 139 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() |
| 94 << " and generating file " << dest.value(); | 140 << " and generating file " << dest.value(); |
| 95 | 141 |
| 96 if (installer_state != NULL) | 142 if (installer_state != NULL) |
| 97 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 143 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
| 98 | 144 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 112 // we will see. If we run into them, return an error and stay on the | 158 // we will see. If we run into them, return an error and stay on the |
| 113 // 'ENSEMBLE_PATCHING' update stage. | 159 // 'ENSEMBLE_PATCHING' update stage. |
| 114 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 160 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
| 115 patch_status == courgette::C_STREAM_ERROR) { | 161 patch_status == courgette::C_STREAM_ERROR) { |
| 116 return MEM_ERROR; | 162 return MEM_ERROR; |
| 117 } | 163 } |
| 118 | 164 |
| 119 if (installer_state != NULL) | 165 if (installer_state != NULL) |
| 120 installer_state->UpdateStage(installer::BINARY_PATCHING); | 166 installer_state->UpdateStage(installer::BINARY_PATCHING); |
| 121 | 167 |
| 122 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), | 168 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), |
| 123 dest.value().c_str()); | 169 patch.value().c_str(), |
| 170 dest.value().c_str()); |
| 171 |
| 172 VLOG(1) << "Failed to apply patch " << patch.value() |
| 173 << " using bsdiff. err=" << binary_patch_status; |
| 174 |
| 175 return binary_patch_status; |
| 124 } | 176 } |
| 125 | 177 |
| 126 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 178 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
| 127 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 179 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
| 128 Version* version = NULL; | 180 Version* version = NULL; |
| 129 base::FileEnumerator version_enum(chrome_path, false, | 181 base::FileEnumerator version_enum(chrome_path, false, |
| 130 base::FileEnumerator::DIRECTORIES); | 182 base::FileEnumerator::DIRECTORIES); |
| 131 // TODO(tommi): The version directory really should match the version of | 183 // TODO(tommi): The version directory really should match the version of |
| 132 // setup.exe. To begin with, we should at least DCHECK that that's true. | 184 // setup.exe. To begin with, we should at least DCHECK that that's true. |
| 133 | 185 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 414 } |
| 363 | 415 |
| 364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 416 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 417 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 418 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 419 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 368 } | 420 } |
| 369 } | 421 } |
| 370 | 422 |
| 371 } // namespace installer | 423 } // namespace installer |
| OLD | NEW |