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