Chromium Code Reviews| 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 |
| 34 // The range of error values for the installer, Courgette, and bsdiff is | |
| 35 // overlapping. These offset values disambiguate between different sets | |
| 36 // of errors by shifting the values up with the specified offset. | |
| 37 const int kCourgetteErrorOffset = 300; | |
| 38 const int kBsdiffErrorOffset = 600; | |
|
robertshield
2013/06/17 16:39:28
This now defines part of the contract for setup.ex
Sorin Jianu
2013/06/17 22:21:09
Done.
| |
| 39 | |
| 33 // Launches |setup_exe| with |command_line|, save --install-archive and its | 40 // Launches |setup_exe| with |command_line|, save --install-archive and its |
| 34 // value if present. Returns false if the process failed to launch. Otherwise, | 41 // 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 | 42 // 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 | 43 // the off chance that waiting itself fails, |exit_code| is set to |
| 37 // WAIT_FOR_EXISTING_FAILED. | 44 // WAIT_FOR_EXISTING_FAILED. |
| 38 bool LaunchAndWaitForExistingInstall(const base::FilePath& setup_exe, | 45 bool LaunchAndWaitForExistingInstall(const base::FilePath& setup_exe, |
| 39 const CommandLine& command_line, | 46 const CommandLine& command_line, |
| 40 int* exit_code) { | 47 int* exit_code) { |
| 41 DCHECK(exit_code); | 48 DCHECK(exit_code); |
| 42 CommandLine new_cl(setup_exe); | 49 CommandLine new_cl(setup_exe); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 86 |
| 80 // Returns true if product |type| cam be meaningfully installed without the | 87 // Returns true if product |type| cam be meaningfully installed without the |
| 81 // --multi-install flag. | 88 // --multi-install flag. |
| 82 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 89 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
| 83 return (type == BrowserDistribution::CHROME_BROWSER || | 90 return (type == BrowserDistribution::CHROME_BROWSER || |
| 84 type == BrowserDistribution::CHROME_FRAME); | 91 type == BrowserDistribution::CHROME_FRAME); |
| 85 } | 92 } |
| 86 | 93 |
| 87 } // namespace | 94 } // namespace |
| 88 | 95 |
| 96 int CourgettePatchFiles(const base::FilePath& src, | |
| 97 const base::FilePath& patch, | |
| 98 const base::FilePath& dest) { | |
| 99 VLOG(1) << "Applying Courgette patch " << patch.value() << " to file " | |
| 100 << src.value() << " and generating file " << dest.value(); | |
| 101 | |
| 102 if (src.empty() || patch.empty() || dest.empty()) { | |
| 103 return installer::PATCH_INVALID_ARGUMENTS; | |
| 104 } | |
| 105 | |
| 106 const courgette::Status patch_status = | |
| 107 courgette::ApplyEnsemblePatch(src.value().c_str(), | |
| 108 patch.value().c_str(), | |
| 109 dest.value().c_str()); | |
| 110 const int exit_code = (patch_status != courgette::C_OK) ? | |
| 111 static_cast<int>(patch_status) + kCourgetteErrorOffset : 0; | |
|
robertshield
2013/06/17 16:39:28
nit: only one space before :
Sorin Jianu
2013/06/17 22:21:09
Done.
| |
| 112 if (exit_code) { | |
| 113 VLOG(1) << "Failed to apply patch " << patch.value() | |
| 114 << ". err=" << exit_code; | |
| 115 } | |
| 116 | |
| 117 return exit_code; | |
| 118 } | |
| 119 | |
| 120 int BsdiffPatchFiles(const base::FilePath& src, | |
| 121 const base::FilePath& patch, | |
| 122 const base::FilePath& dest) { | |
| 123 VLOG(1) << "Applying bsdiff patch " << patch.value() << " to file " | |
| 124 << src.value() << " and generating file " << dest.value(); | |
| 125 | |
| 126 if (src.empty() || patch.empty() || dest.empty()) { | |
| 127 return installer::PATCH_INVALID_ARGUMENTS; | |
| 128 } | |
| 129 | |
| 130 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); | |
| 131 const int exit_code = patch_status ? | |
| 132 patch_status + kBsdiffErrorOffset : 0; | |
| 133 if (exit_code) { | |
| 134 VLOG(1) << "Failed to apply patch " << patch.value() | |
| 135 << ". err=" << exit_code; | |
| 136 } | |
| 137 | |
| 138 return exit_code; | |
| 139 } | |
| 140 | |
| 89 int ApplyDiffPatch(const base::FilePath& src, | 141 int ApplyDiffPatch(const base::FilePath& src, |
| 90 const base::FilePath& patch, | 142 const base::FilePath& patch, |
| 91 const base::FilePath& dest, | 143 const base::FilePath& dest, |
| 92 const InstallerState* installer_state) { | 144 const InstallerState* installer_state) { |
| 93 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() | 145 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() |
| 94 << " and generating file " << dest.value(); | 146 << " and generating file " << dest.value(); |
| 95 | 147 |
| 96 if (installer_state != NULL) | 148 if (installer_state != NULL) |
| 97 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 149 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
| 98 | 150 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 112 // we will see. If we run into them, return an error and stay on the | 164 // we will see. If we run into them, return an error and stay on the |
| 113 // 'ENSEMBLE_PATCHING' update stage. | 165 // 'ENSEMBLE_PATCHING' update stage. |
| 114 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 166 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
| 115 patch_status == courgette::C_STREAM_ERROR) { | 167 patch_status == courgette::C_STREAM_ERROR) { |
| 116 return MEM_ERROR; | 168 return MEM_ERROR; |
| 117 } | 169 } |
| 118 | 170 |
| 119 if (installer_state != NULL) | 171 if (installer_state != NULL) |
| 120 installer_state->UpdateStage(installer::BINARY_PATCHING); | 172 installer_state->UpdateStage(installer::BINARY_PATCHING); |
| 121 | 173 |
| 122 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), | 174 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), |
| 123 dest.value().c_str()); | 175 patch.value().c_str(), |
| 176 dest.value().c_str()); | |
| 177 | |
| 178 VLOG(1) << "Failed to apply patch " << patch.value() | |
| 179 << " using bsdiff. err=" << binary_patch_status; | |
| 180 | |
| 181 return binary_patch_status; | |
| 124 } | 182 } |
| 125 | 183 |
| 126 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 184 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
| 127 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 185 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
| 128 Version* version = NULL; | 186 Version* version = NULL; |
| 129 base::FileEnumerator version_enum(chrome_path, false, | 187 base::FileEnumerator version_enum(chrome_path, false, |
| 130 base::FileEnumerator::DIRECTORIES); | 188 base::FileEnumerator::DIRECTORIES); |
| 131 // TODO(tommi): The version directory really should match the version of | 189 // 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. | 190 // setup.exe. To begin with, we should at least DCHECK that that's true. |
| 133 | 191 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 420 } |
| 363 | 421 |
| 364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 422 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 423 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 424 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 425 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 368 } | 426 } |
| 369 } | 427 } |
| 370 | 428 |
| 371 } // namespace installer | 429 } // namespace installer |
| OLD | NEW |