[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / installer / setup / install.cc
blobb0a4e62438be2211d1f44cf59c3971daed7d8de6
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/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/shell_util.h"
41 #include "chrome/installer/util/util_constants.h"
42 #include "chrome/installer/util/work_item_list.h"
45 namespace {
47 void LogShortcutOperation(ShellUtil::ShortcutLocation location,
48 BrowserDistribution* dist,
49 const ShellUtil::ShortcutProperties& properties,
50 ShellUtil::ShortcutOperation operation,
51 bool failed) {
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);
55 std::string message;
56 if (failed)
57 message.append("Failed: ");
58 message.append(
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 " :
65 "all-users ");
66 switch (location) {
67 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
68 message.append("Desktop ");
69 break;
70 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
71 message.append("Quick Launch ");
72 break;
73 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
74 message.append("Start menu/" +
75 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
76 BrowserDistribution::SUBFOLDER_CHROME)) +
77 " ");
78 break;
79 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
80 message.append("Start menu/" +
81 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
82 BrowserDistribution::SUBFOLDER_APPS)) +
83 " ");
84 break;
85 default:
86 NOTREACHED();
89 message.push_back('"');
90 if (properties.has_shortcut_name())
91 message.append(base::UTF16ToUTF8(properties.shortcut_name));
92 else
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('.');
113 if (failed)
114 LOG(WARNING) << message;
115 else
116 VLOG(1) << 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,
126 operation)) {
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
166 // to be installed.
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,
196 installer_state,
197 setup_path,
198 archive_path,
199 src_path,
200 temp_path,
201 current_version->get(),
202 new_version,
203 install_list.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. ";
220 return result;
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;
254 // Deletes the old "Uninstall Google Chrome" shortcut in the Start menu which
255 // was installed prior to Chrome 24.
256 void CleanupLegacyShortcuts(const installer::InstallerState& installer_state,
257 BrowserDistribution* dist,
258 const base::FilePath& chrome_exe) {
259 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ?
260 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER;
261 base::FilePath uninstall_shortcut_path;
262 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
263 dist, shortcut_level, &uninstall_shortcut_path);
264 uninstall_shortcut_path = uninstall_shortcut_path.Append(
265 dist->GetUninstallLinkName() + installer::kLnkExt);
266 base::DeleteFile(uninstall_shortcut_path, false);
269 } // end namespace
271 namespace installer {
273 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
274 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
275 base::ASCIIToUTF16("&amp;"), att_value);
276 base::ReplaceChars(*att_value, base::ASCIIToUTF16("'"),
277 base::ASCIIToUTF16("&apos;"), att_value);
278 base::ReplaceChars(*att_value, base::ASCIIToUTF16("<"),
279 base::ASCIIToUTF16("&lt;"), att_value);
282 bool CreateVisualElementsManifest(const base::FilePath& src_path,
283 const Version& version) {
284 // Construct the relative path to the versioned VisualElements directory.
285 base::string16 elements_dir(base::ASCIIToUTF16(version.GetString()));
286 elements_dir.push_back(base::FilePath::kSeparators[0]);
287 elements_dir.append(installer::kVisualElements);
289 // Some distributions of Chromium may not include visual elements. Only
290 // proceed if this distribution does.
291 if (!base::PathExists(src_path.Append(elements_dir))) {
292 VLOG(1) << "No visual elements found, not writing "
293 << installer::kVisualElementsManifest << " to " << src_path.value();
294 return true;
295 } else {
296 // A printf-style format string for generating the visual elements
297 // manifest. Required arguments, in order, are:
298 // - Localized display name for the product.
299 // - Relative path to the VisualElements directory, three times.
300 static const char kManifestTemplate[] =
301 "<Application>\r\n"
302 " <VisualElements\r\n"
303 " DisplayName='%ls'\r\n"
304 " Logo='%ls\\Logo.png'\r\n"
305 " SmallLogo='%ls\\SmallLogo.png'\r\n"
306 " ForegroundText='light'\r\n"
307 " BackgroundColor='#323232'>\r\n"
308 " <DefaultTile ShowName='allLogos'/>\r\n"
309 " <SplashScreen Image='%ls\\splash-620x300.png'/>\r\n"
310 " </VisualElements>\r\n"
311 "</Application>";
313 const base::string16 manifest_template(
314 base::ASCIIToUTF16(kManifestTemplate));
316 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
317 BrowserDistribution::CHROME_BROWSER);
318 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
319 // resource for |display_name|.
320 base::string16 display_name(dist->GetDisplayName());
321 EscapeXmlAttributeValueInSingleQuotes(&display_name);
323 // Fill the manifest with the desired values.
324 base::string16 manifest16(base::StringPrintf(
325 manifest_template.c_str(), display_name.c_str(), elements_dir.c_str(),
326 elements_dir.c_str(), elements_dir.c_str()));
328 // Write the manifest to |src_path|.
329 const std::string manifest(base::UTF16ToUTF8(manifest16));
330 int size = base::checked_cast<int>(manifest.size());
331 if (base::WriteFile(
332 src_path.Append(installer::kVisualElementsManifest),
333 manifest.c_str(), size) == size) {
334 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
335 << " to " << src_path.value();
336 return true;
337 } else {
338 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
339 << " to " << src_path.value();
340 return false;
345 void CreateOrUpdateShortcuts(
346 const base::FilePath& target,
347 const installer::Product& product,
348 const MasterPreferences& prefs,
349 InstallShortcutLevel install_level,
350 InstallShortcutOperation install_operation) {
351 bool do_not_create_any_shortcuts = false;
352 prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts,
353 &do_not_create_any_shortcuts);
354 if (do_not_create_any_shortcuts)
355 return;
357 // Extract shortcut preferences from |prefs|.
358 bool do_not_create_desktop_shortcut = false;
359 bool do_not_create_quick_launch_shortcut = false;
360 bool do_not_create_taskbar_shortcut = false;
361 bool do_not_create_start_pin = false;
362 bool alternate_desktop_shortcut = false;
363 prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut,
364 &do_not_create_desktop_shortcut);
365 prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut,
366 &do_not_create_quick_launch_shortcut);
367 prefs.GetBool(master_preferences::kDoNotCreateTaskbarShortcut,
368 &do_not_create_taskbar_shortcut);
369 prefs.GetBool(master_preferences::kDoNotCreateStartPin,
370 &do_not_create_start_pin);
371 prefs.GetBool(master_preferences::kAltShortcutText,
372 &alternate_desktop_shortcut);
374 BrowserDistribution* dist = product.distribution();
376 // The default operation on update is to overwrite shortcuts with the
377 // currently desired properties, but do so only for shortcuts that still
378 // exist.
379 ShellUtil::ShortcutOperation shortcut_operation;
380 switch (install_operation) {
381 case INSTALL_SHORTCUT_CREATE_ALL:
382 shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS;
383 break;
384 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL:
385 shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL;
386 break;
387 default:
388 DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING);
389 shortcut_operation = ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING;
390 break;
393 // Shortcuts are always installed per-user unless specified.
394 ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ?
395 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER);
397 // |base_properties|: The basic properties to set on every shortcut installed
398 // (to be refined on a per-shortcut basis).
399 ShellUtil::ShortcutProperties base_properties(shortcut_level);
400 product.AddDefaultShortcutProperties(target, &base_properties);
402 if (!do_not_create_desktop_shortcut ||
403 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
404 ShellUtil::ShortcutProperties desktop_properties(base_properties);
405 if (alternate_desktop_shortcut) {
406 desktop_properties.set_shortcut_name(
407 dist->GetShortcutName(
408 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE));
410 ExecuteAndLogShortcutOperation(
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties,
412 shortcut_operation);
414 // On update there is no harm in always trying to update the alternate
415 // Desktop shortcut.
416 if (!alternate_desktop_shortcut &&
417 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
418 desktop_properties.set_shortcut_name(
419 dist->GetShortcutName(
420 BrowserDistribution::SHORTCUT_CHROME_ALTERNATE));
421 ExecuteAndLogShortcutOperation(
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties,
423 shortcut_operation);
427 if (!do_not_create_quick_launch_shortcut ||
428 shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) {
429 // There is no such thing as an all-users Quick Launch shortcut, always
430 // install the per-user shortcut.
431 ShellUtil::ShortcutProperties quick_launch_properties(base_properties);
432 quick_launch_properties.level = ShellUtil::CURRENT_USER;
433 ExecuteAndLogShortcutOperation(
434 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist,
435 quick_launch_properties, shortcut_operation);
438 ShellUtil::ShortcutProperties start_menu_properties(base_properties);
439 // IMPORTANT: Only the default (no arguments and default browserappid) browser
440 // shortcut in the Start menu (Start screen on Win8+) should be made dual
441 // mode and that prior to Windows 10 only.
442 if (InstallUtil::ShouldInstallMetroProperties())
443 start_menu_properties.set_dual_mode(true);
444 if (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS ||
445 shortcut_operation ==
446 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL) {
447 start_menu_properties.set_pin_to_taskbar(!do_not_create_taskbar_shortcut);
448 // Disabled for now. TODO(gab): Remove this and the associated code if it
449 // remains disabled long term.
450 start_menu_properties.set_pin_to_start(false);
452 ExecuteAndLogShortcutOperation(
453 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist,
454 start_menu_properties, shortcut_operation);
457 void RegisterChromeOnMachine(const installer::InstallerState& installer_state,
458 const installer::Product& product,
459 bool make_chrome_default) {
460 DCHECK(product.is_chrome());
462 // Try to add Chrome to Media Player shim inclusion list. We don't do any
463 // error checking here because this operation will fail if user doesn't
464 // have admin rights and we want to ignore the error.
465 AddChromeToMediaPlayerList();
467 // Make Chrome the default browser if desired when possible. Otherwise, only
468 // register it with Windows.
469 BrowserDistribution* dist = product.distribution();
470 const base::FilePath chrome_exe(
471 installer_state.target_path().Append(installer::kChromeExe));
472 VLOG(1) << "Registering Chrome as browser: " << chrome_exe.value();
473 if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) {
474 int level = ShellUtil::CURRENT_USER;
475 if (installer_state.system_install())
476 level = level | ShellUtil::SYSTEM_LEVEL;
477 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true);
478 } else {
479 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), false);
483 InstallStatus InstallOrUpdateProduct(
484 const installer::InstallationState& original_state,
485 const installer::InstallerState& installer_state,
486 const base::FilePath& setup_path,
487 const base::FilePath& archive_path,
488 const base::FilePath& install_temp_path,
489 const base::FilePath& src_path,
490 const base::FilePath& prefs_path,
491 const MasterPreferences& prefs,
492 const Version& new_version) {
493 DCHECK(!installer_state.products().empty());
495 // TODO(robertshield): Removing the pending on-reboot moves should be done
496 // elsewhere.
497 // Remove any scheduled MOVEFILE_DELAY_UNTIL_REBOOT entries in the target of
498 // this installation. These may have been added during a previous uninstall of
499 // the same version.
500 LOG_IF(ERROR, !RemoveFromMovesPendingReboot(installer_state.target_path()))
501 << "Error accessing pending moves value.";
503 // Create VisualElementManifest.xml in |src_path| (if required) so that it
504 // looks as if it had been extracted from the archive when calling
505 // InstallNewVersion() below.
506 installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST);
507 CreateVisualElementsManifest(src_path, new_version);
509 scoped_ptr<Version> existing_version;
510 InstallStatus result = InstallNewVersion(original_state, installer_state,
511 setup_path, archive_path, src_path, install_temp_path, new_version,
512 &existing_version);
514 // TODO(robertshield): Everything below this line should instead be captured
515 // by WorkItems.
516 if (!InstallUtil::GetInstallReturnCode(result)) {
517 installer_state.UpdateStage(installer::UPDATING_CHANNELS);
519 // Update the modifiers on the channel values for the product(s) being
520 // installed and for the binaries in case of multi-install.
521 installer_state.UpdateChannels();
523 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE);
525 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty())
526 CopyPreferenceFileForFirstRun(installer_state, prefs_path);
528 installer_state.UpdateStage(installer::CREATING_SHORTCUTS);
530 const installer::Product* chrome_product =
531 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER);
532 // Creates shortcuts for Chrome.
533 if (chrome_product) {
534 BrowserDistribution* chrome_dist = chrome_product->distribution();
535 const base::FilePath chrome_exe(
536 installer_state.target_path().Append(kChromeExe));
537 CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe);
539 // Install per-user shortcuts on user-level installs and all-users
540 // shortcuts on system-level installs. Note that Active Setup will take
541 // care of installing missing per-user shortcuts on system-level install
542 // (i.e., quick launch, taskbar pin, and possibly deleted all-users
543 // shortcuts).
544 InstallShortcutLevel install_level = installer_state.system_install() ?
545 ALL_USERS : CURRENT_USER;
547 InstallShortcutOperation install_operation =
548 INSTALL_SHORTCUT_REPLACE_EXISTING;
549 if (result == installer::FIRST_INSTALL_SUCCESS ||
550 result == installer::INSTALL_REPAIRED ||
551 !original_state.GetProductState(installer_state.system_install(),
552 chrome_dist->GetType())) {
553 // Always create the shortcuts on a new install, a repair install, and
554 // when the Chrome product is being added to the current install.
555 install_operation = INSTALL_SHORTCUT_CREATE_ALL;
558 CreateOrUpdateShortcuts(chrome_exe, *chrome_product, prefs, install_level,
559 install_operation);
562 if (chrome_product) {
563 // Register Chrome and, if requested, make Chrome the default browser.
564 installer_state.UpdateStage(installer::REGISTERING_CHROME);
566 bool make_chrome_default = false;
567 prefs.GetBool(master_preferences::kMakeChromeDefault,
568 &make_chrome_default);
570 // If this is not the user's first Chrome install, but they have chosen
571 // Chrome to become their default browser on the download page, we must
572 // force it here because the master_preferences file will not get copied
573 // into the build.
574 bool force_chrome_default_for_user = false;
575 if (result == NEW_VERSION_UPDATED ||
576 result == INSTALL_REPAIRED) {
577 prefs.GetBool(master_preferences::kMakeChromeDefaultForUser,
578 &force_chrome_default_for_user);
581 RegisterChromeOnMachine(installer_state, *chrome_product,
582 make_chrome_default || force_chrome_default_for_user);
584 // Configure auto-launch.
585 if (result == FIRST_INSTALL_SUCCESS) {
586 installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH);
588 // Add auto-launch key if specified in master_preferences.
589 bool auto_launch_chrome = false;
590 prefs.GetBool(
591 installer::master_preferences::kAutoLaunchChrome,
592 &auto_launch_chrome);
593 if (auto_launch_chrome) {
594 auto_launch_util::EnableForegroundStartAtLogin(
595 base::ASCIIToUTF16(chrome::kInitialProfile),
596 installer_state.target_path());
600 if (!installer_state.system_install()) {
601 DCHECK_EQ(chrome_product->distribution(),
602 BrowserDistribution::GetDistribution());
603 UpdateDefaultBrowserBeaconForPath(
604 installer_state.target_path().Append(installer::kChromeExe));
608 installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS);
610 installer_state.RemoveOldVersionDirectories(
611 new_version,
612 existing_version.get(),
613 install_temp_path);
616 return result;
619 void HandleOsUpgradeForBrowser(const installer::InstallerState& installer_state,
620 const installer::Product& chrome) {
621 DCHECK(chrome.is_chrome());
622 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
623 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
624 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
625 VLOG(1) << "Updating and registering shortcuts.";
626 // Read master_preferences copied beside chrome.exe at install.
627 MasterPreferences prefs(
628 installer_state.target_path().AppendASCII(kDefaultMasterPrefs));
630 // Unfortunately, if this is a system-level install, we can't update the
631 // shortcuts of each individual user (this only matters if this is an OS
632 // upgrade from XP/Vista to Win7+ as some properties are only set on
633 // shortcuts as of Win7).
634 // At least attempt to update potentially existing all-users shortcuts.
635 InstallShortcutLevel level = installer_state.system_install() ?
636 ALL_USERS : CURRENT_USER;
637 base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe));
638 CreateOrUpdateShortcuts(chrome_exe, chrome, prefs, level,
639 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
640 RegisterChromeOnMachine(installer_state, chrome, false);
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
647 // each user's subsequent login on system-level installs.
648 if (!installer_state.system_install()) {
649 UpdateDefaultBrowserBeaconForPath(chrome_exe);
650 } else {
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.";
657 else
658 LOG(ERROR) << "Failed to bump Active Setup Version on-os-upgrade.";
663 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
664 // in install_worker.cc needs to be increased for Active Setup to invoke this
665 // again for all users of this install.
666 void HandleActiveSetupForBrowser(const base::FilePath& installation_root,
667 const installer::Product& chrome,
668 bool force) {
669 DCHECK(chrome.is_chrome());
671 // If the shortcuts are not being forcefully created we may want to forcefully
672 // create them anyways if this Active Setup trigger is in response to an OS
673 // update.
674 force = force || installer::UpdateLastOSUpgradeHandledByActiveSetup(
675 chrome.distribution());
677 // Only create shortcuts on Active Setup if the first run sentinel is not
678 // present for this user (as some shortcuts used to be installed on first
679 // run and this could otherwise re-install shortcuts for users that have
680 // already deleted them in the past).
681 // Decide whether to create the shortcuts or simply replace existing
682 // shortcuts; if the decision is to create them, only shortcuts whose matching
683 // all-users shortcut isn't present on the system will be created.
684 InstallShortcutOperation install_operation =
685 (!force && InstallUtil::IsFirstRunSentinelPresent() ?
686 INSTALL_SHORTCUT_REPLACE_EXISTING :
687 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
689 // Read master_preferences copied beside chrome.exe at install.
690 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
691 base::FilePath chrome_exe(installation_root.Append(kChromeExe));
692 CreateOrUpdateShortcuts(
693 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
695 UpdateDefaultBrowserBeaconForPath(chrome_exe);
698 } // namespace installer