install.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/setup/install.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <shlobj.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <time.h> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/process_util.h" 207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string_util.h" 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/stringprintf.h" 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/shortcut.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/installer/launcher_support/chrome_launcher_support.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/setup/install_worker.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/setup/setup_constants.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/auto_launch_util.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/create_reg_key_work_item.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/delete_after_reboot_helper.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/google_update_constants.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/helper.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/install_util.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/master_preferences.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/master_preferences_constants.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/set_reg_value_work_item.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/shell_util.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/util_constants.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/work_item_list.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Build-time generated include file. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "registered_dlls.h" // NOLINT 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::InstallerState; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::InstallationState; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::Product; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LogShortcutOperation(ShellUtil::ShortcutLocation location, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellUtil::ShortcutProperties& properties, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation operation, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool failed) { 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thus this method does not handle logging a message for it. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(operation != ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string message; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Failed: "); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append( 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS || 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) operation == ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL) ? 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Creating " : "Overwriting "); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed && operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("(maybe the shortcut doesn't exist?) "); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append((properties.level == ShellUtil::CURRENT_USER) ? "per-user " : 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "all-users "); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (location) { 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Desktop "); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Quick Launch "); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_START_MENU: 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Start menu "); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('"'); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.has_shortcut_name()) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.shortcut_name)); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(dist->GetAppShortCutName())); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('"'); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(" shortcut to "); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.target.value())); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.has_arguments()) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.arguments)); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.pin_to_taskbar && 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::GetVersion() >= base::win::VERSION_WIN7) { 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(" and pinning to the taskbar."); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('.'); 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(WARNING) << message; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << message; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExecuteAndLogShortcutOperation( 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutLocation location, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellUtil::ShortcutProperties& properties, 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation operation) { 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogShortcutOperation(location, dist, properties, operation, false); 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!ShellUtil::CreateOrUpdateShortcut(location, dist, properties, 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) operation)) { 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogShortcutOperation(location, dist, properties, operation, true); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AddChromeToMediaPlayerList() { 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 reg_path(installer::kMediaPlayerRegPath); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // registry paths can also be appended like file system path 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) reg_path.push_back(base::FilePath::kSeparators[0]); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reg_path.append(installer::kChromeExe); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Adding Chrome to Media player list at " << reg_path; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<WorkItem> work_item(WorkItem::CreateCreateRegKeyWorkItem( 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HKEY_LOCAL_MACHINE, reg_path)); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the operation fails we log the error but still continue 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!work_item.get()->Do()) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Could not add Chrome to media player inclusion list."; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copy master_preferences file provided to installer, in the same folder 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as chrome.exe so Chrome first run can find it. This function will be called 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// only on the first install of Chrome. 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CopyPreferenceFileForFirstRun(const InstallerState& installer_state, 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& prefs_source_path) { 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath prefs_dest_path(installer_state.target_path().AppendASCII( 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::kDefaultMasterPrefs)); 1447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::CopyFile(prefs_source_path, prefs_dest_path)) { 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Failed to copy master preferences from:" 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << prefs_source_path.value() << " gle: " << ::GetLastError(); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This function installs a new version of Chrome to the specified location. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// setup_path: Path to the executable (setup.exe) as it will be copied 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to Chrome install folder after install is complete 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// archive_path: Path to the archive (chrome.7z) as it will be copied 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to Chrome install folder after install is complete 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// src_path: the path that contains a complete and unpacked Chrome package 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to be installed. 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// temp_path: the path of working directory used during installation. This path 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// does not need to exist. 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new_version: new Chrome version that needs to be installed 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// current_version: returns the current active version (if any) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This function makes best effort to do installation in a transactional 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// manner. If failed it tries to rollback all changes on the file system 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and registry. For example, if package exists before calling the 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function, it rolls back all new file and directory changes under 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// package. If package does not exist before calling the function 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (typical new install), the function creates package during install 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and removes the whole directory during rollback. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)installer::InstallStatus InstallNewVersion( 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state, 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& setup_path, 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& archive_path, 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& src_path, 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& temp_path, 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& new_version, 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Version>* current_version) { 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(current_version); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::BUILDING); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_version->reset(installer_state.GetCurrentVersion(original_state)); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList()); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddInstallWorkItems(original_state, 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state, 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setup_path, 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) archive_path, 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src_path, 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) temp_path, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_version->get(), 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version, 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_list.get()); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath new_chrome_exe( 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(installer::kChromeNewExe)); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::EXECUTING); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!install_list->Do()) { 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::ROLLINGBACK); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::InstallStatus result = 2047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::PathExists(new_chrome_exe) && current_version->get() && 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version.Equals(*current_version->get()) ? 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::SAME_VERSION_REPAIR_FAILED : 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::INSTALL_FAILED; 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Install failed, rolling back... result: " << result; 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_list->Rollback(); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Rollback complete. "; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REFRESHING_POLICY); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::RefreshElevationPolicy(); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!current_version->get()) { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "First install of version " << new_version.GetString(); 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::FIRST_INSTALL_SUCCESS; 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (new_version.Equals(**current_version)) { 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Install repaired of version " << new_version.GetString(); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_REPAIRED; 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (new_version.CompareTo(**current_version) > 0) { 2297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (base::PathExists(new_chrome_exe)) { 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Version updated to " << new_version.GetString() 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " while running " << (*current_version)->GetString(); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::IN_USE_UPDATED; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Version updated to " << new_version.GetString(); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::NEW_VERSION_UPDATED; 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Not sure how we got here while updating" 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << ", new version: " << new_version.GetString() 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << ", old version: " << (*current_version)->GetString(); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_FAILED; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Deletes the old "Uninstall Google Chrome" shortcut in the Start menu and, if 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this is a system-level install, also deletes the old Default user Quick 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Launch shortcut. Both of these were created prior to Chrome 24; in Chrome 24, 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the uninstall shortcut was removed and the Default user Quick Launch shortcut 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// was replaced by per-user shortcuts created via Active Setup. 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CleanupLegacyShortcuts(const InstallerState& installer_state, 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& chrome_exe) { 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShellChange shortcut_level = installer_state.system_install() ? 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER; 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath uninstall_shortcut_path; 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist, 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_level, &uninstall_shortcut_path); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uninstall_shortcut_path = uninstall_shortcut_path.Append( 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dist->GetUninstallLinkName() + installer::kLnkExt); 2607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::DeleteFile(uninstall_shortcut_path, false); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (installer_state.system_install()) { 263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::RemoveShortcuts( 264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist, 265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::SYSTEM_LEVEL, chrome_exe); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the appropriate shortcut operations for App Launcher, 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// based on state of installation and master_preferences. 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)installer::InstallShortcutOperation GetAppLauncherShortcutOperation( 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state) { 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const installer::ProductState* original_app_host_state = 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) original_state.GetProductState(installer_state.system_install(), 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution::CHROME_APP_HOST); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool app_launcher_exists = original_app_host_state && 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) original_app_host_state->uninstall_command() 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .HasSwitch(installer::switches::kChromeAppLauncher); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!app_launcher_exists) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_SHORTCUT_CREATE_ALL; 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_SHORTCUT_REPLACE_EXISTING; 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // end namespace 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace installer { 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) { 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReplaceChars(*att_value, L"&", L"&", att_value); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReplaceChars(*att_value, L"'", L"'", att_value); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReplaceChars(*att_value, L"<", L"<", att_value); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool CreateVisualElementsManifest(const base::FilePath& src_path, 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& version) { 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Construct the relative path to the versioned VisualElements directory. 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 elements_dir(ASCIIToUTF16(version.GetString())); 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) elements_dir.push_back(base::FilePath::kSeparators[0]); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) elements_dir.append(installer::kVisualElements); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some distributions of Chromium may not include visual elements. Only 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // proceed if this distribution does. 3057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::PathExists(src_path.Append(elements_dir))) { 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "No visual elements found, not writing " 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << installer::kVisualElementsManifest << " to " << src_path.value(); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A printf_p-style format string for generating the visual elements 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // manifest. Required arguments, in order, are: 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - Localized display name for the product. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - Relative path to the VisualElements directory. 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char kManifestTemplate[] = 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "<Application>\r\n" 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <VisualElements\r\n" 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " DisplayName='%1$ls'\r\n" 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " Logo='%2$ls\\Logo.png'\r\n" 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " SmallLogo='%2$ls\\SmallLogo.png'\r\n" 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " ForegroundText='light'\r\n" 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " BackgroundColor='#323232'>\r\n" 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <DefaultTile ShowName='allLogos'/>\r\n" 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n" 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " </VisualElements>\r\n" 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "</Application>"; 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 manifest_template(ASCIIToUTF16(kManifestTemplate)); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution::CHROME_BROWSER); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(grt): http://crbug.com/75152 Write a reference to a localized 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // resource for |display_name|. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 display_name(dist->GetAppShortCutName()); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EscapeXmlAttributeValueInSingleQuotes(&display_name); 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fill the manifest with the desired values. 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 manifest16(base::StringPrintf(manifest_template.c_str(), 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) display_name.c_str(), 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) elements_dir.c_str())); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Write the manifest to |src_path|. 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string manifest(UTF16ToUTF8(manifest16)); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (file_util::WriteFile( 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src_path.Append(installer::kVisualElementsManifest), 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.c_str(), manifest.size())) { 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " to " << src_path.value(); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " to " << src_path.value(); 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreateOrUpdateShortcuts( 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& target, 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& product, 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MasterPreferences& prefs, 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutLevel install_level, 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation) { 3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool do_not_create_any_shortcuts = false; 3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts, 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &do_not_create_any_shortcuts); 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (do_not_create_any_shortcuts) 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extract shortcut preferences from |prefs|. 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool do_not_create_desktop_shortcut = false; 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool do_not_create_quick_launch_shortcut = false; 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool do_not_create_taskbar_shortcut = false; 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool alternate_desktop_shortcut = false; 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut, 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &do_not_create_desktop_shortcut); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut, 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &do_not_create_quick_launch_shortcut); 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateTaskbarShortcut, 3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &do_not_create_taskbar_shortcut); 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kAltShortcutText, 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &alternate_desktop_shortcut); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = product.distribution(); 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default operation on update is to overwrite shortcuts with the 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // currently desired properties, but do so only for shortcuts that still 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // exist. 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation shortcut_operation; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (install_operation) { 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case INSTALL_SHORTCUT_CREATE_ALL: 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL: 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING; 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Shortcuts are always installed per-user unless specified. 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ? 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |base_properties|: The basic properties to set on every shortcut installed 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (to be refined on a per-shortcut basis). 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties base_properties(shortcut_level); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) product.AddDefaultShortcutProperties(target, &base_properties); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!do_not_create_desktop_shortcut || 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties desktop_properties(base_properties); 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (alternate_desktop_shortcut) 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName()); 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties, 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On update there is no harm in always trying to update the alternate 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Desktop shortcut. 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!alternate_desktop_shortcut && 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName()); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties, 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!do_not_create_quick_launch_shortcut || 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // There is no such thing as an all-users Quick Launch shortcut, always 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // install the per-user shortcut. 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::ShortcutProperties quick_launch_properties(base_properties); 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) quick_launch_properties.level = ShellUtil::CURRENT_USER; 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist, 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) quick_launch_properties, shortcut_operation); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties start_menu_properties(base_properties); 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IMPORTANT: Only the default (no arguments and default browserappid) browser 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcut in the Start menu (Start screen on Win8+) should be made dual 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // mode. 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) start_menu_properties.set_dual_mode(true); 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!do_not_create_taskbar_shortcut && 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS || 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shortcut_operation == 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)) { 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) start_menu_properties.set_pin_to_taskbar(true); 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation(ShellUtil::SHORTCUT_LOCATION_START_MENU, 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dist, start_menu_properties, 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RegisterChromeOnMachine(const InstallerState& installer_state, 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& product, 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool make_chrome_default) { 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(product.is_chrome()); 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try to add Chrome to Media Player shim inclusion list. We don't do any 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // error checking here because this operation will fail if user doesn't 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have admin rights and we want to ignore the error. 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddChromeToMediaPlayerList(); 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make Chrome the default browser if desired when possible. Otherwise, only 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // register it with Windows. 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = product.distribution(); 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 chrome_exe( 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(installer::kChromeExe).value()); 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Registering Chrome as browser: " << chrome_exe; 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) { 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int level = ShellUtil::CURRENT_USER; 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (installer_state.system_install()) 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) level = level | ShellUtil::SYSTEM_LEVEL; 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)InstallStatus InstallOrUpdateProduct( 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state, 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& setup_path, 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& archive_path, 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& install_temp_path, 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& src_path, 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& prefs_path, 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MasterPreferences& prefs, 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& new_version) { 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(robertshield): Removing the pending on-reboot moves should be done 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // elsewhere. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(erikwright): Understand why this is Chrome Frame only and whether 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it also applies to App Host. Shouldn't it apply to any multi-install too? 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Products& products = installer_state.products(); 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(products.size()); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure that we don't end up deleting installed files on next reboot. 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!RemoveFromMovesPendingReboot( 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().value().c_str())) { 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Error accessing pending moves value."; 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create VisualElementManifest.xml in |src_path| (if required) so that it 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // looks as if it had been extracted from the archive when calling 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // InstallNewVersion() below. 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST); 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateVisualElementsManifest(src_path, new_version); 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Version> existing_version; 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallStatus result = InstallNewVersion(original_state, installer_state, 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setup_path, archive_path, src_path, install_temp_path, new_version, 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &existing_version); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(robertshield): Everything below this line should instead be captured 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by WorkItems. 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!InstallUtil::GetInstallReturnCode(result)) { 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::UPDATING_CHANNELS); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the modifiers on the channel values for the product(s) being 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // installed and for the binaries in case of multi-install. 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateChannels(); 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CopyPreferenceFileForFirstRun(installer_state, prefs_path); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CREATING_SHORTCUTS); 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product* app_launcher_product = 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates shortcuts for App Launcher. 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (app_launcher_product) { 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(huangs): Remove this check once we have system-level App Host. 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!installer_state.system_install()); 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath app_host_exe( 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(kChromeAppHostExe)); 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation app_launcher_shortcut_operation = 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetAppLauncherShortcutOperation(original_state, installer_state); 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Always install per-user shortcuts for App Launcher. 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts(app_host_exe, *app_launcher_product, prefs, 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_USER, app_launcher_shortcut_operation); 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product* chrome_product = 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates shortcuts for Chrome. 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chrome_product) { 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserDistribution* chrome_dist = chrome_product->distribution(); 5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath chrome_exe( 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(kChromeExe)); 5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe); 5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Install per-user shortcuts on user-level installs and all-users 5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts on system-level installs. Note that Active Setup will take 5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // care of installing missing per-user shortcuts on system-level install 5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // (i.e., quick launch, taskbar pin, and possibly deleted all-users 5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts). 5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InstallShortcutLevel install_level = installer_state.system_install() ? 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ALL_USERS : CURRENT_USER; 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation = 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_REPLACE_EXISTING; 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == installer::FIRST_INSTALL_SUCCESS || 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result == installer::INSTALL_REPAIRED || 5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !original_state.GetProductState(installer_state.system_install(), 5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome_dist->GetType())) { 5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Always create the shortcuts on a new install, a repair install, and 5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when the Chrome product is being added to the current install. 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_operation = INSTALL_SHORTCUT_CREATE_ALL; 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateOrUpdateShortcuts(chrome_exe, *chrome_product, prefs, install_level, 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_operation); 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chrome_product) { 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Register Chrome and, if requested, make Chrome the default browser. 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REGISTERING_CHROME); 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool make_chrome_default = false; 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kMakeChromeDefault, 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &make_chrome_default); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this is not the user's first Chrome install, but they have chosen 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome to become their default browser on the download page, we must 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // force it here because the master_preferences file will not get copied 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // into the build. 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool force_chrome_default_for_user = false; 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == NEW_VERSION_UPDATED || 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result == INSTALL_REPAIRED) { 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kMakeChromeDefaultForUser, 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &force_chrome_default_for_user); 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterChromeOnMachine(installer_state, *chrome_product, 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) make_chrome_default || force_chrome_default_for_user); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Configure auto-launch. 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == FIRST_INSTALL_SUCCESS) { 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add auto-launch key if specified in master_preferences. 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool auto_launch_chrome = false; 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool( 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::master_preferences::kAutoLaunchChrome, 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &auto_launch_chrome); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (auto_launch_chrome) { 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_launch_util::EnableForegroundStartAtLogin( 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASCIIToUTF16(chrome::kInitialProfile), 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path()); 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS); 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.RemoveOldVersionDirectories( 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version, 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) existing_version.get(), 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_temp_path); 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void HandleOsUpgradeForBrowser(const InstallerState& installer_state, 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& chrome) { 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(chrome.is_chrome()); 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome, so that Metro Chrome would work if Chrome is the default browser. 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Updating and registering shortcuts."; 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read master_preferences copied beside chrome.exe at install. 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MasterPreferences prefs( 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().AppendASCII(kDefaultMasterPrefs)); 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Unfortunately, if this is a system-level install, we can't update the 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcuts of each individual user (this only matters if this is an OS 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // upgrade from XP/Vista to Win7+ as some properties are only set on 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcuts as of Win7). 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // At least attempt to update potentially existing all-users shortcuts. 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutLevel level = installer_state.system_install() ? 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ALL_USERS : CURRENT_USER; 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe)); 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts( 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome_exe, chrome, prefs, level, INSTALL_SHORTCUT_REPLACE_EXISTING); 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterChromeOnMachine(installer_state, chrome, false); 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in install_worker.cc needs to be increased for Active Setup to invoke this 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// again for all users of this install. 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void HandleActiveSetupForBrowser(const base::FilePath& installation_root, 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& chrome, 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool force) { 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(chrome.is_chrome()); 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Only create shortcuts on Active Setup if the first run sentinel is not 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // present for this user (as some shortcuts used to be installed on first 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // run and this could otherwise re-install shortcuts for users that have 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // already deleted them in the past). 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath first_run_sentinel; 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallUtil::GetSentinelFilePath( 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::kFirstRunSentinel, chrome.distribution(), &first_run_sentinel); 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Decide whether to create the shortcuts or simply replace existing 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts; if the decision is to create them, only shortcuts whose matching 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // all-users shortcut isn't present on the system will be created. 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation = 6767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch (!force && base::PathExists(first_run_sentinel) ? 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_REPLACE_EXISTING : 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read master_preferences copied beside chrome.exe at install. 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath chrome_exe(installation_root.Append(kChromeExe)); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts( 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool InstallFromWebstore(const std::string& app_code) { 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath app_host_path(chrome_launcher_support::GetAnyAppHostPath()); 6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (app_host_path.empty()) 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandLine cmd(app_host_path); 6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) cmd.AppendSwitchASCII(::switches::kInstallFromWebstore, app_code); 6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VLOG(1) << "App install command: " << cmd.GetCommandLineString(); 6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return base::LaunchProcess(cmd, base::LaunchOptions(), NULL); 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace installer 699