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_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/version.h" | 17 #include "base/version.h" |
18 #include "chrome/installer/util/copy_tree_work_item.h" | 18 #include "chrome/installer/util/copy_tree_work_item.h" |
19 #include "chrome/installer/util/installation_state.h" | 19 #include "chrome/installer/util/installation_state.h" |
20 #include "chrome/installer/util/installer_state.h" | 20 #include "chrome/installer/util/installer_state.h" |
21 #include "chrome/installer/util/master_preferences.h" | 21 #include "chrome/installer/util/master_preferences.h" |
22 #include "chrome/installer/util/util_constants.h" | 22 #include "chrome/installer/util/util_constants.h" |
23 #include "chrome/installer/util/work_item.h" | 23 #include "chrome/installer/util/work_item.h" |
24 #include "courgette/courgette.h" | 24 #include "courgette/courgette.h" |
| 25 #include "courgette/third_party/bsdiff.h" |
25 #include "third_party/bspatch/mbspatch.h" | 26 #include "third_party/bspatch/mbspatch.h" |
26 | 27 |
27 namespace installer { | 28 namespace installer { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
| 32 // The range of error values for the installer, Courgette, and bsdiff is |
| 33 // overlapping. These offset values disambiguate between different sets |
| 34 // of errors by shifting the values up with the specified offset. |
| 35 const int kCourgetteErrorOffset = 300; |
| 36 const int kBsdiffErrorOffset = 600; |
| 37 |
31 // Launches |setup_exe| with |command_line|, save --install-archive and its | 38 // Launches |setup_exe| with |command_line|, save --install-archive and its |
32 // value if present. Returns false if the process failed to launch. Otherwise, | 39 // value if present. Returns false if the process failed to launch. Otherwise, |
33 // waits indefinitely for it to exit and populates |exit_code| as expected. On | 40 // waits indefinitely for it to exit and populates |exit_code| as expected. On |
34 // the off chance that waiting itself fails, |exit_code| is set to | 41 // the off chance that waiting itself fails, |exit_code| is set to |
35 // WAIT_FOR_EXISTING_FAILED. | 42 // WAIT_FOR_EXISTING_FAILED. |
36 bool LaunchAndWaitForExistingInstall(const base::FilePath& setup_exe, | 43 bool LaunchAndWaitForExistingInstall(const base::FilePath& setup_exe, |
37 const CommandLine& command_line, | 44 const CommandLine& command_line, |
38 int* exit_code) { | 45 int* exit_code) { |
39 DCHECK(exit_code); | 46 DCHECK(exit_code); |
40 CommandLine new_cl(setup_exe); | 47 CommandLine new_cl(setup_exe); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 84 |
78 // Returns true if product |type| cam be meaningfully installed without the | 85 // Returns true if product |type| cam be meaningfully installed without the |
79 // --multi-install flag. | 86 // --multi-install flag. |
80 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 87 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
81 return (type == BrowserDistribution::CHROME_BROWSER || | 88 return (type == BrowserDistribution::CHROME_BROWSER || |
82 type == BrowserDistribution::CHROME_FRAME); | 89 type == BrowserDistribution::CHROME_FRAME); |
83 } | 90 } |
84 | 91 |
85 } // namespace | 92 } // namespace |
86 | 93 |
| 94 int CourgettePatchFiles(const base::FilePath& src, |
| 95 const base::FilePath& patch, |
| 96 const base::FilePath& dest) { |
| 97 VLOG(1) << "Applying Courgette patch " << patch.value() << " to file " |
| 98 << src.value() << " and generating file " << dest.value(); |
| 99 |
| 100 if (src.empty() || patch.empty() || dest.empty()) { |
| 101 return installer::PATCH_INVALID_ARGUMENTS; |
| 102 } |
| 103 |
| 104 const courgette::Status patch_status = |
| 105 courgette::ApplyEnsemblePatch(src.value().c_str(), |
| 106 patch.value().c_str(), |
| 107 dest.value().c_str()); |
| 108 const int exit_code = (patch_status != courgette::C_OK) ? |
| 109 static_cast<int>(patch_status) + kCourgetteErrorOffset : 0; |
| 110 if (exit_code) { |
| 111 VLOG(1) << "Failed to apply patch " << patch.value() |
| 112 << ". err=" << exit_code; |
| 113 } |
| 114 |
| 115 return exit_code; |
| 116 } |
| 117 |
| 118 int BsdiffPatchFiles(const base::FilePath& src, |
| 119 const base::FilePath& patch, |
| 120 const base::FilePath& dest) { |
| 121 VLOG(1) << "Applying bsdiff patch " << patch.value() << " to file " |
| 122 << src.value() << " and generating file " << dest.value(); |
| 123 |
| 124 if (src.empty() || patch.empty() || dest.empty()) { |
| 125 return installer::PATCH_INVALID_ARGUMENTS; |
| 126 } |
| 127 |
| 128 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); |
| 129 const int exit_code = patch_status ? |
| 130 patch_status + kBsdiffErrorOffset : 0; |
| 131 if (exit_code) { |
| 132 VLOG(1) << "Failed to apply patch " << patch.value() |
| 133 << ". err=" << exit_code; |
| 134 } |
| 135 |
| 136 return exit_code; |
| 137 } |
| 138 |
87 int ApplyDiffPatch(const base::FilePath& src, | 139 int ApplyDiffPatch(const base::FilePath& src, |
88 const base::FilePath& patch, | 140 const base::FilePath& patch, |
89 const base::FilePath& dest, | 141 const base::FilePath& dest, |
90 const InstallerState* installer_state) { | 142 const InstallerState* installer_state) { |
91 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() | 143 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() |
92 << " and generating file " << dest.value(); | 144 << " and generating file " << dest.value(); |
93 | 145 |
94 if (installer_state != NULL) | 146 if (installer_state != NULL) |
95 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 147 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
96 | 148 |
(...skipping 13 matching lines...) Expand all Loading... |
110 // we will see. If we run into them, return an error and stay on the | 162 // we will see. If we run into them, return an error and stay on the |
111 // 'ENSEMBLE_PATCHING' update stage. | 163 // 'ENSEMBLE_PATCHING' update stage. |
112 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 164 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
113 patch_status == courgette::C_STREAM_ERROR) { | 165 patch_status == courgette::C_STREAM_ERROR) { |
114 return MEM_ERROR; | 166 return MEM_ERROR; |
115 } | 167 } |
116 | 168 |
117 if (installer_state != NULL) | 169 if (installer_state != NULL) |
118 installer_state->UpdateStage(installer::BINARY_PATCHING); | 170 installer_state->UpdateStage(installer::BINARY_PATCHING); |
119 | 171 |
120 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), | 172 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), |
121 dest.value().c_str()); | 173 patch.value().c_str(), |
| 174 dest.value().c_str()); |
| 175 |
| 176 VLOG(1) << "Failed to apply patch " << patch.value() |
| 177 << " using bsdiff. err=" << binary_patch_status; |
| 178 |
| 179 return binary_patch_status; |
122 } | 180 } |
123 | 181 |
124 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 182 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
125 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 183 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
126 Version* version = NULL; | 184 Version* version = NULL; |
127 file_util::FileEnumerator version_enum(chrome_path, false, | 185 file_util::FileEnumerator version_enum(chrome_path, false, |
128 file_util::FileEnumerator::DIRECTORIES); | 186 file_util::FileEnumerator::DIRECTORIES); |
129 // TODO(tommi): The version directory really should match the version of | 187 // TODO(tommi): The version directory really should match the version of |
130 // setup.exe. To begin with, we should at least DCHECK that that's true. | 188 // setup.exe. To begin with, we should at least DCHECK that that's true. |
131 | 189 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 403 } |
346 | 404 |
347 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 405 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
348 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 406 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
349 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 407 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
350 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 408 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
351 } | 409 } |
352 } | 410 } |
353 | 411 |
354 } // namespace installer | 412 } // namespace installer |
OLD | NEW |