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/command_line.h"
14 #include "base/file_util.h"
15 #include "base/files/file_path.h"
16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/numerics/safe_conversions.h"
19 #include "base/path_service.h"
20 #include "base/process/launch.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/win/shortcut.h"
25 #include "base/win/windows_version.h"
26 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
29 #include "chrome/installer/setup/install_worker.h"
30 #include "chrome/installer/setup/setup_constants.h"
31 #include "chrome/installer/util/auto_launch_util.h"
32 #include "chrome/installer/util/browser_distribution.h"
33 #include "chrome/installer/util/create_reg_key_work_item.h"
34 #include "chrome/installer/util/delete_after_reboot_helper.h"
35 #include "chrome/installer/util/google_update_constants.h"
36 #include "chrome/installer/util/helper.h"
37 #include "chrome/installer/util/install_util.h"
38 #include "chrome/installer/util/master_preferences.h"
39 #include "chrome/installer/util/master_preferences_constants.h"
40 #include "chrome/installer/util/set_reg_value_work_item.h"
41 #include "chrome/installer/util/shell_util.h"
42 #include "chrome/installer/util/util_constants.h"
43 #include "chrome/installer/util/work_item_list.h"
45 // Build-time generated include file.
46 #include "registered_dlls.h" // NOLINT
48 using base::ASCIIToUTF16
;
49 using base::UTF16ToUTF8
;
50 using installer::InstallerState
;
51 using installer::InstallationState
;
52 using installer::Product
;
56 void LogShortcutOperation(ShellUtil::ShortcutLocation location
,
57 BrowserDistribution
* dist
,
58 const ShellUtil::ShortcutProperties
& properties
,
59 ShellUtil::ShortcutOperation operation
,
61 // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and
62 // thus this method does not handle logging a message for it.
63 DCHECK(operation
!= ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING
);
66 message
.append("Failed: ");
68 (operation
== ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
||
69 operation
== ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
) ?
70 "Creating " : "Overwriting ");
71 if (failed
&& operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
)
72 message
.append("(maybe the shortcut doesn't exist?) ");
73 message
.append((properties
.level
== ShellUtil::CURRENT_USER
) ? "per-user " :
76 case ShellUtil::SHORTCUT_LOCATION_DESKTOP
:
77 message
.append("Desktop ");
79 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
:
80 message
.append("Quick Launch ");
82 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
:
83 message
.append("Start menu/" +
84 UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
85 BrowserDistribution::SUBFOLDER_CHROME
)) +
88 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
:
89 message
.append("Start menu/" +
90 UTF16ToUTF8(dist
->GetStartMenuShortcutSubfolder(
91 BrowserDistribution::SUBFOLDER_APPS
)) +
98 message
.push_back('"');
99 if (properties
.has_shortcut_name())
100 message
.append(UTF16ToUTF8(properties
.shortcut_name
));
102 message
.append(UTF16ToUTF8(dist
->GetDisplayName()));
103 message
.push_back('"');
105 message
.append(" shortcut to ");
106 message
.append(UTF16ToUTF8(properties
.target
.value()));
107 if (properties
.has_arguments())
108 message
.append(UTF16ToUTF8(properties
.arguments
));
110 if (properties
.pin_to_taskbar
&&
111 base::win::GetVersion() >= base::win::VERSION_WIN7
) {
112 message
.append(" and pinning to the taskbar.");
114 message
.push_back('.');
118 LOG(WARNING
) << message
;
123 void ExecuteAndLogShortcutOperation(
124 ShellUtil::ShortcutLocation location
,
125 BrowserDistribution
* dist
,
126 const ShellUtil::ShortcutProperties
& properties
,
127 ShellUtil::ShortcutOperation operation
) {
128 LogShortcutOperation(location
, dist
, properties
, operation
, false);
129 if (!ShellUtil::CreateOrUpdateShortcut(location
, dist
, properties
,
131 LogShortcutOperation(location
, dist
, properties
, operation
, true);
135 void AddChromeToMediaPlayerList() {
136 base::string16
reg_path(installer::kMediaPlayerRegPath
);
137 // registry paths can also be appended like file system path
138 reg_path
.push_back(base::FilePath::kSeparators
[0]);
139 reg_path
.append(installer::kChromeExe
);
140 VLOG(1) << "Adding Chrome to Media player list at " << reg_path
;
141 scoped_ptr
<WorkItem
> work_item(WorkItem::CreateCreateRegKeyWorkItem(
142 HKEY_LOCAL_MACHINE
, reg_path
));
144 // if the operation fails we log the error but still continue
145 if (!work_item
.get()->Do())
146 LOG(ERROR
) << "Could not add Chrome to media player inclusion list.";
149 // Copy master_preferences file provided to installer, in the same folder
150 // as chrome.exe so Chrome first run can find it. This function will be called
151 // only on the first install of Chrome.
152 void CopyPreferenceFileForFirstRun(const InstallerState
& installer_state
,
153 const base::FilePath
& prefs_source_path
) {
154 base::FilePath
prefs_dest_path(installer_state
.target_path().AppendASCII(
155 installer::kDefaultMasterPrefs
));
156 if (!base::CopyFile(prefs_source_path
, prefs_dest_path
)) {
157 VLOG(1) << "Failed to copy master preferences from:"
158 << prefs_source_path
.value() << " gle: " << ::GetLastError();
162 // This function installs a new version of Chrome to the specified location.
164 // setup_path: Path to the executable (setup.exe) as it will be copied
165 // to Chrome install folder after install is complete
166 // archive_path: Path to the archive (chrome.7z) as it will be copied
167 // to Chrome install folder after install is complete
168 // src_path: the path that contains a complete and unpacked Chrome package
170 // temp_path: the path of working directory used during installation. This path
171 // does not need to exist.
172 // new_version: new Chrome version that needs to be installed
173 // current_version: returns the current active version (if any)
175 // This function makes best effort to do installation in a transactional
176 // manner. If failed it tries to rollback all changes on the file system
177 // and registry. For example, if package exists before calling the
178 // function, it rolls back all new file and directory changes under
179 // package. If package does not exist before calling the function
180 // (typical new install), the function creates package during install
181 // and removes the whole directory during rollback.
182 installer::InstallStatus
InstallNewVersion(
183 const InstallationState
& original_state
,
184 const InstallerState
& installer_state
,
185 const base::FilePath
& setup_path
,
186 const base::FilePath
& archive_path
,
187 const base::FilePath
& src_path
,
188 const base::FilePath
& temp_path
,
189 const Version
& new_version
,
190 scoped_ptr
<Version
>* current_version
) {
191 DCHECK(current_version
);
193 installer_state
.UpdateStage(installer::BUILDING
);
195 current_version
->reset(installer_state
.GetCurrentVersion(original_state
));
196 scoped_ptr
<WorkItemList
> install_list(WorkItem::CreateWorkItemList());
198 AddInstallWorkItems(original_state
,
204 current_version
->get(),
208 base::FilePath
new_chrome_exe(
209 installer_state
.target_path().Append(installer::kChromeNewExe
));
211 installer_state
.UpdateStage(installer::EXECUTING
);
213 if (!install_list
->Do()) {
214 installer_state
.UpdateStage(installer::ROLLINGBACK
);
215 installer::InstallStatus result
=
216 base::PathExists(new_chrome_exe
) && current_version
->get() &&
217 new_version
.Equals(*current_version
->get()) ?
218 installer::SAME_VERSION_REPAIR_FAILED
:
219 installer::INSTALL_FAILED
;
220 LOG(ERROR
) << "Install failed, rolling back... result: " << result
;
221 install_list
->Rollback();
222 LOG(ERROR
) << "Rollback complete. ";
226 installer_state
.UpdateStage(installer::REFRESHING_POLICY
);
228 installer::RefreshElevationPolicy();
230 if (!current_version
->get()) {
231 VLOG(1) << "First install of version " << new_version
.GetString();
232 return installer::FIRST_INSTALL_SUCCESS
;
235 if (new_version
.Equals(**current_version
)) {
236 VLOG(1) << "Install repaired of version " << new_version
.GetString();
237 return installer::INSTALL_REPAIRED
;
240 if (new_version
.CompareTo(**current_version
) > 0) {
241 if (base::PathExists(new_chrome_exe
)) {
242 VLOG(1) << "Version updated to " << new_version
.GetString()
243 << " while running " << (*current_version
)->GetString();
244 return installer::IN_USE_UPDATED
;
246 VLOG(1) << "Version updated to " << new_version
.GetString();
247 return installer::NEW_VERSION_UPDATED
;
250 LOG(ERROR
) << "Not sure how we got here while updating"
251 << ", new version: " << new_version
.GetString()
252 << ", old version: " << (*current_version
)->GetString();
254 return installer::INSTALL_FAILED
;
257 // Deletes the old "Uninstall Google Chrome" shortcut in the Start menu and, if
258 // this is a system-level install, also deletes the old Default user Quick
259 // Launch shortcut. Both of these were created prior to Chrome 24; in Chrome 24,
260 // the uninstall shortcut was removed and the Default user Quick Launch shortcut
261 // was replaced by per-user shortcuts created via Active Setup.
262 void CleanupLegacyShortcuts(const InstallerState
& installer_state
,
263 BrowserDistribution
* dist
,
264 const base::FilePath
& chrome_exe
) {
265 ShellUtil::ShellChange shortcut_level
= installer_state
.system_install() ?
266 ShellUtil::SYSTEM_LEVEL
: ShellUtil::CURRENT_USER
;
267 base::FilePath uninstall_shortcut_path
;
268 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
,
269 dist
, shortcut_level
, &uninstall_shortcut_path
);
270 uninstall_shortcut_path
= uninstall_shortcut_path
.Append(
271 dist
->GetUninstallLinkName() + installer::kLnkExt
);
272 base::DeleteFile(uninstall_shortcut_path
, false);
274 if (installer_state
.system_install()) {
275 ShellUtil::RemoveShortcuts(
276 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
, dist
,
277 ShellUtil::SYSTEM_LEVEL
, chrome_exe
);
281 // Returns the appropriate shortcut operations for App Launcher,
282 // based on state of installation and master_preferences.
283 installer::InstallShortcutOperation
GetAppLauncherShortcutOperation(
284 const InstallationState
& original_state
,
285 const InstallerState
& installer_state
) {
286 const installer::ProductState
* original_app_host_state
=
287 original_state
.GetProductState(installer_state
.system_install(),
288 BrowserDistribution::CHROME_APP_HOST
);
289 bool app_launcher_exists
= original_app_host_state
&&
290 original_app_host_state
->uninstall_command()
291 .HasSwitch(installer::switches::kChromeAppLauncher
);
292 if (!app_launcher_exists
)
293 return installer::INSTALL_SHORTCUT_CREATE_ALL
;
295 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING
;
300 namespace installer
{
302 void EscapeXmlAttributeValueInSingleQuotes(base::string16
* att_value
) {
303 base::ReplaceChars(*att_value
, L
"&", L
"&", att_value
);
304 base::ReplaceChars(*att_value
, L
"'", L
"'", att_value
);
305 base::ReplaceChars(*att_value
, L
"<", L
"<", att_value
);
308 bool CreateVisualElementsManifest(const base::FilePath
& src_path
,
309 const Version
& version
) {
310 // Construct the relative path to the versioned VisualElements directory.
311 base::string16
elements_dir(ASCIIToUTF16(version
.GetString()));
312 elements_dir
.push_back(base::FilePath::kSeparators
[0]);
313 elements_dir
.append(installer::kVisualElements
);
315 // Some distributions of Chromium may not include visual elements. Only
316 // proceed if this distribution does.
317 if (!base::PathExists(src_path
.Append(elements_dir
))) {
318 VLOG(1) << "No visual elements found, not writing "
319 << installer::kVisualElementsManifest
<< " to " << src_path
.value();
322 // A printf_p-style format string for generating the visual elements
323 // manifest. Required arguments, in order, are:
324 // - Localized display name for the product.
325 // - Relative path to the VisualElements directory.
326 static const char kManifestTemplate
[] =
328 " <VisualElements\r\n"
329 " DisplayName='%1$ls'\r\n"
330 " Logo='%2$ls\\Logo.png'\r\n"
331 " SmallLogo='%2$ls\\SmallLogo.png'\r\n"
332 " ForegroundText='light'\r\n"
333 " BackgroundColor='#323232'>\r\n"
334 " <DefaultTile ShowName='allLogos'/>\r\n"
335 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
336 " </VisualElements>\r\n"
339 const base::string16
manifest_template(ASCIIToUTF16(kManifestTemplate
));
341 BrowserDistribution
* dist
= BrowserDistribution::GetSpecificDistribution(
342 BrowserDistribution::CHROME_BROWSER
);
343 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
344 // resource for |display_name|.
345 base::string16
display_name(dist
->GetDisplayName());
346 EscapeXmlAttributeValueInSingleQuotes(&display_name
);
348 // Fill the manifest with the desired values.
349 base::string16
manifest16(base::StringPrintf(
350 manifest_template
.c_str(), display_name
.c_str(), elements_dir
.c_str()));
352 // Write the manifest to |src_path|.
353 const std::string
manifest(UTF16ToUTF8(manifest16
));
354 int size
= base::checked_cast
<int>(manifest
.size());
355 if (file_util::WriteFile(
356 src_path
.Append(installer::kVisualElementsManifest
),
357 manifest
.c_str(), size
) == size
) {
358 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
359 << " to " << src_path
.value();
362 PLOG(ERROR
) << "Error writing " << installer::kVisualElementsManifest
363 << " to " << src_path
.value();
369 void CreateOrUpdateShortcuts(
370 const base::FilePath
& target
,
371 const Product
& product
,
372 const MasterPreferences
& prefs
,
373 InstallShortcutLevel install_level
,
374 InstallShortcutOperation install_operation
) {
375 bool do_not_create_any_shortcuts
= false;
376 prefs
.GetBool(master_preferences::kDoNotCreateAnyShortcuts
,
377 &do_not_create_any_shortcuts
);
378 if (do_not_create_any_shortcuts
)
381 // Extract shortcut preferences from |prefs|.
382 bool do_not_create_desktop_shortcut
= false;
383 bool do_not_create_quick_launch_shortcut
= false;
384 bool do_not_create_taskbar_shortcut
= false;
385 bool alternate_desktop_shortcut
= false;
386 prefs
.GetBool(master_preferences::kDoNotCreateDesktopShortcut
,
387 &do_not_create_desktop_shortcut
);
388 prefs
.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut
,
389 &do_not_create_quick_launch_shortcut
);
390 prefs
.GetBool(master_preferences::kDoNotCreateTaskbarShortcut
,
391 &do_not_create_taskbar_shortcut
);
392 prefs
.GetBool(master_preferences::kAltShortcutText
,
393 &alternate_desktop_shortcut
);
395 BrowserDistribution
* dist
= product
.distribution();
397 // The default operation on update is to overwrite shortcuts with the
398 // currently desired properties, but do so only for shortcuts that still
400 ShellUtil::ShortcutOperation shortcut_operation
;
401 switch (install_operation
) {
402 case INSTALL_SHORTCUT_CREATE_ALL
:
403 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
;
405 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
:
406 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
;
409 DCHECK(install_operation
== INSTALL_SHORTCUT_REPLACE_EXISTING
);
410 shortcut_operation
= ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
;
414 // Shortcuts are always installed per-user unless specified.
415 ShellUtil::ShellChange shortcut_level
= (install_level
== ALL_USERS
?
416 ShellUtil::SYSTEM_LEVEL
: ShellUtil::CURRENT_USER
);
418 // |base_properties|: The basic properties to set on every shortcut installed
419 // (to be refined on a per-shortcut basis).
420 ShellUtil::ShortcutProperties
base_properties(shortcut_level
);
421 product
.AddDefaultShortcutProperties(target
, &base_properties
);
423 if (!do_not_create_desktop_shortcut
||
424 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
425 ShellUtil::ShortcutProperties
desktop_properties(base_properties
);
426 if (alternate_desktop_shortcut
) {
427 desktop_properties
.set_shortcut_name(
428 dist
->GetShortcutName(
429 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
431 ExecuteAndLogShortcutOperation(
432 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
435 // On update there is no harm in always trying to update the alternate
437 if (!alternate_desktop_shortcut
&&
438 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
439 desktop_properties
.set_shortcut_name(
440 dist
->GetShortcutName(
441 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE
));
442 ExecuteAndLogShortcutOperation(
443 ShellUtil::SHORTCUT_LOCATION_DESKTOP
, dist
, desktop_properties
,
448 if (!do_not_create_quick_launch_shortcut
||
449 shortcut_operation
== ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING
) {
450 // There is no such thing as an all-users Quick Launch shortcut, always
451 // install the per-user shortcut.
452 ShellUtil::ShortcutProperties
quick_launch_properties(base_properties
);
453 quick_launch_properties
.level
= ShellUtil::CURRENT_USER
;
454 ExecuteAndLogShortcutOperation(
455 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
, dist
,
456 quick_launch_properties
, shortcut_operation
);
459 ShellUtil::ShortcutProperties
start_menu_properties(base_properties
);
460 // IMPORTANT: Only the default (no arguments and default browserappid) browser
461 // shortcut in the Start menu (Start screen on Win8+) should be made dual
463 start_menu_properties
.set_dual_mode(true);
464 if (!do_not_create_taskbar_shortcut
&&
465 (shortcut_operation
== ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS
||
466 shortcut_operation
==
467 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL
)) {
468 start_menu_properties
.set_pin_to_taskbar(true);
470 ExecuteAndLogShortcutOperation(
471 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
, dist
,
472 start_menu_properties
, shortcut_operation
);
475 void RegisterChromeOnMachine(const InstallerState
& installer_state
,
476 const Product
& product
,
477 bool make_chrome_default
) {
478 DCHECK(product
.is_chrome());
480 // Try to add Chrome to Media Player shim inclusion list. We don't do any
481 // error checking here because this operation will fail if user doesn't
482 // have admin rights and we want to ignore the error.
483 AddChromeToMediaPlayerList();
485 // Make Chrome the default browser if desired when possible. Otherwise, only
486 // register it with Windows.
487 BrowserDistribution
* dist
= product
.distribution();
488 const base::string16
chrome_exe(
489 installer_state
.target_path().Append(installer::kChromeExe
).value());
490 VLOG(1) << "Registering Chrome as browser: " << chrome_exe
;
491 if (make_chrome_default
&& ShellUtil::CanMakeChromeDefaultUnattended()) {
492 int level
= ShellUtil::CURRENT_USER
;
493 if (installer_state
.system_install())
494 level
= level
| ShellUtil::SYSTEM_LEVEL
;
495 ShellUtil::MakeChromeDefault(dist
, level
, chrome_exe
, true);
497 ShellUtil::RegisterChromeBrowser(dist
, chrome_exe
, base::string16(), false);
501 InstallStatus
InstallOrUpdateProduct(
502 const InstallationState
& original_state
,
503 const InstallerState
& installer_state
,
504 const base::FilePath
& setup_path
,
505 const base::FilePath
& archive_path
,
506 const base::FilePath
& install_temp_path
,
507 const base::FilePath
& src_path
,
508 const base::FilePath
& prefs_path
,
509 const MasterPreferences
& prefs
,
510 const Version
& new_version
) {
511 DCHECK(!installer_state
.products().empty());
513 // TODO(robertshield): Removing the pending on-reboot moves should be done
515 // Remove any scheduled MOVEFILE_DELAY_UNTIL_REBOOT entries in the target of
516 // this installation. These may have been added during a previous uninstall of
518 LOG_IF(ERROR
, !RemoveFromMovesPendingReboot(installer_state
.target_path()))
519 << "Error accessing pending moves value.";
521 // Create VisualElementManifest.xml in |src_path| (if required) so that it
522 // looks as if it had been extracted from the archive when calling
523 // InstallNewVersion() below.
524 installer_state
.UpdateStage(installer::CREATING_VISUAL_MANIFEST
);
525 CreateVisualElementsManifest(src_path
, new_version
);
527 scoped_ptr
<Version
> existing_version
;
528 InstallStatus result
= InstallNewVersion(original_state
, installer_state
,
529 setup_path
, archive_path
, src_path
, install_temp_path
, new_version
,
532 // TODO(robertshield): Everything below this line should instead be captured
534 if (!InstallUtil::GetInstallReturnCode(result
)) {
535 installer_state
.UpdateStage(installer::UPDATING_CHANNELS
);
537 // Update the modifiers on the channel values for the product(s) being
538 // installed and for the binaries in case of multi-install.
539 installer_state
.UpdateChannels();
541 installer_state
.UpdateStage(installer::COPYING_PREFERENCES_FILE
);
543 if (result
== FIRST_INSTALL_SUCCESS
&& !prefs_path
.empty())
544 CopyPreferenceFileForFirstRun(installer_state
, prefs_path
);
546 installer_state
.UpdateStage(installer::CREATING_SHORTCUTS
);
548 const Product
* app_launcher_product
=
549 installer_state
.FindProduct(BrowserDistribution::CHROME_APP_HOST
);
550 // Creates shortcuts for App Launcher.
551 if (app_launcher_product
) {
552 // TODO(huangs): Remove this check once we have system-level App Host.
553 DCHECK(!installer_state
.system_install());
554 const base::FilePath
app_host_exe(
555 installer_state
.target_path().Append(kChromeAppHostExe
));
556 InstallShortcutOperation app_launcher_shortcut_operation
=
557 GetAppLauncherShortcutOperation(original_state
, installer_state
);
559 // Always install per-user shortcuts for App Launcher.
560 CreateOrUpdateShortcuts(app_host_exe
, *app_launcher_product
, prefs
,
561 CURRENT_USER
, app_launcher_shortcut_operation
);
564 const Product
* chrome_product
=
565 installer_state
.FindProduct(BrowserDistribution::CHROME_BROWSER
);
566 // Creates shortcuts for Chrome.
567 if (chrome_product
) {
568 BrowserDistribution
* chrome_dist
= chrome_product
->distribution();
569 const base::FilePath
chrome_exe(
570 installer_state
.target_path().Append(kChromeExe
));
571 CleanupLegacyShortcuts(installer_state
, chrome_dist
, chrome_exe
);
573 // Install per-user shortcuts on user-level installs and all-users
574 // shortcuts on system-level installs. Note that Active Setup will take
575 // care of installing missing per-user shortcuts on system-level install
576 // (i.e., quick launch, taskbar pin, and possibly deleted all-users
578 InstallShortcutLevel install_level
= installer_state
.system_install() ?
579 ALL_USERS
: CURRENT_USER
;
581 InstallShortcutOperation install_operation
=
582 INSTALL_SHORTCUT_REPLACE_EXISTING
;
583 if (result
== installer::FIRST_INSTALL_SUCCESS
||
584 result
== installer::INSTALL_REPAIRED
||
585 !original_state
.GetProductState(installer_state
.system_install(),
586 chrome_dist
->GetType())) {
587 // Always create the shortcuts on a new install, a repair install, and
588 // when the Chrome product is being added to the current install.
589 install_operation
= INSTALL_SHORTCUT_CREATE_ALL
;
592 CreateOrUpdateShortcuts(chrome_exe
, *chrome_product
, prefs
, install_level
,
596 if (chrome_product
) {
597 // Register Chrome and, if requested, make Chrome the default browser.
598 installer_state
.UpdateStage(installer::REGISTERING_CHROME
);
600 bool make_chrome_default
= false;
601 prefs
.GetBool(master_preferences::kMakeChromeDefault
,
602 &make_chrome_default
);
604 // If this is not the user's first Chrome install, but they have chosen
605 // Chrome to become their default browser on the download page, we must
606 // force it here because the master_preferences file will not get copied
608 bool force_chrome_default_for_user
= false;
609 if (result
== NEW_VERSION_UPDATED
||
610 result
== INSTALL_REPAIRED
) {
611 prefs
.GetBool(master_preferences::kMakeChromeDefaultForUser
,
612 &force_chrome_default_for_user
);
615 RegisterChromeOnMachine(installer_state
, *chrome_product
,
616 make_chrome_default
|| force_chrome_default_for_user
);
618 // Configure auto-launch.
619 if (result
== FIRST_INSTALL_SUCCESS
) {
620 installer_state
.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH
);
622 // Add auto-launch key if specified in master_preferences.
623 bool auto_launch_chrome
= false;
625 installer::master_preferences::kAutoLaunchChrome
,
626 &auto_launch_chrome
);
627 if (auto_launch_chrome
) {
628 auto_launch_util::EnableForegroundStartAtLogin(
629 ASCIIToUTF16(chrome::kInitialProfile
),
630 installer_state
.target_path());
635 installer_state
.UpdateStage(installer::REMOVING_OLD_VERSIONS
);
637 installer_state
.RemoveOldVersionDirectories(
639 existing_version
.get(),
646 void HandleOsUpgradeForBrowser(const InstallerState
& installer_state
,
647 const Product
& chrome
) {
648 DCHECK(chrome
.is_chrome());
649 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
650 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
651 if (base::win::GetVersion() >= base::win::VERSION_WIN8
) {
652 VLOG(1) << "Updating and registering shortcuts.";
653 // Read master_preferences copied beside chrome.exe at install.
654 MasterPreferences
prefs(
655 installer_state
.target_path().AppendASCII(kDefaultMasterPrefs
));
657 // Unfortunately, if this is a system-level install, we can't update the
658 // shortcuts of each individual user (this only matters if this is an OS
659 // upgrade from XP/Vista to Win7+ as some properties are only set on
660 // shortcuts as of Win7).
661 // At least attempt to update potentially existing all-users shortcuts.
662 InstallShortcutLevel level
= installer_state
.system_install() ?
663 ALL_USERS
: CURRENT_USER
;
664 base::FilePath
chrome_exe(installer_state
.target_path().Append(kChromeExe
));
665 CreateOrUpdateShortcuts(
666 chrome_exe
, chrome
, prefs
, level
, INSTALL_SHORTCUT_REPLACE_EXISTING
);
667 RegisterChromeOnMachine(installer_state
, chrome
, false);
671 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
672 // in install_worker.cc needs to be increased for Active Setup to invoke this
673 // again for all users of this install.
674 void HandleActiveSetupForBrowser(const base::FilePath
& installation_root
,
675 const Product
& chrome
,
677 DCHECK(chrome
.is_chrome());
678 // Only create shortcuts on Active Setup if the first run sentinel is not
679 // present for this user (as some shortcuts used to be installed on first
680 // run and this could otherwise re-install shortcuts for users that have
681 // already deleted them in the past).
682 base::FilePath first_run_sentinel
;
683 InstallUtil::GetSentinelFilePath(
684 chrome::kFirstRunSentinel
, chrome
.distribution(), &first_run_sentinel
);
685 // Decide whether to create the shortcuts or simply replace existing
686 // shortcuts; if the decision is to create them, only shortcuts whose matching
687 // all-users shortcut isn't present on the system will be created.
688 InstallShortcutOperation install_operation
=
689 (!force
&& base::PathExists(first_run_sentinel
) ?
690 INSTALL_SHORTCUT_REPLACE_EXISTING
:
691 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL
);
693 // Read master_preferences copied beside chrome.exe at install.
694 MasterPreferences
prefs(installation_root
.AppendASCII(kDefaultMasterPrefs
));
695 base::FilePath
chrome_exe(installation_root
.Append(kChromeExe
));
696 CreateOrUpdateShortcuts(
697 chrome_exe
, chrome
, prefs
, CURRENT_USER
, install_operation
);
700 bool InstallFromWebstore(const std::string
& app_code
) {
701 base::FilePath
app_host_path(chrome_launcher_support::GetAnyAppHostPath());
702 if (app_host_path
.empty())
705 CommandLine
cmd(app_host_path
);
706 cmd
.AppendSwitchASCII(::switches::kInstallFromWebstore
, app_code
);
707 VLOG(1) << "App install command: " << cmd
.GetCommandLineString();
708 return base::LaunchProcess(cmd
, base::LaunchOptions(), NULL
);
711 } // namespace installer