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/setup/setup_util.h"
28 #include "chrome/installer/setup/update_active_setup_version_work_item.h"
29 #include "chrome/installer/util/auto_launch_util.h"
30 #include "chrome/installer/util/beacons.h"
31 #include "chrome/installer/util/browser_distribution.h"
32 #include "chrome/installer/util/create_reg_key_work_item.h"
33 #include "chrome/installer/util/delete_after_reboot_helper.h"
34 #include "chrome/installer/util/google_update_constants.h"
35 #include "chrome/installer/util/helper.h"
36 #include "chrome/installer/util/install_util.h"
37 #include "chrome/installer/util/master_preferences.h"
38 #include "chrome/installer/util/master_preferences_constants.h"
39 #include "chrome/installer/util/set_reg_value_work_item.h"
40 #include "chrome/installer/util/util_constants.h"
41 #include "chrome/installer/util/work_item.h"
42 #include "chrome/installer/util/work_item_list.h"
47 void LogShortcutOperation(ShellUtil::ShortcutLocation location
,
48 BrowserDistribution
* dist
,
49 const ShellUtil::ShortcutProperties
& properties
,
50 ShellUtil::ShortcutOperation operation
,
52 // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and
53 // thus this method does not handle logging a message for it.
54 DCHECK(operation
!= ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING
);
57 message
.append("Failed: ");
59 (operation
== ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
||
60 operation
== ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
) ?
61 "Creating " : "Overwriting ");
62 if (failed
&& operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
)
63 message
.append("(maybe the shortcut doesn't exist?) ");
64 message
.append((properties
.level
== ShellUtil::CURRENT_USER
) ? "per-user " :
67 case ShellUtil::SHORTCUT_LOCATION_DESKTOP
:
68 message
.append("Desktop ");
70 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
:
71 message
.append("Quick Launch ");
73 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
:
74 message
.append("Start menu/" +
75 base::UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
76 BrowserDistribution::SUBFOLDER_CHROME
)) +
79 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
:
80 message
.append("Start menu/" +
81 base::UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
82 BrowserDistribution::SUBFOLDER_APPS
)) +
89 message
.push_back('"');
90 if (properties
.has_shortcut_name())
91 message
.append(base::UTF16ToUTF8(properties
.shortcut_name
));
93 message
.append(base::UTF16ToUTF8(dist
->GetDisplayName()));
94 message
.push_back('"');
96 message
.append(" shortcut to ");
97 message
.append(base::UTF16ToUTF8(properties
.target
.value()));
98 if (properties
.has_arguments())
99 message
.append(base::UTF16ToUTF8(properties
.arguments
));
101 if (properties
.pin_to_taskbar
&&
102 base::win::GetVersion() >= base::win::VERSION_WIN7
) {
103 message
.append(" and pinning to the taskbar");
106 if (properties
.pin_to_start
&&
107 base::win::GetVersion() >= base::win::VERSION_WIN10
) {
108 message
.append(" and pinning to Start");
111 message
.push_back('.');
114 LOG(WARNING
) << message
;
119 void ExecuteAndLogShortcutOperation(
120 ShellUtil::ShortcutLocation location
,
121 BrowserDistribution
* dist
,
122 const ShellUtil::ShortcutProperties
& properties
,
123 ShellUtil::ShortcutOperation operation
) {
124 LogShortcutOperation(location
, dist
, properties
, operation
, false);
125 if (!ShellUtil::CreateOrUpdateShortcut(location
, dist
, properties
,
127 LogShortcutOperation(location
, dist
, properties
, operation
, true);
131 void AddChromeToMediaPlayerList() {
132 base::string16
reg_path(installer::kMediaPlayerRegPath
);
133 // registry paths can also be appended like file system path
134 reg_path
.push_back(base::FilePath::kSeparators
[0]);
135 reg_path
.append(installer::kChromeExe
);
136 VLOG(1) << "Adding Chrome to Media player list at " << reg_path
;
137 scoped_ptr
<WorkItem
> work_item(WorkItem::CreateCreateRegKeyWorkItem(
138 HKEY_LOCAL_MACHINE
, reg_path
, WorkItem::kWow64Default
));
140 // if the operation fails we log the error but still continue
141 if (!work_item
.get()->Do())
142 LOG(ERROR
) << "Could not add Chrome to media player inclusion list.";
145 // Copy master_preferences file provided to installer, in the same folder
146 // as chrome.exe so Chrome first run can find it. This function will be called
147 // only on the first install of Chrome.
148 void CopyPreferenceFileForFirstRun(
149 const installer::InstallerState
& installer_state
,
150 const base::FilePath
& prefs_source_path
) {
151 base::FilePath
prefs_dest_path(installer_state
.target_path().AppendASCII(
152 installer::kDefaultMasterPrefs
));
153 if (!base::CopyFile(prefs_source_path
, prefs_dest_path
)) {
154 VLOG(1) << "Failed to copy master preferences from:"
155 << prefs_source_path
.value() << " gle: " << ::GetLastError();
159 // This function installs a new version of Chrome to the specified location.
161 // setup_path: Path to the executable (setup.exe) as it will be copied
162 // to Chrome install folder after install is complete
163 // archive_path: Path to the archive (chrome.7z) as it will be copied
164 // to Chrome install folder after install is complete
165 // src_path: the path that contains a complete and unpacked Chrome package
167 // temp_path: the path of working directory used during installation. This path
168 // does not need to exist.
169 // new_version: new Chrome version that needs to be installed
170 // current_version: returns the current active version (if any)
172 // This function makes best effort to do installation in a transactional
173 // manner. If failed it tries to rollback all changes on the file system
174 // and registry. For example, if package exists before calling the
175 // function, it rolls back all new file and directory changes under
176 // package. If package does not exist before calling the function
177 // (typical new install), the function creates package during install
178 // and removes the whole directory during rollback.
179 installer::InstallStatus
InstallNewVersion(
180 const installer::InstallationState
& original_state
,
181 const installer::InstallerState
& installer_state
,
182 const base::FilePath
& setup_path
,
183 const base::FilePath
& archive_path
,
184 const base::FilePath
& src_path
,
185 const base::FilePath
& temp_path
,
186 const Version
& new_version
,
187 scoped_ptr
<Version
>* current_version
) {
188 DCHECK(current_version
);
190 installer_state
.UpdateStage(installer::BUILDING
);
192 current_version
->reset(installer_state
.GetCurrentVersion(original_state
));
193 scoped_ptr
<WorkItemList
> install_list(WorkItem::CreateWorkItemList());
195 AddInstallWorkItems(original_state
,
201 current_version
->get(),
205 base::FilePath
new_chrome_exe(
206 installer_state
.target_path().Append(installer::kChromeNewExe
));
208 installer_state
.UpdateStage(installer::EXECUTING
);
210 if (!install_list
->Do()) {
211 installer_state
.UpdateStage(installer::ROLLINGBACK
);
212 installer::InstallStatus result
=
213 base::PathExists(new_chrome_exe
) && current_version
->get() &&
214 new_version
.Equals(*current_version
->get()) ?
215 installer::SAME_VERSION_REPAIR_FAILED
:
216 installer::INSTALL_FAILED
;
217 LOG(ERROR
) << "Install failed, rolling back... result: " << result
;
218 install_list
->Rollback();
219 LOG(ERROR
) << "Rollback complete. ";
223 installer_state
.UpdateStage(installer::REFRESHING_POLICY
);
225 installer::RefreshElevationPolicy();
227 if (!current_version
->get()) {
228 VLOG(1) << "First install of version " << new_version
.GetString();
229 return installer::FIRST_INSTALL_SUCCESS
;
232 if (new_version
.Equals(**current_version
)) {
233 VLOG(1) << "Install repaired of version " << new_version
.GetString();
234 return installer::INSTALL_REPAIRED
;
237 if (new_version
.CompareTo(**current_version
) > 0) {
238 if (base::PathExists(new_chrome_exe
)) {
239 VLOG(1) << "Version updated to " << new_version
.GetString()
240 << " while running " << (*current_version
)->GetString();
241 return installer::IN_USE_UPDATED
;
243 VLOG(1) << "Version updated to " << new_version
.GetString();
244 return installer::NEW_VERSION_UPDATED
;
247 LOG(ERROR
) << "Not sure how we got here while updating"
248 << ", new version: " << new_version
.GetString()
249 << ", old version: " << (*current_version
)->GetString();
251 return installer::INSTALL_FAILED
;
256 namespace installer
{
258 void EscapeXmlAttributeValueInSingleQuotes(base::string16
* att_value
) {
259 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("&"),
260 base::ASCIIToUTF16("&"), att_value
);
261 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("'"),
262 base::ASCIIToUTF16("'"), att_value
);
263 base::ReplaceChars(*att_value
, base::ASCIIToUTF16("<"),
264 base::ASCIIToUTF16("<"), att_value
);
267 bool CreateVisualElementsManifest(const base::FilePath
& src_path
,
268 const Version
& version
) {
269 // Construct the relative path to the versioned VisualElements directory.
270 base::string16
elements_dir(base::ASCIIToUTF16(version
.GetString()));
271 elements_dir
.push_back(base::FilePath::kSeparators
[0]);
272 elements_dir
.append(installer::kVisualElements
);
274 // Some distributions of Chromium may not include visual elements. Only
275 // proceed if this distribution does.
276 if (!base::PathExists(src_path
.Append(elements_dir
))) {
277 VLOG(1) << "No visual elements found, not writing "
278 << installer::kVisualElementsManifest
<< " to " << src_path
.value();
281 // A printf-style format string for generating the visual elements
282 // manifest. Required arguments, in order, are:
283 // - Localized display name for the product.
284 // - Relative path to the VisualElements directory, three times.
285 static const char kManifestTemplate
[] =
287 " <VisualElements\r\n"
288 " DisplayName='%ls'\r\n"
289 " Logo='%ls\\Logo.png'\r\n"
290 " SmallLogo='%ls\\SmallLogo.png'\r\n"
291 " ForegroundText='light'\r\n"
292 " BackgroundColor='#323232'>\r\n"
293 " <DefaultTile ShowName='allLogos'/>\r\n"
294 " <SplashScreen Image='%ls\\splash-620x300.png'/>\r\n"
295 " </VisualElements>\r\n"
298 const base::string16
manifest_template(
299 base::ASCIIToUTF16(kManifestTemplate
));
301 BrowserDistribution
* dist
= BrowserDistribution::GetSpecificDistribution(
302 BrowserDistribution::CHROME_BROWSER
);
303 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
304 // resource for |display_name|.
305 base::string16
display_name(dist
->GetDisplayName());
306 EscapeXmlAttributeValueInSingleQuotes(&display_name
);
308 // Fill the manifest with the desired values.
309 base::string16
manifest16(base::StringPrintf(
310 manifest_template
.c_str(), display_name
.c_str(), elements_dir
.c_str(),
311 elements_dir
.c_str(), elements_dir
.c_str()));
313 // Write the manifest to |src_path|.
314 const std::string
manifest(base::UTF16ToUTF8(manifest16
));
315 int size
= base::checked_cast
<int>(manifest
.size());
317 src_path
.Append(installer::kVisualElementsManifest
),
318 manifest
.c_str(), size
) == size
) {
319 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
320 << " to " << src_path
.value();
323 PLOG(ERROR
) << "Error writing " << installer::kVisualElementsManifest
324 << " to " << src_path
.value();
330 void CreateOrUpdateShortcuts(
331 const base::FilePath
& target
,
332 const installer::Product
& product
,
333 const MasterPreferences
& prefs
,
334 InstallShortcutLevel install_level
,
335 InstallShortcutOperation install_operation
) {
336 bool do_not_create_any_shortcuts
= false;
337 prefs
.GetBool(master_preferences::kDoNotCreateAnyShortcuts
,
338 &do_not_create_any_shortcuts
);
339 if (do_not_create_any_shortcuts
)
342 // Extract shortcut preferences from |prefs|.
343 bool do_not_create_desktop_shortcut
= false;
344 bool do_not_create_quick_launch_shortcut
= false;
345 bool do_not_create_taskbar_shortcut
= false;
346 bool do_not_create_start_pin
= false;
347 bool alternate_desktop_shortcut
= false;
348 prefs
.GetBool(master_preferences::kDoNotCreateDesktopShortcut
,
349 &do_not_create_desktop_shortcut
);
350 prefs
.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut
,
351 &do_not_create_quick_launch_shortcut
);
352 prefs
.GetBool(master_preferences::kDoNotCreateTaskbarShortcut
,
353 &do_not_create_taskbar_shortcut
);
354 prefs
.GetBool(master_preferences::kDoNotCreateStartPin
,
355 &do_not_create_start_pin
);
356 prefs
.GetBool(master_preferences::kAltShortcutText
,
357 &alternate_desktop_shortcut
);
359 BrowserDistribution
* dist
= product
.distribution();
361 // The default operation on update is to overwrite shortcuts with the
362 // currently desired properties, but do so only for shortcuts that still
364 ShellUtil::ShortcutOperation shortcut_operation
;
365 switch (install_operation
) {
366 case INSTALL_SHORTCUT_CREATE_ALL
:
367 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
;
369 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
:
370 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
;
373 DCHECK(install_operation
== INSTALL_SHORTCUT_REPLACE_EXISTING
);
374 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
;
378 // Shortcuts are always installed per-user unless specified.
379 ShellUtil::ShellChange shortcut_level
= (install_level
== ALL_USERS
?
380 ShellUtil::SYSTEM_LEVEL
: ShellUtil::CURRENT_USER
);
382 // |base_properties|: The basic properties to set on every shortcut installed
383 // (to be refined on a per-shortcut basis).
384 ShellUtil::ShortcutProperties
base_properties(shortcut_level
);
385 product
.AddDefaultShortcutProperties(target
, &base_properties
);
387 if (!do_not_create_desktop_shortcut
||
388 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
389 ShellUtil::ShortcutProperties
desktop_properties(base_properties
);
390 if (alternate_desktop_shortcut
) {
391 desktop_properties
.set_shortcut_name(
392 dist
->GetShortcutName(
393 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
395 ExecuteAndLogShortcutOperation(
396 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
399 // On update there is no harm in always trying to update the alternate
401 if (!alternate_desktop_shortcut
&&
402 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
403 desktop_properties
.set_shortcut_name(
404 dist
->GetShortcutName(
405 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
406 ExecuteAndLogShortcutOperation(
407 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
412 if (!do_not_create_quick_launch_shortcut
||
413 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
414 // There is no such thing as an all-users Quick Launch shortcut, always
415 // install the per-user shortcut.
416 ShellUtil::ShortcutProperties
quick_launch_properties(base_properties
);
417 quick_launch_properties
.level
= ShellUtil::CURRENT_USER
;
418 ExecuteAndLogShortcutOperation(
419 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
, dist
,
420 quick_launch_properties
, shortcut_operation
);
423 ShellUtil::ShortcutProperties
start_menu_properties(base_properties
);
424 // IMPORTANT: Only the default (no arguments and default browserappid) browser
425 // shortcut in the Start menu (Start screen on Win8+) should be made dual
426 // mode and that prior to Windows 10 only.
427 if (InstallUtil::ShouldInstallMetroProperties())
428 start_menu_properties
.set_dual_mode(true);
429 if (shortcut_operation
== ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
||
430 shortcut_operation
==
431 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
) {
432 start_menu_properties
.set_pin_to_taskbar(!do_not_create_taskbar_shortcut
);
433 // Disabled for now. TODO(gab): Remove this and the associated code if it
434 // remains disabled long term.
435 start_menu_properties
.set_pin_to_start(false);
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);
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
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
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
,
499 // TODO(robertshield): Everything below this line should instead be captured
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
));
523 // Install per-user shortcuts on user-level installs and all-users
524 // shortcuts on system-level installs. Note that Active Setup will take
525 // care of installing missing per-user shortcuts on system-level install
526 // (i.e., quick launch, taskbar pin, and possibly deleted all-users
528 InstallShortcutLevel install_level
= installer_state
.system_install() ?
529 ALL_USERS
: CURRENT_USER
;
531 InstallShortcutOperation install_operation
=
532 INSTALL_SHORTCUT_REPLACE_EXISTING
;
533 if (result
== installer::FIRST_INSTALL_SUCCESS
||
534 result
== installer::INSTALL_REPAIRED
||
535 !original_state
.GetProductState(installer_state
.system_install(),
536 chrome_dist
->GetType())) {
537 // Always create the shortcuts on a new install, a repair install, and
538 // when the Chrome product is being added to the current install.
539 install_operation
= INSTALL_SHORTCUT_CREATE_ALL
;
542 CreateOrUpdateShortcuts(chrome_exe
, *chrome_product
, prefs
, install_level
,
546 if (chrome_product
) {
547 // Register Chrome and, if requested, make Chrome the default browser.
548 installer_state
.UpdateStage(installer::REGISTERING_CHROME
);
550 bool make_chrome_default
= false;
551 prefs
.GetBool(master_preferences::kMakeChromeDefault
,
552 &make_chrome_default
);
554 // If this is not the user's first Chrome install, but they have chosen
555 // Chrome to become their default browser on the download page, we must
556 // force it here because the master_preferences file will not get copied
558 bool force_chrome_default_for_user
= false;
559 if (result
== NEW_VERSION_UPDATED
||
560 result
== INSTALL_REPAIRED
) {
561 prefs
.GetBool(master_preferences::kMakeChromeDefaultForUser
,
562 &force_chrome_default_for_user
);
565 RegisterChromeOnMachine(installer_state
, *chrome_product
,
566 make_chrome_default
|| force_chrome_default_for_user
);
568 // Configure auto-launch.
569 if (result
== FIRST_INSTALL_SUCCESS
) {
570 installer_state
.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH
);
572 // Add auto-launch key if specified in master_preferences.
573 bool auto_launch_chrome
= false;
575 installer::master_preferences::kAutoLaunchChrome
,
576 &auto_launch_chrome
);
577 if (auto_launch_chrome
) {
578 auto_launch_util::EnableForegroundStartAtLogin(
579 base::ASCIIToUTF16(chrome::kInitialProfile
),
580 installer_state
.target_path());
584 if (!installer_state
.system_install()) {
585 DCHECK_EQ(chrome_product
->distribution(),
586 BrowserDistribution::GetDistribution());
587 UpdateDefaultBrowserBeaconForPath(
588 installer_state
.target_path().Append(installer::kChromeExe
));
592 installer_state
.UpdateStage(installer::REMOVING_OLD_VERSIONS
);
594 installer_state
.RemoveOldVersionDirectories(
596 existing_version
.get(),
603 void HandleOsUpgradeForBrowser(const installer::InstallerState
& installer_state
,
604 const installer::Product
& chrome
,
605 const base::Version
& installed_version
) {
606 DCHECK(chrome
.is_chrome());
608 VLOG(1) << "Updating and registering shortcuts for --on-os-upgrade.";
610 // Read master_preferences copied beside chrome.exe at install.
611 const MasterPreferences
prefs(
612 installer_state
.target_path().AppendASCII(kDefaultMasterPrefs
));
614 // Update shortcuts at this install level (per-user shortcuts on system-level
615 // installs will be updated through Active Setup).
616 const InstallShortcutLevel level
=
617 installer_state
.system_install() ? ALL_USERS
: CURRENT_USER
;
618 const base::FilePath
chrome_exe(
619 installer_state
.target_path().Append(kChromeExe
));
620 CreateOrUpdateShortcuts(chrome_exe
, chrome
, prefs
, level
,
621 INSTALL_SHORTCUT_REPLACE_EXISTING
);
623 // Adapt Chrome registrations to this new OS.
624 RegisterChromeOnMachine(installer_state
, chrome
, false);
626 // Active Setup registrations are sometimes lost across OS update, make sure
627 // they're back in place. Note: when Active Setup registrations in HKLM are
628 // lost, the per-user values of performed Active Setups in HKCU are also lost,
629 // so it is fine to restart the dynamic components of the Active Setup version
630 // (ref. UpdateActiveSetupVersionWorkItem) from scratch.
631 // TODO(gab): This should really perform all registry only update steps (i.e.,
632 // something between InstallOrUpdateProduct and AddActiveSetupWorkItems, but
633 // this takes care of what is most required for now).
634 scoped_ptr
<WorkItemList
> work_item_list(WorkItem::CreateWorkItemList());
635 AddActiveSetupWorkItems(installer_state
, installed_version
, chrome
,
636 work_item_list
.get());
637 if (!work_item_list
->Do()) {
638 LOG(WARNING
) << "Failed to reinstall Active Setup keys.";
639 work_item_list
->Rollback();
642 UpdateOsUpgradeBeacon(installer_state
.system_install(),
643 BrowserDistribution::GetDistribution());
645 // Update the per-user default browser beacon. For user-level installs this
646 // can be done directly; whereas it requires triggering Active Setup for each
647 // user's subsequent login on system-level installs.
648 if (!installer_state
.system_install()) {
649 UpdateDefaultBrowserBeaconForPath(chrome_exe
);
651 UpdateActiveSetupVersionWorkItem
active_setup_work_item(
652 InstallUtil::GetActiveSetupPath(chrome
.distribution()),
653 UpdateActiveSetupVersionWorkItem::
654 UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT
);
655 if (active_setup_work_item
.Do())
656 VLOG(1) << "Bumped Active Setup Version on-os-upgrade.";
658 LOG(ERROR
) << "Failed to bump Active Setup Version on-os-upgrade.";
662 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
663 // in update_active_setup_version_work_item.cc needs to be increased for Active
664 // Setup to invoke this again for all users of this install. It may also be
665 // invoked again when a system-level chrome install goes through an OS upgrade.
666 void HandleActiveSetupForBrowser(const base::FilePath
& installation_root
,
667 const installer::Product
& chrome
,
669 DCHECK(chrome
.is_chrome());
671 // Only create shortcuts on Active Setup if the first run sentinel is not
672 // present for this user (as some shortcuts used to be installed on first
673 // run and this could otherwise re-install shortcuts for users that have
674 // already deleted them in the past).
675 // Decide whether to create the shortcuts or simply replace existing
676 // shortcuts; if the decision is to create them, only shortcuts whose matching
677 // all-users shortcut isn't present on the system will be created.
678 InstallShortcutOperation install_operation
=
679 (!force
&& InstallUtil::IsFirstRunSentinelPresent())
680 ? INSTALL_SHORTCUT_REPLACE_EXISTING
681 : INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
;
683 // Read master_preferences copied beside chrome.exe at install.
684 MasterPreferences
prefs(installation_root
.AppendASCII(kDefaultMasterPrefs
));
685 base::FilePath
chrome_exe(installation_root
.Append(kChromeExe
));
686 CreateOrUpdateShortcuts(
687 chrome_exe
, chrome
, prefs
, CURRENT_USER
, install_operation
);
689 UpdateDefaultBrowserBeaconForPath(chrome_exe
);
692 } // namespace installer