Convert browser_tests to Swarming.
[chromium-blink-merge.git] / chrome / installer / setup / install.cc
blob58272b7f454da3a8d6398b386d8d881894f23155
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/install.h"
7 #include <windows.h>
8 #include <shlobj.h>
9 #include <time.h>
11 #include <string>
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/numerics/safe_conversions.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/win/shortcut.h"
22 #include "base/win/windows_version.h"
23 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/installer/setup/install_worker.h"
26 #include "chrome/installer/setup/setup_constants.h"
27 #include "chrome/installer/util/auto_launch_util.h"
28 #include "chrome/installer/util/beacons.h"
29 #include "chrome/installer/util/browser_distribution.h"
30 #include "chrome/installer/util/create_reg_key_work_item.h"
31 #include "chrome/installer/util/delete_after_reboot_helper.h"
32 #include "chrome/installer/util/google_update_constants.h"
33 #include "chrome/installer/util/helper.h"
34 #include "chrome/installer/util/install_util.h"
35 #include "chrome/installer/util/master_preferences.h"
36 #include "chrome/installer/util/master_preferences_constants.h"
37 #include "chrome/installer/util/set_reg_value_work_item.h"
38 #include "chrome/installer/util/shell_util.h"
39 #include "chrome/installer/util/util_constants.h"
40 #include "chrome/installer/util/work_item_list.h"
43 namespace {
45 void LogShortcutOperation(ShellUtil::ShortcutLocation location,
46 BrowserDistribution* dist,
47 const ShellUtil::ShortcutProperties& properties,
48 ShellUtil::ShortcutOperation operation,
49 bool failed) {
50 // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and
51 // thus this method does not handle logging a message for it.
52 DCHECK(operation != ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING);
53 std::string message;
54 if (failed)
55 message.append("Failed: ");
56 message.append(
57 (operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS ||
58 operation == ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL) ?
59 "Creating " : "Overwriting ");
60 if (failed && operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING)
61 message.append("(maybe the shortcut doesn't exist?) ");
62 message.append((properties.level == ShellUtil::CURRENT_USER) ? "per-user " :
63 "all-users ");
64 switch (location) {
65 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
66 message.append("Desktop ");
67 break;
68 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
69 message.append("Quick Launch ");
70 break;
71 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
72 message.append("Start menu/" +
73 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
74 BrowserDistribution::SUBFOLDER_CHROME)) +
75 " ");
76 break;
77 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
78 message.append("Start menu/" +
79 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
80 BrowserDistribution::SUBFOLDER_APPS)) +
81 " ");
82 break;
83 default:
84 NOTREACHED();
87 message.push_back('"');
88 if (properties.has_shortcut_name())
89 message.append(base::UTF16ToUTF8(properties.shortcut_name));
90 else
91 message.append(base::UTF16ToUTF8(dist->GetDisplayName()));
92 message.push_back('"');
94 message.append(" shortcut to ");
95 message.append(base::UTF16ToUTF8(properties.target.value()));
96 if (properties.has_arguments())
97 message.append(base::UTF16ToUTF8(properties.arguments));
99 if (properties.pin_to_taskbar &&
100 base::win::GetVersion() >= base::win::VERSION_WIN7) {
101 message.append(" and pinning to the taskbar.");
102 } else {
103 message.push_back('.');
106 if (failed)
107 LOG(WARNING) << message;
108 else
109 VLOG(1) << message;
112 void ExecuteAndLogShortcutOperation(
113 ShellUtil::ShortcutLocation location,
114 BrowserDistribution* dist,
115 const ShellUtil::ShortcutProperties& properties,
116 ShellUtil::ShortcutOperation operation) {
117 LogShortcutOperation(location, dist, properties, operation, false);
118 if (!ShellUtil::CreateOrUpdateShortcut(location, dist, properties,
119 operation)) {
120 LogShortcutOperation(location, dist, properties, operation, true);
124 void AddChromeToMediaPlayerList() {
125 base::string16 reg_path(installer::kMediaPlayerRegPath);
126 // registry paths can also be appended like file system path
127 reg_path.push_back(base::FilePath::kSeparators[0]);
128 reg_path.append(installer::kChromeExe);
129 VLOG(1) << "Adding Chrome to Media player list at " << reg_path;
130 scoped_ptr<WorkItem> work_item(WorkItem::CreateCreateRegKeyWorkItem(
131 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default));
133 // if the operation fails we log the error but still continue
134 if (!work_item.get()->Do())
135 LOG(ERROR) << "Could not add Chrome to media player inclusion list.";
138 // Copy master_preferences file provided to installer, in the same folder
139 // as chrome.exe so Chrome first run can find it. This function will be called
140 // only on the first install of Chrome.
141 void CopyPreferenceFileForFirstRun(
142 const installer::InstallerState& installer_state,
143 const base::FilePath& prefs_source_path) {
144 base::FilePath prefs_dest_path(installer_state.target_path().AppendASCII(
145 installer::kDefaultMasterPrefs));
146 if (!base::CopyFile(prefs_source_path, prefs_dest_path)) {
147 VLOG(1) << "Failed to copy master preferences from:"
148 << prefs_source_path.value() << " gle: " << ::GetLastError();
152 // This function installs a new version of Chrome to the specified location.
154 // setup_path: Path to the executable (setup.exe) as it will be copied
155 // to Chrome install folder after install is complete
156 // archive_path: Path to the archive (chrome.7z) as it will be copied
157 // to Chrome install folder after install is complete
158 // src_path: the path that contains a complete and unpacked Chrome package
159 // to be installed.
160 // temp_path: the path of working directory used during installation. This path
161 // does not need to exist.
162 // new_version: new Chrome version that needs to be installed
163 // current_version: returns the current active version (if any)
165 // This function makes best effort to do installation in a transactional
166 // manner. If failed it tries to rollback all changes on the file system
167 // and registry. For example, if package exists before calling the
168 // function, it rolls back all new file and directory changes under
169 // package. If package does not exist before calling the function
170 // (typical new install), the function creates package during install
171 // and removes the whole directory during rollback.
172 installer::InstallStatus InstallNewVersion(
173 const installer::InstallationState& original_state,
174 const installer::InstallerState& installer_state,
175 const base::FilePath& setup_path,
176 const base::FilePath& archive_path,
177 const base::FilePath& src_path,
178 const base::FilePath& temp_path,
179 const Version& new_version,
180 scoped_ptr<Version>* current_version) {
181 DCHECK(current_version);
183 installer_state.UpdateStage(installer::BUILDING);
185 current_version->reset(installer_state.GetCurrentVersion(original_state));
186 scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList());
188 AddInstallWorkItems(original_state,
189 installer_state,
190 setup_path,
191 archive_path,
192 src_path,
193 temp_path,
194 current_version->get(),
195 new_version,
196 install_list.get());
198 base::FilePath new_chrome_exe(
199 installer_state.target_path().Append(installer::kChromeNewExe));
201 installer_state.UpdateStage(installer::EXECUTING);
203 if (!install_list->Do()) {
204 installer_state.UpdateStage(installer::ROLLINGBACK);
205 installer::InstallStatus result =
206 base::PathExists(new_chrome_exe) && current_version->get() &&
207 new_version.Equals(*current_version->get()) ?
208 installer::SAME_VERSION_REPAIR_FAILED :
209 installer::INSTALL_FAILED;
210 LOG(ERROR) << "Install failed, rolling back... result: " << result;
211 install_list->Rollback();
212 LOG(ERROR) << "Rollback complete. ";
213 return result;
216 installer_state.UpdateStage(installer::REFRESHING_POLICY);
218 installer::RefreshElevationPolicy();
220 if (!current_version->get()) {
221 VLOG(1) << "First install of version " << new_version.GetString();
222 return installer::FIRST_INSTALL_SUCCESS;
225 if (new_version.Equals(**current_version)) {
226 VLOG(1) << "Install repaired of version " << new_version.GetString();
227 return installer::INSTALL_REPAIRED;
230 if (new_version.CompareTo(**current_version) > 0) {
231 if (base::PathExists(new_chrome_exe)) {
232 VLOG(1) << "Version updated to " << new_version.GetString()
233 << " while running " << (*current_version)->GetString();
234 return installer::IN_USE_UPDATED;
236 VLOG(1) << "Version updated to " << new_version.GetString();
237 return installer::NEW_VERSION_UPDATED;
240 LOG(ERROR) << "Not sure how we got here while updating"
241 << ", new version: " << new_version.GetString()
242 << ", old version: " << (*current_version)->GetString();
244 return installer::INSTALL_FAILED;
247 // Deletes the old "Uninstall Google Chrome" shortcut in the Start menu which
248 // was installed prior to Chrome 24.
249 void CleanupLegacyShortcuts(const installer::InstallerState& installer_state,
250 BrowserDistribution* dist,
251 const base::FilePath& chrome_exe) {
252 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ?
253 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER;
254 base::FilePath uninstall_shortcut_path;
255 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
256 dist, shortcut_level, &uninstall_shortcut_path);
257 uninstall_shortcut_path = uninstall_shortcut_path.Append(
258 dist->GetUninstallLinkName() + installer::kLnkExt);
259 base::DeleteFile(uninstall_shortcut_path, false);
262 } // end namespace
264 namespace installer {
266 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
267 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
268 base::ASCIIToUTF16("&amp;"), att_value);
269 base::ReplaceChars(*att_value, base::ASCIIToUTF16("'"),
270 base::ASCIIToUTF16("&apos;"), att_value);
271 base::ReplaceChars(*att_value, base::ASCIIToUTF16("<"),
272 base::ASCIIToUTF16("&lt;"), att_value);
275 bool CreateVisualElementsManifest(const base::FilePath& src_path,
276 const Version& version) {
277 // Construct the relative path to the versioned VisualElements directory.
278 base::string16 elements_dir(base::ASCIIToUTF16(version.GetString()));
279 elements_dir.push_back(base::FilePath::kSeparators[0]);
280 elements_dir.append(installer::kVisualElements);
282 // Some distributions of Chromium may not include visual elements. Only
283 // proceed if this distribution does.
284 if (!base::PathExists(src_path.Append(elements_dir))) {
285 VLOG(1) << "No visual elements found, not writing "
286 << installer::kVisualElementsManifest << " to " << src_path.value();
287 return true;
288 } else {
289 // A printf-style format string for generating the visual elements
290 // manifest. Required arguments, in order, are:
291 // - Localized display name for the product.
292 // - Relative path to the VisualElements directory, three times.
293 static const char kManifestTemplate[] =
294 "<Application>\r\n"
295 " <VisualElements\r\n"
296 " DisplayName='%ls'\r\n"
297 " Logo='%ls\\Logo.png'\r\n"
298 " SmallLogo='%ls\\SmallLogo.png'\r\n"
299 " ForegroundText='light'\r\n"
300 " BackgroundColor='#323232'>\r\n"
301 " <DefaultTile ShowName='allLogos'/>\r\n"
302 " <SplashScreen Image='%ls\\splash-620x300.png'/>\r\n"
303 " </VisualElements>\r\n"
304 "</Application>";
306 const base::string16 manifest_template(
307 base::ASCIIToUTF16(kManifestTemplate));
309 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
310 BrowserDistribution::CHROME_BROWSER);
311 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
312 // resource for |display_name|.
313 base::string16 display_name(dist->GetDisplayName());
314 EscapeXmlAttributeValueInSingleQuotes(&display_name);
316 // Fill the manifest with the desired values.
317 base::string16 manifest16(base::StringPrintf(
318 manifest_template.c_str(), display_name.c_str(), elements_dir.c_str(),
319 elements_dir.c_str(), elements_dir.c_str()));
321 // Write the manifest to |src_path|.
322 const std::string manifest(base::UTF16ToUTF8(manifest16));
323 int size = base::checked_cast<int>(manifest.size());
324 if (base::WriteFile(
325 src_path.Append(installer::kVisualElementsManifest),
326 manifest.c_str(), size) == size) {
327 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
328 << " to " << src_path.value();
329 return true;
330 } else {
331 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
332 << " to " << src_path.value();
333 return false;
338 void CreateOrUpdateShortcuts(
339 const base::FilePath& target,
340 const installer::Product& product,
341 const MasterPreferences& prefs,
342 InstallShortcutLevel install_level,
343 InstallShortcutOperation install_operation) {
344 bool do_not_create_any_shortcuts = false;
345 prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts,
346 &do_not_create_any_shortcuts);
347 if (do_not_create_any_shortcuts)
348 return;
350 // Extract shortcut preferences from |prefs|.
351 bool do_not_create_desktop_shortcut = false;
352 bool do_not_create_quick_launch_shortcut = false;
353 bool do_not_create_taskbar_shortcut = false;
354 bool alternate_desktop_shortcut = false;
355 prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut,
356 &do_not_create_desktop_shortcut);
357 prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut,
358 &do_not_create_quick_launch_shortcut);
359 prefs.GetBool(master_preferences::kDoNotCreateTaskbarShortcut,
360 &do_not_create_taskbar_shortcut);
361 prefs.GetBool(master_preferences::kAltShortcutText,
362 &alternate_desktop_shortcut);
364 BrowserDistribution* dist = product.distribution();
366 // The default operation on update is to overwrite shortcuts with the
367 // currently desired properties, but do so only for shortcuts that still
368 // exist.
369 ShellUtil::ShortcutOperation shortcut_operation;
370 switch (install_operation) {
371 case INSTALL_SHORTCUT_CREATE_ALL:
372 shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS;
373 break;
374 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL:
375 shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL;
376 break;
377 default:
378 DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING);
379 shortcut_operation = ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING;
380 break;
383 // Shortcuts are always installed per-user unless specified.
384 ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ?
385 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER);
387 // |base_properties|: The basic properties to set on every shortcut installed
388 // (to be refined on a per-shortcut basis).
389 ShellUtil::ShortcutProperties base_properties(shortcut_level);
390 product.AddDefaultShortcutProperties(target, &base_properties);
392 if (!do_not_create_desktop_shortcut ||
393 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
394 ShellUtil::ShortcutProperties desktop_properties(base_properties);
395 if (alternate_desktop_shortcut) {
396 desktop_properties.set_shortcut_name(
397 dist->GetShortcutName(
398 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE));
400 ExecuteAndLogShortcutOperation(
401 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties,
402 shortcut_operation);
404 // On update there is no harm in always trying to update the alternate
405 // Desktop shortcut.
406 if (!alternate_desktop_shortcut &&
407 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
408 desktop_properties.set_shortcut_name(
409 dist->GetShortcutName(
410 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE));
411 ExecuteAndLogShortcutOperation(
412 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties,
413 shortcut_operation);
417 if (!do_not_create_quick_launch_shortcut ||
418 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
419 // There is no such thing as an all-users Quick Launch shortcut, always
420 // install the per-user shortcut.
421 ShellUtil::ShortcutProperties quick_launch_properties(base_properties);
422 quick_launch_properties.level = ShellUtil::CURRENT_USER;
423 ExecuteAndLogShortcutOperation(
424 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist,
425 quick_launch_properties, shortcut_operation);
428 ShellUtil::ShortcutProperties start_menu_properties(base_properties);
429 // IMPORTANT: Only the default (no arguments and default browserappid) browser
430 // shortcut in the Start menu (Start screen on Win8+) should be made dual
431 // mode.
432 start_menu_properties.set_dual_mode(true);
433 if (!do_not_create_taskbar_shortcut &&
434 (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS ||
435 shortcut_operation ==
436 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)) {
437 start_menu_properties.set_pin_to_taskbar(true);
439 ExecuteAndLogShortcutOperation(
440 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist,
441 start_menu_properties, shortcut_operation);
444 void RegisterChromeOnMachine(const installer::InstallerState& installer_state,
445 const installer::Product& product,
446 bool make_chrome_default) {
447 DCHECK(product.is_chrome());
449 // Try to add Chrome to Media Player shim inclusion list. We don't do any
450 // error checking here because this operation will fail if user doesn't
451 // have admin rights and we want to ignore the error.
452 AddChromeToMediaPlayerList();
454 // Make Chrome the default browser if desired when possible. Otherwise, only
455 // register it with Windows.
456 BrowserDistribution* dist = product.distribution();
457 const base::FilePath chrome_exe(
458 installer_state.target_path().Append(installer::kChromeExe));
459 VLOG(1) << "Registering Chrome as browser: " << chrome_exe.value();
460 if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) {
461 int level = ShellUtil::CURRENT_USER;
462 if (installer_state.system_install())
463 level = level | ShellUtil::SYSTEM_LEVEL;
464 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true);
465 } else {
466 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), false);
470 InstallStatus InstallOrUpdateProduct(
471 const installer::InstallationState& original_state,
472 const installer::InstallerState& installer_state,
473 const base::FilePath& setup_path,
474 const base::FilePath& archive_path,
475 const base::FilePath& install_temp_path,
476 const base::FilePath& src_path,
477 const base::FilePath& prefs_path,
478 const MasterPreferences& prefs,
479 const Version& new_version) {
480 DCHECK(!installer_state.products().empty());
482 // TODO(robertshield): Removing the pending on-reboot moves should be done
483 // elsewhere.
484 // Remove any scheduled MOVEFILE_DELAY_UNTIL_REBOOT entries in the target of
485 // this installation. These may have been added during a previous uninstall of
486 // the same version.
487 LOG_IF(ERROR, !RemoveFromMovesPendingReboot(installer_state.target_path()))
488 << "Error accessing pending moves value.";
490 // Create VisualElementManifest.xml in |src_path| (if required) so that it
491 // looks as if it had been extracted from the archive when calling
492 // InstallNewVersion() below.
493 installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST);
494 CreateVisualElementsManifest(src_path, new_version);
496 scoped_ptr<Version> existing_version;
497 InstallStatus result = InstallNewVersion(original_state, installer_state,
498 setup_path, archive_path, src_path, install_temp_path, new_version,
499 &existing_version);
501 // TODO(robertshield): Everything below this line should instead be captured
502 // by WorkItems.
503 if (!InstallUtil::GetInstallReturnCode(result)) {
504 installer_state.UpdateStage(installer::UPDATING_CHANNELS);
506 // Update the modifiers on the channel values for the product(s) being
507 // installed and for the binaries in case of multi-install.
508 installer_state.UpdateChannels();
510 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE);
512 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty())
513 CopyPreferenceFileForFirstRun(installer_state, prefs_path);
515 installer_state.UpdateStage(installer::CREATING_SHORTCUTS);
517 const installer::Product* chrome_product =
518 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER);
519 // Creates shortcuts for Chrome.
520 if (chrome_product) {
521 BrowserDistribution* chrome_dist = chrome_product->distribution();
522 const base::FilePath chrome_exe(
523 installer_state.target_path().Append(kChromeExe));
524 CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe);
526 // Install per-user shortcuts on user-level installs and all-users
527 // shortcuts on system-level installs. Note that Active Setup will take
528 // care of installing missing per-user shortcuts on system-level install
529 // (i.e., quick launch, taskbar pin, and possibly deleted all-users
530 // shortcuts).
531 InstallShortcutLevel install_level = installer_state.system_install() ?
532 ALL_USERS : CURRENT_USER;
534 InstallShortcutOperation install_operation =
535 INSTALL_SHORTCUT_REPLACE_EXISTING;
536 if (result == installer::FIRST_INSTALL_SUCCESS ||
537 result == installer::INSTALL_REPAIRED ||
538 !original_state.GetProductState(installer_state.system_install(),
539 chrome_dist->GetType())) {
540 // Always create the shortcuts on a new install, a repair install, and
541 // when the Chrome product is being added to the current install.
542 install_operation = INSTALL_SHORTCUT_CREATE_ALL;
545 CreateOrUpdateShortcuts(chrome_exe, *chrome_product, prefs, install_level,
546 install_operation);
549 if (chrome_product) {
550 // Register Chrome and, if requested, make Chrome the default browser.
551 installer_state.UpdateStage(installer::REGISTERING_CHROME);
553 bool make_chrome_default = false;
554 prefs.GetBool(master_preferences::kMakeChromeDefault,
555 &make_chrome_default);
557 // If this is not the user's first Chrome install, but they have chosen
558 // Chrome to become their default browser on the download page, we must
559 // force it here because the master_preferences file will not get copied
560 // into the build.
561 bool force_chrome_default_for_user = false;
562 if (result == NEW_VERSION_UPDATED ||
563 result == INSTALL_REPAIRED) {
564 prefs.GetBool(master_preferences::kMakeChromeDefaultForUser,
565 &force_chrome_default_for_user);
568 RegisterChromeOnMachine(installer_state, *chrome_product,
569 make_chrome_default || force_chrome_default_for_user);
571 // Configure auto-launch.
572 if (result == FIRST_INSTALL_SUCCESS) {
573 installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH);
575 // Add auto-launch key if specified in master_preferences.
576 bool auto_launch_chrome = false;
577 prefs.GetBool(
578 installer::master_preferences::kAutoLaunchChrome,
579 &auto_launch_chrome);
580 if (auto_launch_chrome) {
581 auto_launch_util::EnableForegroundStartAtLogin(
582 base::ASCIIToUTF16(chrome::kInitialProfile),
583 installer_state.target_path());
587 if (!installer_state.system_install()) {
588 DCHECK_EQ(chrome_product->distribution(),
589 BrowserDistribution::GetDistribution());
590 UpdateDefaultBrowserBeaconForPath(
591 installer_state.target_path().Append(installer::kChromeExe));
595 installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS);
597 installer_state.RemoveOldVersionDirectories(
598 new_version,
599 existing_version.get(),
600 install_temp_path);
603 return result;
606 void HandleOsUpgradeForBrowser(const installer::InstallerState& installer_state,
607 const installer::Product& chrome) {
608 DCHECK(chrome.is_chrome());
609 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
610 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
611 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
612 VLOG(1) << "Updating and registering shortcuts.";
613 // Read master_preferences copied beside chrome.exe at install.
614 MasterPreferences prefs(
615 installer_state.target_path().AppendASCII(kDefaultMasterPrefs));
617 // Unfortunately, if this is a system-level install, we can't update the
618 // shortcuts of each individual user (this only matters if this is an OS
619 // upgrade from XP/Vista to Win7+ as some properties are only set on
620 // shortcuts as of Win7).
621 // At least attempt to update potentially existing all-users shortcuts.
622 InstallShortcutLevel level = installer_state.system_install() ?
623 ALL_USERS : CURRENT_USER;
624 base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe));
625 CreateOrUpdateShortcuts(
626 chrome_exe, chrome, prefs, level, INSTALL_SHORTCUT_REPLACE_EXISTING);
627 RegisterChromeOnMachine(installer_state, chrome, false);
629 UpdateOsUpgradeBeacon(installer_state.system_install(),
630 BrowserDistribution::GetDistribution());
631 if (!installer_state.system_install())
632 UpdateDefaultBrowserBeaconForPath(chrome_exe);
636 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
637 // in install_worker.cc needs to be increased for Active Setup to invoke this
638 // again for all users of this install.
639 void HandleActiveSetupForBrowser(const base::FilePath& installation_root,
640 const installer::Product& chrome,
641 bool force) {
642 DCHECK(chrome.is_chrome());
643 // Only create shortcuts on Active Setup if the first run sentinel is not
644 // present for this user (as some shortcuts used to be installed on first
645 // run and this could otherwise re-install shortcuts for users that have
646 // already deleted them in the past).
647 // Decide whether to create the shortcuts or simply replace existing
648 // shortcuts; if the decision is to create them, only shortcuts whose matching
649 // all-users shortcut isn't present on the system will be created.
650 InstallShortcutOperation install_operation =
651 (!force && InstallUtil::IsFirstRunSentinelPresent() ?
652 INSTALL_SHORTCUT_REPLACE_EXISTING :
653 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
655 // Read master_preferences copied beside chrome.exe at install.
656 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
657 base::FilePath chrome_exe(installation_root.Append(kChromeExe));
658 CreateOrUpdateShortcuts(
659 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
661 UpdateDefaultBrowserBeaconForPath(chrome_exe);
664 } // namespace installer