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
3 // found in the LICENSE file.
5 #include "chrome/installer/setup/setup_main.h"
14 #include "base/at_exit.h"
15 #include "base/basictypes.h"
16 #include "base/command_line.h"
17 #include "base/file_version_info.h"
18 #include "base/files/file_path.h"
19 #include "base/files/file_util.h"
20 #include "base/files/scoped_temp_dir.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/path_service.h"
23 #include "base/process/launch.h"
24 #include "base/strings/string16.h"
25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/string_util.h"
27 #include "base/strings/stringprintf.h"
28 #include "base/strings/utf_string_conversions.h"
29 #include "base/values.h"
30 #include "base/version.h"
31 #include "base/win/registry.h"
32 #include "base/win/scoped_com_initializer.h"
33 #include "base/win/scoped_comptr.h"
34 #include "base/win/scoped_handle.h"
35 #include "base/win/win_util.h"
36 #include "base/win/windows_version.h"
37 #include "breakpad/src/client/windows/handler/exception_handler.h"
38 #include "chrome/common/chrome_constants.h"
39 #include "chrome/common/chrome_paths.h"
40 #include "chrome/common/chrome_switches.h"
41 #include "chrome/installer/setup/archive_patch_helper.h"
42 #include "chrome/installer/setup/install.h"
43 #include "chrome/installer/setup/install_worker.h"
44 #include "chrome/installer/setup/setup_constants.h"
45 #include "chrome/installer/setup/setup_util.h"
46 #include "chrome/installer/setup/uninstall.h"
47 #include "chrome/installer/util/browser_distribution.h"
48 #include "chrome/installer/util/channel_info.h"
49 #include "chrome/installer/util/delete_after_reboot_helper.h"
50 #include "chrome/installer/util/delete_tree_work_item.h"
51 #include "chrome/installer/util/google_update_constants.h"
52 #include "chrome/installer/util/google_update_settings.h"
53 #include "chrome/installer/util/google_update_util.h"
54 #include "chrome/installer/util/helper.h"
55 #include "chrome/installer/util/html_dialog.h"
56 #include "chrome/installer/util/install_util.h"
57 #include "chrome/installer/util/installation_state.h"
58 #include "chrome/installer/util/installation_validator.h"
59 #include "chrome/installer/util/installer_state.h"
60 #include "chrome/installer/util/installer_util_strings.h"
61 #include "chrome/installer/util/l10n_string_util.h"
62 #include "chrome/installer/util/logging_installer.h"
63 #include "chrome/installer/util/lzma_util.h"
64 #include "chrome/installer/util/master_preferences.h"
65 #include "chrome/installer/util/master_preferences_constants.h"
66 #include "chrome/installer/util/self_cleaning_temp_dir.h"
67 #include "chrome/installer/util/shell_util.h"
68 #include "chrome/installer/util/user_experiment.h"
70 #if defined(GOOGLE_CHROME_BUILD)
71 #include "chrome/installer/util/updating_app_registration_data.h"
74 using installer::InstallerState
;
75 using installer::InstallationState
;
76 using installer::InstallationValidator
;
77 using installer::MasterPreferences
;
78 using installer::Product
;
79 using installer::ProductState
;
80 using installer::Products
;
82 const wchar_t kGoogleUpdatePipeName
[] = L
"\\\\.\\pipe\\GoogleCrashServices\\";
83 const wchar_t kSystemPrincipalSid
[] = L
"S-1-5-18";
85 const MINIDUMP_TYPE kLargerDumpType
= static_cast<MINIDUMP_TYPE
>(
86 MiniDumpWithProcessThreadData
| // Get PEB and TEB.
87 MiniDumpWithUnloadedModules
| // Get unloaded modules when available.
88 MiniDumpWithIndirectlyReferencedMemory
); // Get memory referenced by stack.
92 // Returns NULL if no compressed archive is available for processing, otherwise
93 // returns a patch helper configured to uncompress and patch.
94 scoped_ptr
<installer::ArchivePatchHelper
> CreateChromeArchiveHelper(
95 const base::FilePath
& setup_exe
,
96 const base::CommandLine
& command_line
,
97 const installer::InstallerState
& installer_state
,
98 const base::FilePath
& working_directory
) {
99 // A compressed archive is ordinarily given on the command line by the mini
100 // installer. If one was not given, look for chrome.packed.7z next to the
102 base::FilePath
compressed_archive(
103 command_line
.GetSwitchValuePath(installer::switches::kInstallArchive
));
104 bool compressed_archive_specified
= !compressed_archive
.empty();
105 if (!compressed_archive_specified
) {
106 compressed_archive
= setup_exe
.DirName().Append(
107 installer::kChromeCompressedArchive
);
110 // Fail if no compressed archive is found.
111 if (!base::PathExists(compressed_archive
)) {
112 if (compressed_archive_specified
) {
113 LOG(ERROR
) << installer::switches::kInstallArchive
<< "="
114 << compressed_archive
.value() << " not found.";
116 return scoped_ptr
<installer::ArchivePatchHelper
>();
119 // chrome.7z is either extracted directly from the compressed archive into the
120 // working dir or is the target of patching in the working dir.
121 base::FilePath
target(working_directory
.Append(installer::kChromeArchive
));
122 DCHECK(!base::PathExists(target
));
124 // Specify an empty path for the patch source since it isn't yet known that
125 // one is needed. It will be supplied in UncompressAndPatchChromeArchive if it
127 return scoped_ptr
<installer::ArchivePatchHelper
>(
128 new installer::ArchivePatchHelper(working_directory
,
134 // Workhorse for producing an uncompressed archive (chrome.7z) given a
135 // chrome.packed.7z containing either a patch file based on the version of
136 // chrome being updated or the full uncompressed archive. Returns true on
137 // success, in which case |archive_type| is populated based on what was found.
138 // Returns false on failure, in which case |install_status| contains the error
139 // code and the result is written to the registry (via WriteInstallerResult).
140 bool UncompressAndPatchChromeArchive(
141 const installer::InstallationState
& original_state
,
142 const installer::InstallerState
& installer_state
,
143 installer::ArchivePatchHelper
* archive_helper
,
144 installer::ArchiveType
* archive_type
,
145 installer::InstallStatus
* install_status
,
146 const base::Version
& previous_version
) {
147 installer_state
.UpdateStage(installer::UNCOMPRESSING
);
148 if (!archive_helper
->Uncompress(NULL
)) {
149 *install_status
= installer::UNCOMPRESSION_FAILED
;
150 installer_state
.WriteInstallerResult(*install_status
,
151 IDS_INSTALL_UNCOMPRESSION_FAILED_BASE
,
156 // Short-circuit if uncompression produced the uncompressed archive rather
157 // than a patch file.
158 if (base::PathExists(archive_helper
->target())) {
159 *archive_type
= installer::FULL_ARCHIVE_TYPE
;
163 // Find the installed version's archive to serve as the source for patching.
164 base::FilePath
patch_source(installer::FindArchiveToPatch(original_state
,
167 if (patch_source
.empty()) {
168 LOG(ERROR
) << "Failed to find archive to patch.";
169 *install_status
= installer::DIFF_PATCH_SOURCE_MISSING
;
170 installer_state
.WriteInstallerResult(*install_status
,
171 IDS_INSTALL_UNCOMPRESSION_FAILED_BASE
,
175 archive_helper
->set_patch_source(patch_source
);
177 // Try courgette first. Failing that, try bspatch.
178 installer_state
.UpdateStage(installer::ENSEMBLE_PATCHING
);
179 if (!archive_helper
->EnsemblePatch()) {
180 installer_state
.UpdateStage(installer::BINARY_PATCHING
);
181 if (!archive_helper
->BinaryPatch()) {
182 *install_status
= installer::APPLY_DIFF_PATCH_FAILED
;
183 installer_state
.WriteInstallerResult(
184 *install_status
, IDS_INSTALL_UNCOMPRESSION_FAILED_BASE
, NULL
);
189 *archive_type
= installer::INCREMENTAL_ARCHIVE_TYPE
;
193 // In multi-install, adds all products to |installer_state| that are
194 // multi-installed and must be updated along with the products already present
195 // in |installer_state|.
196 void AddExistingMultiInstalls(const InstallationState
& original_state
,
197 InstallerState
* installer_state
) {
198 if (installer_state
->is_multi_install()) {
199 for (size_t i
= 0; i
< BrowserDistribution::NUM_TYPES
; ++i
) {
200 BrowserDistribution::Type type
=
201 static_cast<BrowserDistribution::Type
>(i
);
203 if (!installer_state
->FindProduct(type
)) {
204 const ProductState
* state
=
205 original_state
.GetProductState(installer_state
->system_install(),
207 if ((state
!= NULL
) && state
->is_multi_install()) {
208 installer_state
->AddProductFromState(type
, *state
);
209 VLOG(1) << "Product already installed and must be included: "
210 << BrowserDistribution::GetSpecificDistribution(type
)->
218 // This function is called when --rename-chrome-exe option is specified on
219 // setup.exe command line. This function assumes an in-use update has happened
220 // for Chrome so there should be a file called new_chrome.exe on the file
221 // system and a key called 'opv' in the registry. This function will move
222 // new_chrome.exe to chrome.exe and delete 'opv' key in one atomic operation.
223 // This function also deletes elevation policies associated with the old version
225 installer::InstallStatus
RenameChromeExecutables(
226 const InstallationState
& original_state
,
227 InstallerState
* installer_state
) {
228 // See what products are already installed in multi mode. When we do the
229 // rename for multi installs, we must update all installations since they
230 // share the binaries.
231 AddExistingMultiInstalls(original_state
, installer_state
);
232 const base::FilePath
&target_path
= installer_state
->target_path();
233 base::FilePath
chrome_exe(target_path
.Append(installer::kChromeExe
));
234 base::FilePath
chrome_new_exe(target_path
.Append(installer::kChromeNewExe
));
235 base::FilePath
chrome_old_exe(target_path
.Append(installer::kChromeOldExe
));
237 // Create a temporary backup directory on the same volume as chrome.exe so
238 // that moving in-use files doesn't lead to trouble.
239 installer::SelfCleaningTempDir temp_path
;
240 if (!temp_path
.Initialize(target_path
.DirName(),
241 installer::kInstallTempDir
)) {
242 PLOG(ERROR
) << "Failed to create Temp directory "
243 << target_path
.DirName()
244 .Append(installer::kInstallTempDir
).value();
245 return installer::RENAME_FAILED
;
247 scoped_ptr
<WorkItemList
> install_list(WorkItem::CreateWorkItemList());
248 // Move chrome.exe to old_chrome.exe, then move new_chrome.exe to chrome.exe.
249 install_list
->AddMoveTreeWorkItem(chrome_exe
.value(),
250 chrome_old_exe
.value(),
251 temp_path
.path().value(),
252 WorkItem::ALWAYS_MOVE
);
253 install_list
->AddMoveTreeWorkItem(chrome_new_exe
.value(),
255 temp_path
.path().value(),
256 WorkItem::ALWAYS_MOVE
);
257 install_list
->AddDeleteTreeWorkItem(chrome_new_exe
, temp_path
.path());
258 // old_chrome.exe is still in use in most cases, so ignore failures here.
259 install_list
->AddDeleteTreeWorkItem(chrome_old_exe
, temp_path
.path())->
260 set_ignore_failure(true);
262 // Add work items to delete the "opv", "cpv", and "cmd" values from all
263 // products we're operating on (which including the multi-install binaries).
264 const Products
& products
= installer_state
->products();
265 HKEY reg_root
= installer_state
->root_key();
266 base::string16 version_key
;
267 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
269 version_key
= (*it
)->distribution()->GetVersionKey();
270 install_list
->AddDeleteRegValueWorkItem(reg_root
,
273 google_update::kRegOldVersionField
);
274 install_list
->AddDeleteRegValueWorkItem(
278 google_update::kRegCriticalVersionField
);
279 install_list
->AddDeleteRegValueWorkItem(reg_root
,
282 google_update::kRegRenameCmdField
);
284 installer::InstallStatus ret
= installer::RENAME_SUCCESSFUL
;
285 if (!install_list
->Do()) {
286 LOG(ERROR
) << "Renaming of executables failed. Rolling back any changes.";
287 install_list
->Rollback();
288 ret
= installer::RENAME_FAILED
;
290 // temp_path's dtor will take care of deleting or scheduling itself for
291 // deletion at reboot when this scope closes.
292 VLOG(1) << "Deleting temporary directory " << temp_path
.path().value();
297 // If only the binaries are being updated, fail.
298 // If any product is being installed in single-mode that already exists in
300 bool CheckMultiInstallConditions(const InstallationState
& original_state
,
301 InstallerState
* installer_state
,
302 installer::InstallStatus
* status
) {
303 const Products
& products
= installer_state
->products();
304 DCHECK(products
.size());
306 const bool system_level
= installer_state
->system_install();
308 if (installer_state
->is_multi_install()) {
309 const Product
* chrome
=
310 installer_state
->FindProduct(BrowserDistribution::CHROME_BROWSER
);
311 const Product
* binaries
=
312 installer_state
->FindProduct(BrowserDistribution::CHROME_BINARIES
);
313 const ProductState
* chrome_state
=
314 original_state
.GetProductState(system_level
,
315 BrowserDistribution::CHROME_BROWSER
);
318 if (products
.size() == 1) {
319 // There are no products aside from the binaries, so there is no update
320 // to be applied. This can happen after multi-install Chrome Frame is
321 // migrated to single-install. This is treated as an update failure
322 // unless the binaries are not in-use, in which case they will be
323 // uninstalled and success will be reported (see handling in wWinMain).
324 VLOG(1) << "No products to be updated.";
325 *status
= installer::UNUSED_BINARIES
;
326 installer_state
->WriteInstallerResult(*status
, 0, NULL
);
330 // This will only be hit if --multi-install is given with no products.
334 if (!chrome
&& chrome_state
) {
335 // A product other than Chrome is being installed in multi-install mode,
336 // and Chrome is already present. Add Chrome to the set of products
337 // (making it multi-install in the process) so that it is updated, too.
338 scoped_ptr
<Product
> multi_chrome(new Product(
339 BrowserDistribution::GetSpecificDistribution(
340 BrowserDistribution::CHROME_BROWSER
)));
341 multi_chrome
->SetOption(installer::kOptionMultiInstall
, true);
342 chrome
= installer_state
->AddProduct(&multi_chrome
);
343 VLOG(1) << "Upgrading existing Chrome browser in multi-install mode.";
345 } // else migrate multi-install Chrome to single-install.
350 // Checks for compatibility between the current state of the system and the
351 // desired operation. Also applies policy that mutates the desired operation;
352 // specifically, the |installer_state| object.
353 // Also blocks simultaneous user-level and system-level installs. In the case
354 // of trying to install user-level Chrome when system-level exists, the
355 // existing system-level Chrome is launched.
356 // When the pre-install conditions are not satisfied, the result is written to
357 // the registry (via WriteInstallerResult), |status| is set appropriately, and
358 // false is returned.
359 bool CheckPreInstallConditions(const InstallationState
& original_state
,
360 InstallerState
* installer_state
,
361 installer::InstallStatus
* status
) {
362 // See what products are already installed in multi mode. When we do multi
363 // installs, we must upgrade all installations since they share the binaries.
364 AddExistingMultiInstalls(original_state
, installer_state
);
366 if (!CheckMultiInstallConditions(original_state
, installer_state
, status
)) {
367 DCHECK_NE(*status
, installer::UNKNOWN_STATUS
);
371 const Products
& products
= installer_state
->products();
372 if (products
.empty()) {
373 // We haven't been given any products on which to operate.
375 << "Not given any products to install and no products found to update.";
376 *status
= installer::CHROME_NOT_INSTALLED
;
377 installer_state
->WriteInstallerResult(*status
,
378 IDS_INSTALL_NO_PRODUCTS_TO_UPDATE_BASE
, NULL
);
382 if (!installer_state
->system_install()) {
383 // This is a user-level installation. Make sure that we are not installing
384 // on top of an existing system-level installation.
385 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
387 const Product
& product
= **it
;
388 BrowserDistribution
* browser_dist
= product
.distribution();
390 // Skip over the binaries, as it's okay for them to be at both levels
391 // for different products.
392 if (browser_dist
->GetType() == BrowserDistribution::CHROME_BINARIES
)
395 const ProductState
* user_level_product_state
=
396 original_state
.GetProductState(false, browser_dist
->GetType());
397 const ProductState
* system_level_product_state
=
398 original_state
.GetProductState(true, browser_dist
->GetType());
400 // Allow upgrades to proceed so that out-of-date versions are not left
402 if (user_level_product_state
)
405 // This is a new user-level install...
407 if (system_level_product_state
) {
408 // ... and the product already exists at system-level.
409 LOG(ERROR
) << "Already installed version "
410 << system_level_product_state
->version().GetString()
411 << " at system-level conflicts with this one at user-level.";
412 if (product
.is_chrome()) {
413 // Instruct Google Update to launch the existing system-level Chrome.
414 // There should be no error dialog.
415 base::FilePath
install_path(installer::GetChromeInstallPath(
418 if (install_path
.empty()) {
419 // Give up if we failed to construct the install path.
420 *status
= installer::OS_ERROR
;
421 installer_state
->WriteInstallerResult(*status
,
422 IDS_INSTALL_OS_ERROR_BASE
,
425 *status
= installer::EXISTING_VERSION_LAUNCHED
;
426 base::FilePath chrome_exe
=
427 install_path
.Append(installer::kChromeExe
);
428 base::CommandLine
cmd(chrome_exe
);
429 cmd
.AppendSwitch(switches::kForceFirstRun
);
430 installer_state
->WriteInstallerResult(*status
, 0, NULL
);
431 VLOG(1) << "Launching existing system-level chrome instead.";
432 base::LaunchProcess(cmd
, base::LaunchOptions());
435 // It's no longer possible for |product| to be anything other than
447 // Initializes |temp_path| to "Temp" within the target directory, and
448 // |unpack_path| to a random directory beginning with "source" within
449 // |temp_path|. Returns false on error.
450 bool CreateTemporaryAndUnpackDirectories(
451 const InstallerState
& installer_state
,
452 installer::SelfCleaningTempDir
* temp_path
,
453 base::FilePath
* unpack_path
) {
454 DCHECK(temp_path
&& unpack_path
);
456 if (!temp_path
->Initialize(installer_state
.target_path().DirName(),
457 installer::kInstallTempDir
)) {
458 PLOG(ERROR
) << "Could not create temporary path.";
461 VLOG(1) << "Created path " << temp_path
->path().value();
463 if (!base::CreateTemporaryDirInDir(temp_path
->path(),
464 installer::kInstallSourceDir
,
466 PLOG(ERROR
) << "Could not create temporary path for unpacked archive.";
473 installer::InstallStatus
UninstallProduct(
474 const InstallationState
& original_state
,
475 const InstallerState
& installer_state
,
476 const base::FilePath
& setup_exe
,
477 const base::CommandLine
& cmd_line
,
479 bool force_uninstall
,
480 const Product
& product
) {
481 const ProductState
* product_state
=
482 original_state
.GetProductState(installer_state
.system_install(),
483 product
.distribution()->GetType());
484 if (product_state
!= NULL
) {
485 VLOG(1) << "version on the system: "
486 << product_state
->version().GetString();
487 } else if (!force_uninstall
) {
488 LOG(ERROR
) << product
.distribution()->GetDisplayName()
489 << " not found for uninstall.";
490 return installer::CHROME_NOT_INSTALLED
;
493 return installer::UninstallProduct(
494 original_state
, installer_state
, setup_exe
, product
, remove_all
,
495 force_uninstall
, cmd_line
);
498 installer::InstallStatus
UninstallProducts(
499 const InstallationState
& original_state
,
500 const InstallerState
& installer_state
,
501 const base::FilePath
& setup_exe
,
502 const base::CommandLine
& cmd_line
) {
503 const Products
& products
= installer_state
.products();
505 // System-level Chrome will be launched via this command if its program gets
507 base::CommandLine
system_level_cmd(base::CommandLine::NO_PROGRAM
);
509 const Product
* chrome
=
510 installer_state
.FindProduct(BrowserDistribution::CHROME_BROWSER
);
512 // InstallerState::Initialize always puts Chrome first, and we rely on that
513 // here for this reason: if Chrome is in-use, the user will be prompted to
514 // confirm uninstallation. Upon cancel, we should not continue with the
516 DCHECK(products
[0]->is_chrome());
518 if (cmd_line
.HasSwitch(installer::switches::kSelfDestruct
) &&
519 !installer_state
.system_install()) {
520 BrowserDistribution
* dist
= chrome
->distribution();
521 const base::FilePath
system_exe_path(
522 installer::GetChromeInstallPath(true, dist
)
523 .Append(installer::kChromeExe
));
524 system_level_cmd
.SetProgram(system_exe_path
);
527 if (installer_state
.FindProduct(BrowserDistribution::CHROME_BINARIES
)) {
528 // Chrome Binaries should be last; if something else is cancelled, they
530 DCHECK(products
[products
.size() - 1]->is_chrome_binaries());
533 installer::InstallStatus install_status
= installer::UNINSTALL_SUCCESSFUL
;
534 installer::InstallStatus prod_status
= installer::UNKNOWN_STATUS
;
535 const bool force
= cmd_line
.HasSwitch(installer::switches::kForceUninstall
);
536 const bool remove_all
= !cmd_line
.HasSwitch(
537 installer::switches::kDoNotRemoveSharedItems
);
539 for (Products::const_iterator it
= products
.begin();
540 install_status
!= installer::UNINSTALL_CANCELLED
&& it
< products
.end();
542 prod_status
= UninstallProduct(original_state
, installer_state
, setup_exe
,
543 cmd_line
, remove_all
, force
, **it
);
544 if (prod_status
!= installer::UNINSTALL_SUCCESSFUL
)
545 install_status
= prod_status
;
548 installer::CleanUpInstallationDirectoryAfterUninstall(
549 original_state
, installer_state
, setup_exe
, &install_status
);
551 // The app and vendor dirs may now be empty. Make a last-ditch attempt to
553 installer::DeleteChromeDirectoriesIfEmpty(installer_state
.target_path());
555 // Trigger Active Setup if it was requested for the chrome product. This needs
556 // to be done after the UninstallProduct calls as some of them might
557 // otherwise terminate the process launched by TriggerActiveSetupCommand().
558 if (chrome
&& cmd_line
.HasSwitch(installer::switches::kTriggerActiveSetup
))
559 InstallUtil::TriggerActiveSetupCommand();
561 if (!system_level_cmd
.GetProgram().empty())
562 base::LaunchProcess(system_level_cmd
, base::LaunchOptions());
564 // Tell Google Update that an uninstall has taken place.
565 // Ignore the return value: success or failure of Google Update
566 // has no bearing on the success or failure of Chrome's uninstallation.
567 google_update::UninstallGoogleUpdate(installer_state
.system_install());
569 return install_status
;
572 // Uninstall the binaries if they are the only product present and they're not
574 void UninstallBinariesIfUnused(
575 const InstallationState
& original_state
,
576 const InstallerState
& installer_state
,
577 installer::InstallStatus
* install_status
) {
578 // Early exit if the binaries are still in use.
579 if (*install_status
!= installer::UNUSED_BINARIES
||
580 installer_state
.AreBinariesInUse(original_state
)) {
584 LOG(INFO
) << "Uninstalling unused binaries";
585 installer_state
.UpdateStage(installer::UNINSTALLING_BINARIES
);
587 // Simulate the uninstall as coming from the installed version.
588 const ProductState
* binaries_state
=
589 original_state
.GetProductState(installer_state
.system_install(),
590 BrowserDistribution::CHROME_BINARIES
);
591 const base::CommandLine
& uninstall_cmd(binaries_state
->uninstall_command());
592 MasterPreferences
uninstall_prefs(uninstall_cmd
);
593 InstallerState uninstall_state
;
594 uninstall_state
.Initialize(uninstall_cmd
, uninstall_prefs
, original_state
);
596 *install_status
= UninstallProducts(original_state
, uninstall_state
,
597 uninstall_cmd
.GetProgram(),
600 // Report that the binaries were uninstalled if they were. This translates
601 // into a successful install return code.
602 if (IsUninstallSuccess(*install_status
)) {
603 *install_status
= installer::UNUSED_BINARIES_UNINSTALLED
;
604 installer_state
.WriteInstallerResult(*install_status
, 0, NULL
);
608 // This function is a short-term repair for the damage documented in
609 // http://crbug.com/456602. Briefly: canaries from 42.0.2293.0 through
610 // 42.0.2302.0 (inclusive) contained a bug that broke normal Chrome installed at
611 // user-level. This function detects the broken state during a canary update and
612 // repairs it by calling on the existing Chrome's installer to fix itself.
613 // TODO(grt): Remove this once the majority of impacted canary clients have
615 void RepairChromeIfBroken(const InstallationState
& original_state
,
616 const InstallerState
& installer_state
) {
617 #if !defined(GOOGLE_CHROME_BUILD)
618 // Chromium does not support SxS installation, so there is no work to be done.
620 #else // GOOGLE_CHROME_BUILD
621 // Nothing to do if not a per-user SxS install/update.
622 if (!InstallUtil::IsChromeSxSProcess() ||
623 installer_state
.system_install() ||
624 installer_state
.is_multi_install()) {
628 // When running a side-by-side install, BrowserDistribution provides no way
629 // to create or access a GoogleChromeDistribution (by design).
630 static const base::char16 kChromeGuid
[] =
631 L
"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
632 static const base::char16 kChromeBinariesGuid
[] =
633 L
"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
635 UpdatingAppRegistrationData
chrome_reg_data(kChromeGuid
);
636 UpdatingAppRegistrationData
binaries_reg_data(kChromeBinariesGuid
);
638 // Nothing to do if the binaries are installed.
639 base::win::RegKey key
;
640 base::string16 version_str
;
641 if (key
.Open(HKEY_CURRENT_USER
,
642 binaries_reg_data
.GetVersionKey().c_str(),
643 KEY_QUERY_VALUE
| KEY_WOW64_32KEY
) == ERROR_SUCCESS
&&
644 key
.ReadValue(google_update::kRegVersionField
,
645 &version_str
) == ERROR_SUCCESS
) {
649 // Nothing to do if Chrome is not installed.
650 if (key
.Open(HKEY_CURRENT_USER
,
651 chrome_reg_data
.GetVersionKey().c_str(),
652 KEY_QUERY_VALUE
| KEY_WOW64_32KEY
) != ERROR_SUCCESS
||
653 key
.ReadValue(google_update::kRegVersionField
,
654 &version_str
) != ERROR_SUCCESS
) {
658 // Nothing to do if Chrome is not multi-install.
659 base::string16 setup_args
;
660 if (key
.Open(HKEY_CURRENT_USER
,
661 chrome_reg_data
.GetStateKey().c_str(),
662 KEY_QUERY_VALUE
| KEY_WOW64_32KEY
) != ERROR_SUCCESS
) {
663 LOG(ERROR
) << "RepairChrome: Failed to open Chrome's ClientState key.";
666 if (key
.ReadValue(installer::kUninstallArgumentsField
,
667 &setup_args
) != ERROR_SUCCESS
) {
668 LOG(ERROR
) << "RepairChrome: Failed to read Chrome's UninstallArguments.";
671 if (setup_args
.find(base::UTF8ToUTF16(installer::switches::kMultiInstall
)) ==
672 base::string16::npos
) {
673 LOG(INFO
) << "RepairChrome: Not repairing single-install Chrome.";
677 // Generate a command line to run Chrome's installer.
678 base::string16 setup_path
;
679 if (key
.ReadValue(installer::kUninstallStringField
,
680 &setup_path
) != ERROR_SUCCESS
) {
681 LOG(ERROR
) << "RepairChrome: Failed to read Chrome's UninstallString.";
685 // Replace --uninstall with --do-not-launch-chrome to cause chrome to
687 base::ReplaceFirstSubstringAfterOffset(
688 &setup_args
, 0, base::UTF8ToUTF16(installer::switches::kUninstall
),
689 base::UTF8ToUTF16(installer::switches::kDoNotLaunchChrome
));
690 base::CommandLine
setup_command(base::CommandLine::NO_PROGRAM
);
691 InstallUtil::ComposeCommandLine(setup_path
, setup_args
, &setup_command
);
693 // Run Chrome's installer so that it repairs itself. Break away from any job
694 // in which this operation is running so that Google Update doesn't wait
695 // around for the repair. Retry once without the attempt to break away in case
696 // this process doesn't have JOB_OBJECT_LIMIT_BREAKAWAY_OK.
697 base::LaunchOptions launch_options
;
698 launch_options
.force_breakaway_from_job_
= true;
700 if (base::LaunchProcess(setup_command
, launch_options
).IsValid()) {
701 LOG(INFO
) << "RepairChrome: Launched repair command \""
702 << setup_command
.GetCommandLineString() << "\"";
705 PLOG(ERROR
) << "RepairChrome: Failed launching repair command \""
706 << setup_command
.GetCommandLineString() << "\"";
707 if (launch_options
.force_breakaway_from_job_
) {
708 LOG(ERROR
) << "RepairChrome: Will retry without breakaway.";
709 launch_options
.force_breakaway_from_job_
= false;
715 #endif // GOOGLE_CHROME_BUILD
718 installer::InstallStatus
InstallProducts(
719 const InstallationState
& original_state
,
720 const base::FilePath
& setup_exe
,
721 const base::CommandLine
& cmd_line
,
722 const MasterPreferences
& prefs
,
723 InstallerState
* installer_state
,
724 base::FilePath
* installer_directory
) {
725 DCHECK(installer_state
);
726 const bool system_install
= installer_state
->system_install();
727 installer::InstallStatus install_status
= installer::UNKNOWN_STATUS
;
728 installer::ArchiveType archive_type
= installer::UNKNOWN_ARCHIVE_TYPE
;
729 bool delegated_to_existing
= false;
730 installer_state
->UpdateStage(installer::PRECONDITIONS
);
731 // The stage provides more fine-grained information than -multifail, so remove
732 // the -multifail suffix from the Google Update "ap" value.
733 BrowserDistribution::GetSpecificDistribution(installer_state
->state_type())->
734 UpdateInstallStatus(system_install
, archive_type
, install_status
);
735 if (CheckPreInstallConditions(original_state
, installer_state
,
737 VLOG(1) << "Installing to " << installer_state
->target_path().value();
738 install_status
= InstallProductsHelper(
739 original_state
, setup_exe
, cmd_line
, prefs
, *installer_state
,
740 installer_directory
, &archive_type
, &delegated_to_existing
);
742 // CheckPreInstallConditions must set the status on failure.
743 DCHECK_NE(install_status
, installer::UNKNOWN_STATUS
);
746 // Delete the master preferences file if present. Note that we do not care
747 // about rollback here and we schedule for deletion on reboot if the delete
748 // fails. As such, we do not use DeleteTreeWorkItem.
749 if (cmd_line
.HasSwitch(installer::switches::kInstallerData
)) {
750 base::FilePath
prefs_path(cmd_line
.GetSwitchValuePath(
751 installer::switches::kInstallerData
));
752 if (!base::DeleteFile(prefs_path
, false)) {
753 LOG(ERROR
) << "Failed deleting master preferences file "
754 << prefs_path
.value()
755 << ", scheduling for deletion after reboot.";
756 ScheduleFileSystemEntityForDeletion(prefs_path
);
760 // Early exit if this setup.exe delegated to another, since that one would
761 // have taken care of UpdateInstallStatus and UpdateStage.
762 if (delegated_to_existing
)
763 return install_status
;
765 const Products
& products
= installer_state
->products();
766 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
768 (*it
)->distribution()->UpdateInstallStatus(
769 system_install
, archive_type
, install_status
);
772 UninstallBinariesIfUnused(original_state
, *installer_state
, &install_status
);
774 RepairChromeIfBroken(original_state
, *installer_state
);
776 installer_state
->UpdateStage(installer::NO_STAGE
);
777 return install_status
;
780 installer::InstallStatus
ShowEULADialog(const base::string16
& inner_frame
) {
781 VLOG(1) << "About to show EULA";
782 base::string16 eula_path
= installer::GetLocalizedEulaResource();
783 if (eula_path
.empty()) {
784 LOG(ERROR
) << "No EULA path available";
785 return installer::EULA_REJECTED
;
787 // Newer versions of the caller pass an inner frame parameter that must
788 // be given to the html page being launched.
789 installer::EulaHTMLDialog
dlg(eula_path
, inner_frame
);
790 installer::EulaHTMLDialog::Outcome outcome
= dlg
.ShowModal();
791 if (installer::EulaHTMLDialog::REJECTED
== outcome
) {
792 LOG(ERROR
) << "EULA rejected or EULA failure";
793 return installer::EULA_REJECTED
;
795 if (installer::EulaHTMLDialog::ACCEPTED_OPT_IN
== outcome
) {
796 VLOG(1) << "EULA accepted (opt-in)";
797 return installer::EULA_ACCEPTED_OPT_IN
;
799 VLOG(1) << "EULA accepted (no opt-in)";
800 return installer::EULA_ACCEPTED
;
803 // Creates the sentinel indicating that the EULA was required and has been
805 bool CreateEULASentinel(BrowserDistribution
* dist
) {
806 base::FilePath eula_sentinel
;
807 if (!InstallUtil::GetEULASentinelFilePath(&eula_sentinel
))
810 return (base::CreateDirectory(eula_sentinel
.DirName()) &&
811 base::WriteFile(eula_sentinel
, "", 0) != -1);
814 void ActivateMetroChrome() {
815 // Check to see if we're per-user or not. Need to do this since we may
816 // not have been invoked with --system-level even for a machine install.
817 base::FilePath exe_path
;
818 PathService::Get(base::FILE_EXE
, &exe_path
);
819 bool is_per_user_install
= InstallUtil::IsPerUserInstall(exe_path
);
821 base::string16 app_model_id
= ShellUtil::GetBrowserModelId(
822 BrowserDistribution::GetDistribution(), is_per_user_install
);
824 base::win::ScopedComPtr
<IApplicationActivationManager
> activator
;
825 HRESULT hr
= activator
.CreateInstance(CLSID_ApplicationActivationManager
);
828 hr
= activator
->ActivateApplication(
829 app_model_id
.c_str(), L
"open", AO_NONE
, &pid
);
832 LOG_IF(ERROR
, FAILED(hr
)) << "Tried and failed to launch Metro Chrome. "
833 << "hr=" << std::hex
<< hr
;
836 installer::InstallStatus
RegisterDevChrome(
837 const InstallationState
& original_state
,
838 const InstallerState
& installer_state
,
839 const base::FilePath
& setup_exe
,
840 const base::CommandLine
& cmd_line
) {
841 BrowserDistribution
* chrome_dist
=
842 BrowserDistribution::GetSpecificDistribution(
843 BrowserDistribution::CHROME_BROWSER
);
845 // Only proceed with registering a dev chrome if no real Chrome installation
846 // of the same distribution are present on this system.
847 const ProductState
* existing_chrome
=
848 original_state
.GetProductState(false,
849 BrowserDistribution::CHROME_BROWSER
);
850 if (!existing_chrome
) {
852 original_state
.GetProductState(true, BrowserDistribution::CHROME_BROWSER
);
854 if (existing_chrome
) {
855 static const wchar_t kPleaseUninstallYourChromeMessage
[] =
856 L
"You already have a full-installation (non-dev) of %1ls, please "
857 L
"uninstall it first using Add/Remove Programs in the control panel.";
858 base::string16
name(chrome_dist
->GetDisplayName());
859 base::string16
message(
860 base::StringPrintf(kPleaseUninstallYourChromeMessage
, name
.c_str()));
862 LOG(ERROR
) << "Aborting operation: another installation of " << name
863 << " was found, as a last resort (if the product is not present "
864 "in Add/Remove Programs), try executing: "
865 << existing_chrome
->uninstall_command().GetCommandLineString();
866 MessageBox(NULL
, message
.c_str(), NULL
, MB_ICONERROR
);
867 return installer::INSTALL_FAILED
;
870 base::FilePath
chrome_exe(
871 cmd_line
.GetSwitchValuePath(installer::switches::kRegisterDevChrome
));
872 if (chrome_exe
.empty())
873 chrome_exe
= setup_exe
.DirName().Append(installer::kChromeExe
);
874 if (!chrome_exe
.IsAbsolute())
875 chrome_exe
= base::MakeAbsoluteFilePath(chrome_exe
);
877 installer::InstallStatus status
= installer::FIRST_INSTALL_SUCCESS
;
878 if (base::PathExists(chrome_exe
)) {
879 Product
chrome(chrome_dist
);
881 // Create the Start menu shortcut and pin it to the Win7+ taskbar and Win10+
883 ShellUtil::ShortcutProperties
shortcut_properties(ShellUtil::CURRENT_USER
);
884 chrome
.AddDefaultShortcutProperties(chrome_exe
, &shortcut_properties
);
885 if (InstallUtil::ShouldInstallMetroProperties())
886 shortcut_properties
.set_dual_mode(true);
887 shortcut_properties
.set_pin_to_taskbar(true);
888 shortcut_properties
.set_pin_to_start(true);
889 ShellUtil::CreateOrUpdateShortcut(
890 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
, chrome_dist
,
891 shortcut_properties
, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
);
893 // Register Chrome at user-level and make it default.
894 scoped_ptr
<WorkItemList
> delegate_execute_list(
895 WorkItem::CreateWorkItemList());
896 installer::AddDelegateExecuteWorkItems(
897 installer_state
, chrome_exe
.DirName(), Version(), chrome
,
898 delegate_execute_list
.get());
899 delegate_execute_list
->Do();
900 if (ShellUtil::CanMakeChromeDefaultUnattended()) {
901 ShellUtil::MakeChromeDefault(chrome_dist
, ShellUtil::CURRENT_USER
,
904 ShellUtil::ShowMakeChromeDefaultSystemUI(chrome_dist
, chrome_exe
);
907 LOG(ERROR
) << "Path not found: " << chrome_exe
.value();
908 status
= installer::INSTALL_FAILED
;
913 // This method processes any command line options that make setup.exe do
914 // various tasks other than installation (renaming chrome.exe, showing eula
915 // among others). This function returns true if any such command line option
916 // has been found and processed (so setup.exe should exit at that point).
917 bool HandleNonInstallCmdLineOptions(const InstallationState
& original_state
,
918 const base::FilePath
& setup_exe
,
919 const base::CommandLine
& cmd_line
,
920 InstallerState
* installer_state
,
922 // TODO(gab): Add a local |status| variable which each block below sets;
923 // only determine the |exit_code| from |status| at the end (this will allow
924 // this method to validate that
925 // (!handled || status != installer::UNKNOWN_STATUS)).
927 // TODO(tommi): Split these checks up into functions and use a data driven
928 // map of switch->function.
929 if (cmd_line
.HasSwitch(installer::switches::kUpdateSetupExe
)) {
930 installer::InstallStatus status
= installer::SETUP_PATCH_FAILED
;
931 // If --update-setup-exe command line option is given, we apply the given
932 // patch to current exe, and store the resulting binary in the path
933 // specified by --new-setup-exe. But we need to first unpack the file
934 // given in --update-setup-exe.
935 base::ScopedTempDir temp_path
;
936 if (!temp_path
.CreateUniqueTempDir()) {
937 PLOG(ERROR
) << "Could not create temporary path.";
939 base::FilePath
compressed_archive(cmd_line
.GetSwitchValuePath(
940 installer::switches::kUpdateSetupExe
));
941 VLOG(1) << "Opening archive " << compressed_archive
.value();
942 if (installer::ArchivePatchHelper::UncompressAndPatch(
946 cmd_line
.GetSwitchValuePath(installer::switches::kNewSetupExe
))) {
947 status
= installer::NEW_VERSION_UPDATED
;
949 if (!temp_path
.Delete()) {
950 // PLOG would be nice, but Delete() doesn't leave a meaningful value in
951 // the Windows last-error code.
952 LOG(WARNING
) << "Scheduling temporary path " << temp_path
.path().value()
953 << " for deletion at reboot.";
954 ScheduleDirectoryForDeletion(temp_path
.path());
958 *exit_code
= InstallUtil::GetInstallReturnCode(status
);
960 LOG(WARNING
) << "setup.exe patching failed.";
961 installer_state
->WriteInstallerResult(
962 status
, IDS_SETUP_PATCH_FAILED_BASE
, NULL
);
964 // We will be exiting normally, so clear the stage indicator.
965 installer_state
->UpdateStage(installer::NO_STAGE
);
966 } else if (cmd_line
.HasSwitch(installer::switches::kShowEula
)) {
967 // Check if we need to show the EULA. If it is passed as a command line
968 // then the dialog is shown and regardless of the outcome setup exits here.
969 base::string16 inner_frame
=
970 cmd_line
.GetSwitchValueNative(installer::switches::kShowEula
);
971 *exit_code
= ShowEULADialog(inner_frame
);
973 if (installer::EULA_REJECTED
!= *exit_code
) {
974 if (GoogleUpdateSettings::SetEULAConsent(
975 original_state
, BrowserDistribution::GetDistribution(), true)) {
976 CreateEULASentinel(BrowserDistribution::GetDistribution());
978 // For a metro-originated launch, we now need to launch back into metro.
979 if (cmd_line
.HasSwitch(installer::switches::kShowEulaForMetro
))
980 ActivateMetroChrome();
982 } else if (cmd_line
.HasSwitch(installer::switches::kConfigureUserSettings
)) {
983 // NOTE: Should the work done here, on kConfigureUserSettings, change:
984 // kActiveSetupVersion in install_worker.cc needs to be increased for Active
985 // Setup to invoke this again for all users of this install.
986 const Product
* chrome_install
=
987 installer_state
->FindProduct(BrowserDistribution::CHROME_BROWSER
);
988 installer::InstallStatus status
= installer::INVALID_STATE_FOR_OPTION
;
989 if (chrome_install
&& installer_state
->system_install()) {
991 cmd_line
.HasSwitch(installer::switches::kForceConfigureUserSettings
);
992 installer::HandleActiveSetupForBrowser(installer_state
->target_path(),
993 *chrome_install
, force
);
994 status
= installer::INSTALL_REPAIRED
;
996 LOG(DFATAL
) << "chrome_install:" << chrome_install
997 << ", system_install:" << installer_state
->system_install();
999 *exit_code
= InstallUtil::GetInstallReturnCode(status
);
1000 } else if (cmd_line
.HasSwitch(installer::switches::kRegisterDevChrome
)) {
1001 installer::InstallStatus status
= RegisterDevChrome(
1002 original_state
, *installer_state
, setup_exe
, cmd_line
);
1003 *exit_code
= InstallUtil::GetInstallReturnCode(status
);
1004 } else if (cmd_line
.HasSwitch(installer::switches::kRegisterChromeBrowser
)) {
1005 installer::InstallStatus status
= installer::UNKNOWN_STATUS
;
1006 const Product
* chrome_install
=
1007 installer_state
->FindProduct(BrowserDistribution::CHROME_BROWSER
);
1008 if (chrome_install
) {
1009 // If --register-chrome-browser option is specified, register all
1010 // Chrome protocol/file associations, as well as register it as a valid
1011 // browser for Start Menu->Internet shortcut. This switch will also
1012 // register Chrome as a valid handler for a set of URL protocols that
1013 // Chrome may become the default handler for, either by the user marking
1014 // Chrome as the default browser, through the Windows Default Programs
1015 // control panel settings, or through website use of
1016 // registerProtocolHandler. These protocols are found in
1017 // ShellUtil::kPotentialProtocolAssociations.
1018 // The --register-url-protocol will additionally register Chrome as a
1019 // potential handler for the supplied protocol, and is used if a website
1020 // registers a handler for a protocol not found in
1021 // ShellUtil::kPotentialProtocolAssociations.
1022 // These options should only be used when setup.exe is launched with admin
1023 // rights. We do not make any user specific changes with this option.
1024 DCHECK(IsUserAnAdmin());
1025 base::FilePath
chrome_exe(cmd_line
.GetSwitchValuePath(
1026 installer::switches::kRegisterChromeBrowser
));
1027 base::string16 suffix
;
1028 if (cmd_line
.HasSwitch(
1029 installer::switches::kRegisterChromeBrowserSuffix
)) {
1030 suffix
= cmd_line
.GetSwitchValueNative(
1031 installer::switches::kRegisterChromeBrowserSuffix
);
1033 if (cmd_line
.HasSwitch(installer::switches::kRegisterURLProtocol
)) {
1034 base::string16 protocol
= cmd_line
.GetSwitchValueNative(
1035 installer::switches::kRegisterURLProtocol
);
1036 // ShellUtil::RegisterChromeForProtocol performs all registration
1037 // done by ShellUtil::RegisterChromeBrowser, as well as registering
1038 // with Windows as capable of handling the supplied protocol.
1039 if (ShellUtil::RegisterChromeForProtocol(
1040 chrome_install
->distribution(), chrome_exe
, suffix
, protocol
,
1042 status
= installer::IN_USE_UPDATED
;
1044 if (ShellUtil::RegisterChromeBrowser(chrome_install
->distribution(),
1045 chrome_exe
, suffix
, false))
1046 status
= installer::IN_USE_UPDATED
;
1049 LOG(DFATAL
) << "Can't register browser - Chrome distribution not found";
1051 *exit_code
= InstallUtil::GetInstallReturnCode(status
);
1052 } else if (cmd_line
.HasSwitch(installer::switches::kRenameChromeExe
)) {
1053 // If --rename-chrome-exe is specified, we want to rename the executables
1055 *exit_code
= RenameChromeExecutables(original_state
, installer_state
);
1056 } else if (cmd_line
.HasSwitch(
1057 installer::switches::kRemoveChromeRegistration
)) {
1058 // This is almost reverse of --register-chrome-browser option above.
1059 // Here we delete Chrome browser registration. This option should only
1060 // be used when setup.exe is launched with admin rights. We do not
1061 // make any user specific changes in this option.
1062 base::string16 suffix
;
1063 if (cmd_line
.HasSwitch(
1064 installer::switches::kRegisterChromeBrowserSuffix
)) {
1065 suffix
= cmd_line
.GetSwitchValueNative(
1066 installer::switches::kRegisterChromeBrowserSuffix
);
1068 installer::InstallStatus tmp
= installer::UNKNOWN_STATUS
;
1069 const Product
* chrome_install
=
1070 installer_state
->FindProduct(BrowserDistribution::CHROME_BROWSER
);
1071 DCHECK(chrome_install
);
1072 if (chrome_install
) {
1073 installer::DeleteChromeRegistrationKeys(*installer_state
,
1074 chrome_install
->distribution(), HKEY_LOCAL_MACHINE
, suffix
, &tmp
);
1077 } else if (cmd_line
.HasSwitch(installer::switches::kOnOsUpgrade
)) {
1078 const Product
* chrome_install
=
1079 installer_state
->FindProduct(BrowserDistribution::CHROME_BROWSER
);
1080 installer::InstallStatus status
= installer::INVALID_STATE_FOR_OPTION
;
1081 if (chrome_install
) {
1082 scoped_ptr
<FileVersionInfo
> version_info(
1083 FileVersionInfo::CreateFileVersionInfo(setup_exe
));
1084 const base::Version
installed_version(
1085 base::UTF16ToUTF8(version_info
->product_version()));
1086 if (installed_version
.IsValid()) {
1087 installer::HandleOsUpgradeForBrowser(*installer_state
, *chrome_install
,
1089 status
= installer::INSTALL_REPAIRED
;
1091 LOG(DFATAL
) << "Failed to extract product version from "
1092 << setup_exe
.value();
1095 LOG(DFATAL
) << "Chrome product not found.";
1097 *exit_code
= InstallUtil::GetInstallReturnCode(status
);
1098 } else if (cmd_line
.HasSwitch(installer::switches::kInactiveUserToast
)) {
1099 // Launch the inactive user toast experiment.
1101 base::StringToInt(cmd_line
.GetSwitchValueNative(
1102 installer::switches::kInactiveUserToast
), &flavor
);
1103 std::string experiment_group
=
1104 cmd_line
.GetSwitchValueASCII(installer::switches::kExperimentGroup
);
1105 DCHECK_NE(-1, flavor
);
1107 *exit_code
= installer::UNKNOWN_STATUS
;
1109 // This code is called (via setup.exe relaunch) only if a product is known
1110 // to run user experiments, so no check is required.
1111 const Products
& products
= installer_state
->products();
1112 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
1114 const Product
& product
= **it
;
1115 installer::InactiveUserToastExperiment(
1116 flavor
, base::ASCIIToUTF16(experiment_group
), product
,
1117 installer_state
->target_path());
1120 } else if (cmd_line
.HasSwitch(installer::switches::kSystemLevelToast
)) {
1121 const Products
& products
= installer_state
->products();
1122 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
1124 const Product
& product
= **it
;
1125 BrowserDistribution
* browser_dist
= product
.distribution();
1126 // We started as system-level and have been re-launched as user level
1127 // to continue with the toast experiment.
1128 Version installed_version
;
1129 InstallUtil::GetChromeVersion(browser_dist
, true, &installed_version
);
1130 if (!installed_version
.IsValid()) {
1131 LOG(ERROR
) << "No installation of "
1132 << browser_dist
->GetDisplayName()
1133 << " found for system-level toast.";
1135 product
.LaunchUserExperiment(
1136 setup_exe
, installer::REENTRY_SYS_UPDATE
, true);
1139 } else if (cmd_line
.HasSwitch(installer::switches::kPatch
)) {
1140 const std::string
patch_type_str(
1141 cmd_line
.GetSwitchValueASCII(installer::switches::kPatch
));
1142 const base::FilePath
input_file(
1143 cmd_line
.GetSwitchValuePath(installer::switches::kInputFile
));
1144 const base::FilePath
patch_file(
1145 cmd_line
.GetSwitchValuePath(installer::switches::kPatchFile
));
1146 const base::FilePath
output_file(
1147 cmd_line
.GetSwitchValuePath(installer::switches::kOutputFile
));
1149 if (patch_type_str
== installer::kCourgette
) {
1150 *exit_code
= installer::CourgettePatchFiles(input_file
,
1153 } else if (patch_type_str
== installer::kBsdiff
) {
1154 *exit_code
= installer::BsdiffPatchFiles(input_file
,
1158 *exit_code
= installer::PATCH_INVALID_ARGUMENTS
;
1160 } else if (cmd_line
.HasSwitch(installer::switches::kReenableAutoupdates
)) {
1161 // setup.exe has been asked to attempt to reenable updates for Chrome.
1162 bool updates_enabled
= GoogleUpdateSettings::ReenableAutoupdates();
1163 *exit_code
= updates_enabled
? installer::REENABLE_UPDATES_SUCCEEDED
:
1164 installer::REENABLE_UPDATES_FAILED
;
1172 // Returns the Custom information for the client identified by the exe path
1173 // passed in. This information is used for crash reporting.
1174 google_breakpad::CustomClientInfo
* GetCustomInfo(const wchar_t* exe_path
) {
1175 base::string16 product
;
1176 base::string16 version
;
1177 scoped_ptr
<FileVersionInfo
> version_info(
1178 FileVersionInfo::CreateFileVersionInfo(base::FilePath(exe_path
)));
1179 if (version_info
.get()) {
1180 version
= version_info
->product_version();
1181 product
= version_info
->product_short_name();
1184 if (version
.empty())
1185 version
= L
"0.1.0.0";
1187 if (product
.empty())
1188 product
= L
"Chrome Installer";
1190 static google_breakpad::CustomInfoEntry
ver_entry(L
"ver", version
.c_str());
1191 static google_breakpad::CustomInfoEntry
prod_entry(L
"prod", product
.c_str());
1192 static google_breakpad::CustomInfoEntry
plat_entry(L
"plat", L
"Win32");
1193 static google_breakpad::CustomInfoEntry
type_entry(L
"ptype",
1194 L
"Chrome Installer");
1195 static google_breakpad::CustomInfoEntry entries
[] = {
1196 ver_entry
, prod_entry
, plat_entry
, type_entry
};
1197 static google_breakpad::CustomClientInfo custom_info
= {
1198 entries
, arraysize(entries
) };
1199 return &custom_info
;
1202 // Initialize crash reporting for this process. This involves connecting to
1204 scoped_ptr
<google_breakpad::ExceptionHandler
> InitializeCrashReporting(
1205 bool system_install
) {
1206 // Only report crashes if the user allows it.
1207 if (!GoogleUpdateSettings::GetCollectStatsConsent())
1208 return scoped_ptr
<google_breakpad::ExceptionHandler
>();
1210 // Get the alternate dump directory. We use the temp path.
1211 base::FilePath temp_directory
;
1212 if (!base::GetTempDir(&temp_directory
) || temp_directory
.empty())
1213 return scoped_ptr
<google_breakpad::ExceptionHandler
>();
1215 wchar_t exe_path
[MAX_PATH
* 2] = {0};
1216 GetModuleFileName(NULL
, exe_path
, arraysize(exe_path
));
1218 // Build the pipe name. It can be either:
1219 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18"
1220 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>"
1221 base::string16 user_sid
= kSystemPrincipalSid
;
1223 if (!system_install
) {
1224 if (!base::win::GetUserSidString(&user_sid
)) {
1225 return scoped_ptr
<google_breakpad::ExceptionHandler
>();
1229 base::string16 pipe_name
= kGoogleUpdatePipeName
;
1230 pipe_name
+= user_sid
;
1233 // The protocol for connecting to the out-of-process Breakpad crash
1234 // reporter is different for x86-32 and x86-64: the message sizes
1235 // are different because the message struct contains a pointer. As
1236 // a result, there are two different named pipes to connect to. The
1237 // 64-bit one is distinguished with an "-x64" suffix.
1238 pipe_name
+= L
"-x64";
1241 return scoped_ptr
<google_breakpad::ExceptionHandler
>(
1242 new google_breakpad::ExceptionHandler(
1243 temp_directory
.value(), NULL
, NULL
, NULL
,
1244 google_breakpad::ExceptionHandler::HANDLER_ALL
, kLargerDumpType
,
1245 pipe_name
.c_str(), GetCustomInfo(exe_path
)));
1248 // Uninstalls multi-install Chrome Frame if the current operation is a
1249 // multi-install install or update. The operation is performed directly rather
1250 // than delegated to the existing install since there is no facility in older
1251 // versions of setup.exe to uninstall GCF without touching the binaries. The
1252 // binaries will be uninstalled during later processing if they are not in-use
1253 // (see UninstallBinariesIfUnused). |original_state| and |installer_state| are
1254 // updated to reflect the state of the world following the operation.
1255 void UninstallMultiChromeFrameIfPresent(const base::CommandLine
& cmd_line
,
1256 const MasterPreferences
& prefs
,
1257 InstallationState
* original_state
,
1258 InstallerState
* installer_state
) {
1259 // Early exit if not installing or updating.
1260 if (installer_state
->operation() == InstallerState::UNINSTALL
)
1263 // Early exit if Chrome Frame is not present as multi-install.
1264 const ProductState
* chrome_frame_state
=
1265 original_state
->GetProductState(installer_state
->system_install(),
1266 BrowserDistribution::CHROME_FRAME
);
1267 if (!chrome_frame_state
|| !chrome_frame_state
->is_multi_install())
1270 LOG(INFO
) << "Uninstalling multi-install Chrome Frame.";
1271 installer_state
->UpdateStage(installer::UNINSTALLING_CHROME_FRAME
);
1273 // Uninstall Chrome Frame without touching the multi-install binaries.
1274 // Simulate the uninstall as coming from the installed version.
1275 const base::CommandLine
& uninstall_cmd(
1276 chrome_frame_state
->uninstall_command());
1277 MasterPreferences
uninstall_prefs(uninstall_cmd
);
1278 InstallerState uninstall_state
;
1279 uninstall_state
.Initialize(uninstall_cmd
, uninstall_prefs
, *original_state
);
1280 // Post M32, uninstall_prefs and uninstall_state won't have Chrome Frame in
1281 // them since they've lost the power to do Chrome Frame installs.
1282 const Product
* chrome_frame_product
= uninstall_state
.AddProductFromState(
1283 BrowserDistribution::CHROME_FRAME
, *chrome_frame_state
);
1284 if (chrome_frame_product
) {
1285 // No shared state should be left behind.
1286 const bool remove_all
= true;
1287 // Don't accept no for an answer.
1288 const bool force_uninstall
= true;
1289 installer::InstallStatus uninstall_status
=
1290 installer::UninstallProduct(*original_state
, uninstall_state
,
1291 uninstall_cmd
.GetProgram(),
1292 *chrome_frame_product
, remove_all
,
1293 force_uninstall
, cmd_line
);
1295 VLOG(1) << "Uninstallation of Chrome Frame returned status "
1296 << uninstall_status
;
1298 LOG(ERROR
) << "Chrome Frame not found for uninstall.";
1301 // Refresh state for the continuation of the original install/update.
1302 original_state
->Initialize();
1303 installer_state
->Initialize(cmd_line
, prefs
, *original_state
);
1308 namespace installer
{
1310 InstallStatus
InstallProductsHelper(const InstallationState
& original_state
,
1311 const base::FilePath
& setup_exe
,
1312 const base::CommandLine
& cmd_line
,
1313 const MasterPreferences
& prefs
,
1314 const InstallerState
& installer_state
,
1315 base::FilePath
* installer_directory
,
1316 ArchiveType
* archive_type
,
1317 bool* delegated_to_existing
) {
1318 DCHECK(archive_type
);
1319 DCHECK(delegated_to_existing
);
1320 const bool system_install
= installer_state
.system_install();
1321 InstallStatus install_status
= UNKNOWN_STATUS
;
1323 // Drop to background processing mode if the process was started below the
1324 // normal process priority class.
1325 bool entered_background_mode
= AdjustProcessPriority();
1326 VLOG_IF(1, entered_background_mode
) << "Entered background processing mode.";
1328 // Create a temp folder where we will unpack Chrome archive. If it fails,
1329 // then we are doomed, so return immediately and no cleanup is required.
1330 SelfCleaningTempDir temp_path
;
1331 base::FilePath unpack_path
;
1332 if (!CreateTemporaryAndUnpackDirectories(installer_state
, &temp_path
,
1334 installer_state
.WriteInstallerResult(TEMP_DIR_FAILED
,
1335 IDS_INSTALL_TEMP_DIR_FAILED_BASE
,
1337 return TEMP_DIR_FAILED
;
1340 // Uncompress and optionally patch the archive if an uncompressed archive was
1341 // not specified on the command line and a compressed archive is found.
1342 *archive_type
= UNKNOWN_ARCHIVE_TYPE
;
1343 base::FilePath
uncompressed_archive(cmd_line
.GetSwitchValuePath(
1344 switches::kUncompressedArchive
));
1345 if (uncompressed_archive
.empty()) {
1346 base::Version previous_version
;
1347 if (cmd_line
.HasSwitch(installer::switches::kPreviousVersion
)) {
1348 previous_version
= base::Version(cmd_line
.GetSwitchValueASCII(
1349 installer::switches::kPreviousVersion
));
1352 scoped_ptr
<ArchivePatchHelper
> archive_helper(
1353 CreateChromeArchiveHelper(setup_exe
, cmd_line
, installer_state
,
1355 if (archive_helper
) {
1356 VLOG(1) << "Installing Chrome from compressed archive "
1357 << archive_helper
->compressed_archive().value();
1358 if (!UncompressAndPatchChromeArchive(original_state
,
1360 archive_helper
.get(),
1363 previous_version
)) {
1364 DCHECK_NE(install_status
, UNKNOWN_STATUS
);
1365 return install_status
;
1367 uncompressed_archive
= archive_helper
->target();
1368 DCHECK(!uncompressed_archive
.empty());
1372 // Check for an uncompressed archive alongside the current executable if one
1373 // was not given or generated.
1374 if (uncompressed_archive
.empty())
1375 uncompressed_archive
= setup_exe
.DirName().Append(kChromeArchive
);
1377 if (*archive_type
== UNKNOWN_ARCHIVE_TYPE
) {
1378 // An archive was not uncompressed or patched above.
1379 if (uncompressed_archive
.empty() ||
1380 !base::PathExists(uncompressed_archive
)) {
1381 LOG(ERROR
) << "Cannot install Chrome without an uncompressed archive.";
1382 installer_state
.WriteInstallerResult(
1383 INVALID_ARCHIVE
, IDS_INSTALL_INVALID_ARCHIVE_BASE
, NULL
);
1384 return INVALID_ARCHIVE
;
1386 *archive_type
= FULL_ARCHIVE_TYPE
;
1389 // Unpack the uncompressed archive.
1390 if (LzmaUtil::UnPackArchive(uncompressed_archive
.value(),
1391 unpack_path
.value(),
1393 installer_state
.WriteInstallerResult(
1395 IDS_INSTALL_UNCOMPRESSION_FAILED_BASE
,
1397 return UNPACKING_FAILED
;
1400 VLOG(1) << "unpacked to " << unpack_path
.value();
1401 base::FilePath
src_path(
1402 unpack_path
.Append(kInstallSourceChromeDir
));
1404 installer_version(GetMaxVersionFromArchiveDir(src_path
));
1405 if (!installer_version
.get()) {
1406 LOG(ERROR
) << "Did not find any valid version in installer.";
1407 install_status
= INVALID_ARCHIVE
;
1408 installer_state
.WriteInstallerResult(install_status
,
1409 IDS_INSTALL_INVALID_ARCHIVE_BASE
, NULL
);
1411 VLOG(1) << "version to install: " << installer_version
->GetString();
1412 bool proceed_with_installation
= true;
1414 if (installer_state
.operation() == InstallerState::MULTI_INSTALL
) {
1415 // This is a new install of a multi-install product. Rather than give up
1416 // in case a higher version of the binaries (including a single-install
1417 // of Chrome, which can safely be migrated to multi-install by way of
1418 // CheckMultiInstallConditions) is already installed, delegate to the
1419 // installed setup.exe to install the product at hand.
1420 base::FilePath existing_setup_exe
;
1421 if (GetExistingHigherInstaller(original_state
, system_install
,
1422 *installer_version
, &existing_setup_exe
)) {
1423 VLOG(1) << "Deferring to existing installer.";
1424 installer_state
.UpdateStage(DEFERRING_TO_HIGHER_VERSION
);
1425 if (DeferToExistingInstall(existing_setup_exe
, cmd_line
,
1426 installer_state
, temp_path
.path(),
1428 *delegated_to_existing
= true;
1429 return install_status
;
1434 uint32 higher_products
= 0;
1436 sizeof(higher_products
) * 8 > BrowserDistribution::NUM_TYPES
,
1437 too_many_distribution_types_
);
1438 const Products
& products
= installer_state
.products();
1439 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
1441 const Product
& product
= **it
;
1442 const ProductState
* product_state
=
1443 original_state
.GetProductState(system_install
,
1444 product
.distribution()->GetType());
1445 if (product_state
!= NULL
&&
1446 (product_state
->version().CompareTo(*installer_version
) > 0)) {
1447 LOG(ERROR
) << "Higher version of "
1448 << product
.distribution()->GetDisplayName()
1449 << " is already installed.";
1450 higher_products
|= (1 << product
.distribution()->GetType());
1454 if (higher_products
!= 0) {
1455 COMPILE_ASSERT(BrowserDistribution::NUM_TYPES
== 3,
1456 add_support_for_new_products_here_
);
1457 int message_id
= IDS_INSTALL_HIGHER_VERSION_BASE
;
1458 proceed_with_installation
= false;
1459 install_status
= HIGHER_VERSION_EXISTS
;
1460 installer_state
.WriteInstallerResult(install_status
, message_id
, NULL
);
1463 if (proceed_with_installation
) {
1464 base::FilePath
prefs_source_path(cmd_line
.GetSwitchValueNative(
1465 switches::kInstallerData
));
1466 install_status
= InstallOrUpdateProduct(
1467 original_state
, installer_state
, setup_exe
, uncompressed_archive
,
1468 temp_path
.path(), src_path
, prefs_source_path
, prefs
,
1469 *installer_version
);
1471 int install_msg_base
= IDS_INSTALL_FAILED_BASE
;
1472 base::FilePath chrome_exe
;
1473 base::string16 quoted_chrome_exe
;
1474 if (install_status
== SAME_VERSION_REPAIR_FAILED
) {
1475 install_msg_base
= IDS_SAME_VERSION_REPAIR_FAILED_BASE
;
1476 } else if (install_status
!= INSTALL_FAILED
) {
1477 if (installer_state
.target_path().empty()) {
1478 // If we failed to construct install path, it means the OS call to
1479 // get %ProgramFiles% or %AppData% failed. Report this as failure.
1480 install_msg_base
= IDS_INSTALL_OS_ERROR_BASE
;
1481 install_status
= OS_ERROR
;
1483 chrome_exe
= installer_state
.target_path().Append(kChromeExe
);
1484 quoted_chrome_exe
= L
"\"" + chrome_exe
.value() + L
"\"";
1485 install_msg_base
= 0;
1489 installer_state
.UpdateStage(FINISHING
);
1491 // Only do Chrome-specific stuff (like launching the browser) if
1492 // Chrome was specifically requested (rather than being upgraded as
1493 // part of a multi-install).
1494 const Product
* chrome_install
= prefs
.install_chrome() ?
1495 installer_state
.FindProduct(BrowserDistribution::CHROME_BROWSER
) :
1498 bool do_not_register_for_update_launch
= false;
1499 if (chrome_install
) {
1500 prefs
.GetBool(master_preferences::kDoNotRegisterForUpdateLaunch
,
1501 &do_not_register_for_update_launch
);
1503 do_not_register_for_update_launch
= true; // Never register.
1506 bool write_chrome_launch_string
=
1507 (!do_not_register_for_update_launch
&&
1508 install_status
!= IN_USE_UPDATED
);
1510 installer_state
.WriteInstallerResult(install_status
, install_msg_base
,
1511 write_chrome_launch_string
? "ed_chrome_exe
: NULL
);
1513 if (install_status
== FIRST_INSTALL_SUCCESS
) {
1514 VLOG(1) << "First install successful.";
1515 if (chrome_install
) {
1516 // We never want to launch Chrome in system level install mode.
1517 bool do_not_launch_chrome
= false;
1518 prefs
.GetBool(master_preferences::kDoNotLaunchChrome
,
1519 &do_not_launch_chrome
);
1520 if (!system_install
&& !do_not_launch_chrome
)
1521 chrome_install
->LaunchChrome(installer_state
.target_path());
1523 } else if ((install_status
== NEW_VERSION_UPDATED
) ||
1524 (install_status
== IN_USE_UPDATED
)) {
1525 const Product
* chrome
= installer_state
.FindProduct(
1526 BrowserDistribution::CHROME_BROWSER
);
1527 if (chrome
!= NULL
) {
1528 DCHECK_NE(chrome_exe
.value(), base::string16());
1529 RemoveChromeLegacyRegistryKeys(chrome
->distribution(), chrome_exe
);
1535 // There might be an experiment (for upgrade usually) that needs to happen.
1536 // An experiment's outcome can include chrome's uninstallation. If that is
1537 // the case we would not do that directly at this point but in another
1538 // instance of setup.exe
1540 // There is another way to reach this same function if this is a system
1541 // level install. See HandleNonInstallCmdLineOptions().
1543 // If installation failed, use the path to the currently running setup.
1544 // If installation succeeded, use the path to setup in the installer dir.
1545 base::FilePath
setup_path(setup_exe
);
1546 if (InstallUtil::GetInstallReturnCode(install_status
) == 0) {
1547 setup_path
= installer_state
.GetInstallerDirectory(*installer_version
)
1548 .Append(setup_path
.BaseName());
1550 const Products
& products
= installer_state
.products();
1551 for (Products::const_iterator it
= products
.begin(); it
< products
.end();
1553 const Product
& product
= **it
;
1554 product
.LaunchUserExperiment(setup_path
, install_status
, system_install
);
1558 // If installation completed successfully, return the path to the directory
1559 // containing the newly installed setup.exe and uncompressed archive if the
1560 // caller requested it.
1561 if (installer_directory
&&
1562 InstallUtil::GetInstallReturnCode(install_status
) == 0) {
1563 *installer_directory
=
1564 installer_state
.GetInstallerDirectory(*installer_version
);
1567 // temp_path's dtor will take care of deleting or scheduling itself for
1568 // deletion at reboot when this scope closes.
1569 VLOG(1) << "Deleting temporary directory " << temp_path
.path().value();
1571 return install_status
;
1574 } // namespace installer
1576 int WINAPI
wWinMain(HINSTANCE instance
, HINSTANCE prev_instance
,
1577 wchar_t* command_line
, int show_command
) {
1578 // Check to see if the CPU is supported before doing anything else. There's
1579 // very little than can safely be accomplished if the CPU isn't supported
1580 // since dependent libraries (e.g., base) may use invalid instructions.
1581 if (!installer::IsProcessorSupported())
1582 return installer::CPU_NOT_SUPPORTED
;
1584 // The exit manager is in charge of calling the dtors of singletons.
1585 base::AtExitManager exit_manager
;
1586 base::CommandLine::Init(0, NULL
);
1588 // install_util uses chrome paths.
1589 chrome::RegisterPathProvider();
1591 const MasterPreferences
& prefs
= MasterPreferences::ForCurrentProcess();
1592 installer::InitInstallerLogging(prefs
);
1594 const base::CommandLine
& cmd_line
= *base::CommandLine::ForCurrentProcess();
1595 VLOG(1) << "Command Line: " << cmd_line
.GetCommandLineString();
1597 VLOG(1) << "multi install is " << prefs
.is_multi_install();
1598 bool system_install
= false;
1599 prefs
.GetBool(installer::master_preferences::kSystemLevel
, &system_install
);
1600 VLOG(1) << "system install is " << system_install
;
1602 scoped_ptr
<google_breakpad::ExceptionHandler
> breakpad(
1603 InitializeCrashReporting(system_install
));
1605 InstallationState original_state
;
1606 original_state
.Initialize();
1608 InstallerState installer_state
;
1609 installer_state
.Initialize(cmd_line
, prefs
, original_state
);
1610 const bool is_uninstall
= cmd_line
.HasSwitch(installer::switches::kUninstall
);
1612 // Check to make sure current system is WinXP or later. If not, log
1613 // error message and get out.
1614 if (!InstallUtil::IsOSSupported()) {
1615 LOG(ERROR
) << "Chrome only supports Windows XP or later.";
1616 installer_state
.WriteInstallerResult(
1617 installer::OS_NOT_SUPPORTED
, IDS_INSTALL_OS_NOT_SUPPORTED_BASE
, NULL
);
1618 return installer::OS_NOT_SUPPORTED
;
1621 // Initialize COM for use later.
1622 base::win::ScopedCOMInitializer com_initializer
;
1623 if (!com_initializer
.succeeded()) {
1624 installer_state
.WriteInstallerResult(
1625 installer::OS_ERROR
, IDS_INSTALL_OS_ERROR_BASE
, NULL
);
1626 return installer::OS_ERROR
;
1629 // Some command line options don't work with SxS install/uninstall
1630 if (InstallUtil::IsChromeSxSProcess()) {
1631 if (system_install
||
1632 prefs
.is_multi_install() ||
1633 cmd_line
.HasSwitch(installer::switches::kSelfDestruct
) ||
1634 cmd_line
.HasSwitch(installer::switches::kMakeChromeDefault
) ||
1635 cmd_line
.HasSwitch(installer::switches::kRegisterChromeBrowser
) ||
1636 cmd_line
.HasSwitch(installer::switches::kRemoveChromeRegistration
) ||
1637 cmd_line
.HasSwitch(installer::switches::kInactiveUserToast
) ||
1638 cmd_line
.HasSwitch(installer::switches::kSystemLevelToast
)) {
1639 return installer::SXS_OPTION_NOT_SUPPORTED
;
1643 // Some command line options are no longer supported and must error out.
1644 if (installer::ContainsUnsupportedSwitch(cmd_line
))
1645 return installer::UNSUPPORTED_OPTION
;
1647 // A variety of installer operations require the path to the current
1648 // executable. Get it once here for use throughout these operations. Note that
1649 // the path service is the authoritative source for this path. One might think
1650 // that CommandLine::GetProgram would suffice, but it won't since
1651 // CreateProcess may have been called with a command line that is somewhat
1652 // ambiguous (e.g., an unquoted path with spaces, or a path lacking the file
1653 // extension), in which case CommandLineToArgv will not yield an argv with the
1654 // true path to the program at position 0.
1655 base::FilePath setup_exe
;
1656 PathService::Get(base::FILE_EXE
, &setup_exe
);
1659 if (HandleNonInstallCmdLineOptions(
1660 original_state
, setup_exe
, cmd_line
, &installer_state
, &exit_code
)) {
1664 if (system_install
&& !IsUserAnAdmin()) {
1665 if (base::win::GetVersion() >= base::win::VERSION_VISTA
&&
1666 !cmd_line
.HasSwitch(installer::switches::kRunAsAdmin
)) {
1667 base::CommandLine
new_cmd(base::CommandLine::NO_PROGRAM
);
1668 new_cmd
.AppendArguments(cmd_line
, true);
1669 // Append --run-as-admin flag to let the new instance of setup.exe know
1670 // that we already tried to launch ourselves as admin.
1671 new_cmd
.AppendSwitch(installer::switches::kRunAsAdmin
);
1672 // If system_install became true due to an environment variable, append
1673 // it to the command line here since env vars may not propagate past the
1675 if (!new_cmd
.HasSwitch(installer::switches::kSystemLevel
))
1676 new_cmd
.AppendSwitch(installer::switches::kSystemLevel
);
1678 DWORD exit_code
= installer::UNKNOWN_STATUS
;
1679 InstallUtil::ExecuteExeAsAdmin(new_cmd
, &exit_code
);
1682 LOG(ERROR
) << "Non admin user can not install system level Chrome.";
1683 installer_state
.WriteInstallerResult(installer::INSUFFICIENT_RIGHTS
,
1684 IDS_INSTALL_INSUFFICIENT_RIGHTS_BASE
, NULL
);
1685 return installer::INSUFFICIENT_RIGHTS
;
1689 UninstallMultiChromeFrameIfPresent(cmd_line
, prefs
,
1690 &original_state
, &installer_state
);
1692 base::FilePath installer_directory
;
1693 installer::InstallStatus install_status
= installer::UNKNOWN_STATUS
;
1694 // If --uninstall option is given, uninstall the identified product(s)
1697 UninstallProducts(original_state
, installer_state
, setup_exe
, cmd_line
);
1699 // If --uninstall option is not specified, we assume it is install case.
1701 InstallProducts(original_state
, setup_exe
, cmd_line
, prefs
,
1702 &installer_state
, &installer_directory
);
1705 // Validate that the machine is now in a good state following the operation.
1706 // TODO(grt): change this to log at DFATAL once we're convinced that the
1707 // validator handles all cases properly.
1708 InstallationValidator::InstallationType installation_type
=
1709 InstallationValidator::NO_PRODUCTS
;
1711 !InstallationValidator::ValidateInstallationType(system_install
,
1712 &installation_type
));
1714 int return_code
= 0;
1715 // MSI demands that custom actions always return 0 (ERROR_SUCCESS) or it will
1716 // rollback the action. If we're uninstalling we want to avoid this, so always
1717 // report success, squashing any more informative return codes.
1718 if (!(installer_state
.is_msi() && is_uninstall
)) {
1719 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT
1720 // to pass through, since this is only returned on uninstall which is
1721 // never invoked directly by Google Update.
1722 return_code
= InstallUtil::GetInstallReturnCode(install_status
);
1725 VLOG(1) << "Installation complete, returning: " << return_code
;