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"
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"
44 void LogShortcutOperation(ShellUtil::ShortcutLocation location
,
45 BrowserDistribution
* dist
,
46 const ShellUtil::ShortcutProperties
& properties
,
47 ShellUtil::ShortcutOperation operation
,
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
);
54 message
.append("Failed: ");
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 " :
64 case ShellUtil::SHORTCUT_LOCATION_DESKTOP
:
65 message
.append("Desktop ");
67 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
:
68 message
.append("Quick Launch ");
70 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
:
71 message
.append("Start menu/" +
72 base::UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
73 BrowserDistribution::SUBFOLDER_CHROME
)) +
76 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
:
77 message
.append("Start menu/" +
78 base::UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
79 BrowserDistribution::SUBFOLDER_APPS
)) +
86 message
.push_back('"');
87 if (properties
.has_shortcut_name())
88 message
.append(base::UTF16ToUTF8(properties
.shortcut_name
));
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.");
102 message
.push_back('.');
106 LOG(WARNING
) << 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
,
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
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
,
193 current_version
->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. ";
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);
263 namespace installer
{
265 void EscapeXmlAttributeValueInSingleQuotes(base::string16
* att_value
) {
266 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("&"),
267 base::ASCIIToUTF16("&"), att_value
);
268 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("'"),
269 base::ASCIIToUTF16("'"), att_value
);
270 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("<"),
271 base::ASCIIToUTF16("<"), 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();
288 // A printf-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, three times.
292 static const char kManifestTemplate
[] =
294 " <VisualElements\r\n"
295 " DisplayName='%ls'\r\n"
296 " Logo='%ls\\Logo.png'\r\n"
297 " SmallLogo='%ls\\SmallLogo.png'\r\n"
298 " ForegroundText='light'\r\n"
299 " BackgroundColor='#323232'>\r\n"
300 " <DefaultTile ShowName='allLogos'/>\r\n"
301 " <SplashScreen Image='%ls\\splash-620x300.png'/>\r\n"
302 " </VisualElements>\r\n"
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(),
318 elements_dir
.c_str(), elements_dir
.c_str()));
320 // Write the manifest to |src_path|.
321 const std::string
manifest(base::UTF16ToUTF8(manifest16
));
322 int size
= base::checked_cast
<int>(manifest
.size());
324 src_path
.Append(installer::kVisualElementsManifest
),
325 manifest
.c_str(), size
) == size
) {
326 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
327 << " to " << src_path
.value();
330 PLOG(ERROR
) << "Error writing " << installer::kVisualElementsManifest
331 << " to " << src_path
.value();
337 void CreateOrUpdateShortcuts(
338 const base::FilePath
& target
,
339 const installer::Product
& product
,
340 const MasterPreferences
& prefs
,
341 InstallShortcutLevel install_level
,
342 InstallShortcutOperation install_operation
) {
343 bool do_not_create_any_shortcuts
= false;
344 prefs
.GetBool(master_preferences::kDoNotCreateAnyShortcuts
,
345 &do_not_create_any_shortcuts
);
346 if (do_not_create_any_shortcuts
)
349 // Extract shortcut preferences from |prefs|.
350 bool do_not_create_desktop_shortcut
= false;
351 bool do_not_create_quick_launch_shortcut
= false;
352 bool do_not_create_taskbar_shortcut
= false;
353 bool alternate_desktop_shortcut
= false;
354 prefs
.GetBool(master_preferences::kDoNotCreateDesktopShortcut
,
355 &do_not_create_desktop_shortcut
);
356 prefs
.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut
,
357 &do_not_create_quick_launch_shortcut
);
358 prefs
.GetBool(master_preferences::kDoNotCreateTaskbarShortcut
,
359 &do_not_create_taskbar_shortcut
);
360 prefs
.GetBool(master_preferences::kAltShortcutText
,
361 &alternate_desktop_shortcut
);
363 BrowserDistribution
* dist
= product
.distribution();
365 // The default operation on update is to overwrite shortcuts with the
366 // currently desired properties, but do so only for shortcuts that still
368 ShellUtil::ShortcutOperation shortcut_operation
;
369 switch (install_operation
) {
370 case INSTALL_SHORTCUT_CREATE_ALL
:
371 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
;
373 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
:
374 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
;
377 DCHECK(install_operation
== INSTALL_SHORTCUT_REPLACE_EXISTING
);
378 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
;
382 // Shortcuts are always installed per-user unless specified.
383 ShellUtil::ShellChange shortcut_level
= (install_level
== ALL_USERS
?
384 ShellUtil::SYSTEM_LEVEL
: ShellUtil::CURRENT_USER
);
386 // |base_properties|: The basic properties to set on every shortcut installed
387 // (to be refined on a per-shortcut basis).
388 ShellUtil::ShortcutProperties
base_properties(shortcut_level
);
389 product
.AddDefaultShortcutProperties(target
, &base_properties
);
391 if (!do_not_create_desktop_shortcut
||
392 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
393 ShellUtil::ShortcutProperties
desktop_properties(base_properties
);
394 if (alternate_desktop_shortcut
) {
395 desktop_properties
.set_shortcut_name(
396 dist
->GetShortcutName(
397 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
399 ExecuteAndLogShortcutOperation(
400 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
403 // On update there is no harm in always trying to update the alternate
405 if (!alternate_desktop_shortcut
&&
406 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
407 desktop_properties
.set_shortcut_name(
408 dist
->GetShortcutName(
409 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
410 ExecuteAndLogShortcutOperation(
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
416 if (!do_not_create_quick_launch_shortcut
||
417 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
418 // There is no such thing as an all-users Quick Launch shortcut, always
419 // install the per-user shortcut.
420 ShellUtil::ShortcutProperties
quick_launch_properties(base_properties
);
421 quick_launch_properties
.level
= ShellUtil::CURRENT_USER
;
422 ExecuteAndLogShortcutOperation(
423 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
, dist
,
424 quick_launch_properties
, shortcut_operation
);
427 ShellUtil::ShortcutProperties
start_menu_properties(base_properties
);
428 // IMPORTANT: Only the default (no arguments and default browserappid) browser
429 // shortcut in the Start menu (Start screen on Win8+) should be made dual
431 start_menu_properties
.set_dual_mode(true);
432 if (!do_not_create_taskbar_shortcut
&&
433 (shortcut_operation
== ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
||
434 shortcut_operation
==
435 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
)) {
436 start_menu_properties
.set_pin_to_taskbar(true);
438 ExecuteAndLogShortcutOperation(
439 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
, dist
,
440 start_menu_properties
, shortcut_operation
);
443 void RegisterChromeOnMachine(const installer::InstallerState
& installer_state
,
444 const installer::Product
& product
,
445 bool make_chrome_default
) {
446 DCHECK(product
.is_chrome());
448 // Try to add Chrome to Media Player shim inclusion list. We don't do any
449 // error checking here because this operation will fail if user doesn't
450 // have admin rights and we want to ignore the error.
451 AddChromeToMediaPlayerList();
453 // Make Chrome the default browser if desired when possible. Otherwise, only
454 // register it with Windows.
455 BrowserDistribution
* dist
= product
.distribution();
456 const base::FilePath
chrome_exe(
457 installer_state
.target_path().Append(installer::kChromeExe
));
458 VLOG(1) << "Registering Chrome as browser: " << chrome_exe
.value();
459 if (make_chrome_default
&& ShellUtil::CanMakeChromeDefaultUnattended()) {
460 int level
= ShellUtil::CURRENT_USER
;
461 if (installer_state
.system_install())
462 level
= level
| ShellUtil::SYSTEM_LEVEL
;
463 ShellUtil::MakeChromeDefault(dist
, level
, chrome_exe
, true);
465 ShellUtil::RegisterChromeBrowser(dist
, chrome_exe
, base::string16(), false);
469 InstallStatus
InstallOrUpdateProduct(
470 const installer::InstallationState
& original_state
,
471 const installer::InstallerState
& installer_state
,
472 const base::FilePath
& setup_path
,
473 const base::FilePath
& archive_path
,
474 const base::FilePath
& install_temp_path
,
475 const base::FilePath
& src_path
,
476 const base::FilePath
& prefs_path
,
477 const MasterPreferences
& prefs
,
478 const Version
& new_version
) {
479 DCHECK(!installer_state
.products().empty());
481 // TODO(robertshield): Removing the pending on-reboot moves should be done
483 // Remove any scheduled MOVEFILE_DELAY_UNTIL_REBOOT entries in the target of
484 // this installation. These may have been added during a previous uninstall of
486 LOG_IF(ERROR
, !RemoveFromMovesPendingReboot(installer_state
.target_path()))
487 << "Error accessing pending moves value.";
489 // Create VisualElementManifest.xml in |src_path| (if required) so that it
490 // looks as if it had been extracted from the archive when calling
491 // InstallNewVersion() below.
492 installer_state
.UpdateStage(installer::CREATING_VISUAL_MANIFEST
);
493 CreateVisualElementsManifest(src_path
, new_version
);
495 scoped_ptr
<Version
> existing_version
;
496 InstallStatus result
= InstallNewVersion(original_state
, installer_state
,
497 setup_path
, archive_path
, src_path
, install_temp_path
, new_version
,
500 // TODO(robertshield): Everything below this line should instead be captured
502 if (!InstallUtil::GetInstallReturnCode(result
)) {
503 installer_state
.UpdateStage(installer::UPDATING_CHANNELS
);
505 // Update the modifiers on the channel values for the product(s) being
506 // installed and for the binaries in case of multi-install.
507 installer_state
.UpdateChannels();
509 installer_state
.UpdateStage(installer::COPYING_PREFERENCES_FILE
);
511 if (result
== FIRST_INSTALL_SUCCESS
&& !prefs_path
.empty())
512 CopyPreferenceFileForFirstRun(installer_state
, prefs_path
);
514 installer_state
.UpdateStage(installer::CREATING_SHORTCUTS
);
516 const installer::Product
* chrome_product
=
517 installer_state
.FindProduct(BrowserDistribution::CHROME_BROWSER
);
518 // Creates shortcuts for Chrome.
519 if (chrome_product
) {
520 BrowserDistribution
* chrome_dist
= chrome_product
->distribution();
521 const base::FilePath
chrome_exe(
522 installer_state
.target_path().Append(kChromeExe
));
523 CleanupLegacyShortcuts(installer_state
, chrome_dist
, chrome_exe
);
525 // Install per-user shortcuts on user-level installs and all-users
526 // shortcuts on system-level installs. Note that Active Setup will take
527 // care of installing missing per-user shortcuts on system-level install
528 // (i.e., quick launch, taskbar pin, and possibly deleted all-users
530 InstallShortcutLevel install_level
= installer_state
.system_install() ?
531 ALL_USERS
: CURRENT_USER
;
533 InstallShortcutOperation install_operation
=
534 INSTALL_SHORTCUT_REPLACE_EXISTING
;
535 if (result
== installer::FIRST_INSTALL_SUCCESS
||
536 result
== installer::INSTALL_REPAIRED
||
537 !original_state
.GetProductState(installer_state
.system_install(),
538 chrome_dist
->GetType())) {
539 // Always create the shortcuts on a new install, a repair install, and
540 // when the Chrome product is being added to the current install.
541 install_operation
= INSTALL_SHORTCUT_CREATE_ALL
;
544 CreateOrUpdateShortcuts(chrome_exe
, *chrome_product
, prefs
, install_level
,
548 if (chrome_product
) {
549 // Register Chrome and, if requested, make Chrome the default browser.
550 installer_state
.UpdateStage(installer::REGISTERING_CHROME
);
552 bool make_chrome_default
= false;
553 prefs
.GetBool(master_preferences::kMakeChromeDefault
,
554 &make_chrome_default
);
556 // If this is not the user's first Chrome install, but they have chosen
557 // Chrome to become their default browser on the download page, we must
558 // force it here because the master_preferences file will not get copied
560 bool force_chrome_default_for_user
= false;
561 if (result
== NEW_VERSION_UPDATED
||
562 result
== INSTALL_REPAIRED
) {
563 prefs
.GetBool(master_preferences::kMakeChromeDefaultForUser
,
564 &force_chrome_default_for_user
);
567 RegisterChromeOnMachine(installer_state
, *chrome_product
,
568 make_chrome_default
|| force_chrome_default_for_user
);
570 // Configure auto-launch.
571 if (result
== FIRST_INSTALL_SUCCESS
) {
572 installer_state
.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH
);
574 // Add auto-launch key if specified in master_preferences.
575 bool auto_launch_chrome
= false;
577 installer::master_preferences::kAutoLaunchChrome
,
578 &auto_launch_chrome
);
579 if (auto_launch_chrome
) {
580 auto_launch_util::EnableForegroundStartAtLogin(
581 base::ASCIIToUTF16(chrome::kInitialProfile
),
582 installer_state
.target_path());
587 installer_state
.UpdateStage(installer::REMOVING_OLD_VERSIONS
);
589 installer_state
.RemoveOldVersionDirectories(
591 existing_version
.get(),
598 void HandleOsUpgradeForBrowser(const installer::InstallerState
& installer_state
,
599 const installer::Product
& chrome
) {
600 DCHECK(chrome
.is_chrome());
601 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
602 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
603 if (base::win::GetVersion() >= base::win::VERSION_WIN8
) {
604 VLOG(1) << "Updating and registering shortcuts.";
605 // Read master_preferences copied beside chrome.exe at install.
606 MasterPreferences
prefs(
607 installer_state
.target_path().AppendASCII(kDefaultMasterPrefs
));
609 // Unfortunately, if this is a system-level install, we can't update the
610 // shortcuts of each individual user (this only matters if this is an OS
611 // upgrade from XP/Vista to Win7+ as some properties are only set on
612 // shortcuts as of Win7).
613 // At least attempt to update potentially existing all-users shortcuts.
614 InstallShortcutLevel level
= installer_state
.system_install() ?
615 ALL_USERS
: CURRENT_USER
;
616 base::FilePath
chrome_exe(installer_state
.target_path().Append(kChromeExe
));
617 CreateOrUpdateShortcuts(
618 chrome_exe
, chrome
, prefs
, level
, INSTALL_SHORTCUT_REPLACE_EXISTING
);
619 RegisterChromeOnMachine(installer_state
, chrome
, false);
623 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
624 // in install_worker.cc needs to be increased for Active Setup to invoke this
625 // again for all users of this install.
626 void HandleActiveSetupForBrowser(const base::FilePath
& installation_root
,
627 const installer::Product
& chrome
,
629 DCHECK(chrome
.is_chrome());
630 // Only create shortcuts on Active Setup if the first run sentinel is not
631 // present for this user (as some shortcuts used to be installed on first
632 // run and this could otherwise re-install shortcuts for users that have
633 // already deleted them in the past).
634 // Decide whether to create the shortcuts or simply replace existing
635 // shortcuts; if the decision is to create them, only shortcuts whose matching
636 // all-users shortcut isn't present on the system will be created.
637 InstallShortcutOperation install_operation
=
638 (!force
&& InstallUtil::IsFirstRunSentinelPresent() ?
639 INSTALL_SHORTCUT_REPLACE_EXISTING
:
640 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
);
642 // Read master_preferences copied beside chrome.exe at install.
643 MasterPreferences
prefs(installation_root
.AppendASCII(kDefaultMasterPrefs
));
644 base::FilePath
chrome_exe(installation_root
.Append(kChromeExe
));
645 CreateOrUpdateShortcuts(
646 chrome_exe
, chrome
, prefs
, CURRENT_USER
, install_operation
);
649 } // namespace installer