install.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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" 19a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "base/process/launch.h" 2068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "base/safe_numerics.h" 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string_util.h" 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/stringprintf.h" 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/shortcut.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/installer/launcher_support/chrome_launcher_support.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/setup/install_worker.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/setup/setup_constants.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/auto_launch_util.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/create_reg_key_work_item.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/delete_after_reboot_helper.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/google_update_constants.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/helper.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/install_util.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/master_preferences.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/master_preferences_constants.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/set_reg_value_work_item.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/shell_util.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/util_constants.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/work_item_list.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Build-time generated include file. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "registered_dlls.h" // NOLINT 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::InstallerState; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::InstallationState; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using installer::Product; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LogShortcutOperation(ShellUtil::ShortcutLocation location, 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellUtil::ShortcutProperties& properties, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation operation, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool failed) { 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thus this method does not handle logging a message for it. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(operation != ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string message; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Failed: "); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append( 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS || 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) operation == ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL) ? 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Creating " : "Overwriting "); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed && operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("(maybe the shortcut doesn't exist?) "); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append((properties.level == ShellUtil::CURRENT_USER) ? "per-user " : 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "all-users "); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (location) { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Desktop "); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append("Quick Launch "); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: 81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message.append("Start menu/" + 82a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder( 83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserDistribution::SUBFOLDER_CHROME)) + 84a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) " "); 85a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) break; 86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: 87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message.append("Start menu/" + 88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder( 89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserDistribution::SUBFOLDER_APPS)) + 90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) " "); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('"'); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.has_shortcut_name()) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.shortcut_name)); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) message.append(UTF16ToUTF8(dist->GetDisplayName())); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('"'); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(" shortcut to "); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.target.value())); 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.has_arguments()) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(UTF16ToUTF8(properties.arguments)); 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (properties.pin_to_taskbar && 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::GetVersion() >= base::win::VERSION_WIN7) { 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.append(" and pinning to the taskbar."); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message.push_back('.'); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (failed) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(WARNING) << message; 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << message; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExecuteAndLogShortcutOperation( 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutLocation location, 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellUtil::ShortcutProperties& properties, 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation operation) { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogShortcutOperation(location, dist, properties, operation, false); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!ShellUtil::CreateOrUpdateShortcut(location, dist, properties, 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) operation)) { 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogShortcutOperation(location, dist, properties, operation, true); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AddChromeToMediaPlayerList() { 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 reg_path(installer::kMediaPlayerRegPath); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // registry paths can also be appended like file system path 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) reg_path.push_back(base::FilePath::kSeparators[0]); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reg_path.append(installer::kChromeExe); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Adding Chrome to Media player list at " << reg_path; 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<WorkItem> work_item(WorkItem::CreateCreateRegKeyWorkItem( 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HKEY_LOCAL_MACHINE, reg_path)); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the operation fails we log the error but still continue 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!work_item.get()->Do()) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Could not add Chrome to media player inclusion list."; 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copy master_preferences file provided to installer, in the same folder 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as chrome.exe so Chrome first run can find it. This function will be called 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// only on the first install of Chrome. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CopyPreferenceFileForFirstRun(const InstallerState& installer_state, 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& prefs_source_path) { 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath prefs_dest_path(installer_state.target_path().AppendASCII( 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::kDefaultMasterPrefs)); 1547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::CopyFile(prefs_source_path, prefs_dest_path)) { 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Failed to copy master preferences from:" 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << prefs_source_path.value() << " gle: " << ::GetLastError(); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This function installs a new version of Chrome to the specified location. 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// setup_path: Path to the executable (setup.exe) as it will be copied 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to Chrome install folder after install is complete 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// archive_path: Path to the archive (chrome.7z) as it will be copied 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to Chrome install folder after install is complete 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// src_path: the path that contains a complete and unpacked Chrome package 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to be installed. 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// temp_path: the path of working directory used during installation. This path 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// does not need to exist. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new_version: new Chrome version that needs to be installed 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// current_version: returns the current active version (if any) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This function makes best effort to do installation in a transactional 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// manner. If failed it tries to rollback all changes on the file system 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and registry. For example, if package exists before calling the 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function, it rolls back all new file and directory changes under 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// package. If package does not exist before calling the function 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (typical new install), the function creates package during install 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and removes the whole directory during rollback. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)installer::InstallStatus InstallNewVersion( 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state, 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& setup_path, 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& archive_path, 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& src_path, 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& temp_path, 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& new_version, 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Version>* current_version) { 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(current_version); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::BUILDING); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_version->reset(installer_state.GetCurrentVersion(original_state)); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList()); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddInstallWorkItems(original_state, 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state, 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setup_path, 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) archive_path, 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src_path, 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) temp_path, 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_version->get(), 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version, 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_list.get()); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath new_chrome_exe( 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(installer::kChromeNewExe)); 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::EXECUTING); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!install_list->Do()) { 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::ROLLINGBACK); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::InstallStatus result = 2147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::PathExists(new_chrome_exe) && current_version->get() && 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version.Equals(*current_version->get()) ? 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::SAME_VERSION_REPAIR_FAILED : 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::INSTALL_FAILED; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Install failed, rolling back... result: " << result; 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_list->Rollback(); 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Rollback complete. "; 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REFRESHING_POLICY); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::RefreshElevationPolicy(); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!current_version->get()) { 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "First install of version " << new_version.GetString(); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::FIRST_INSTALL_SUCCESS; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (new_version.Equals(**current_version)) { 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Install repaired of version " << new_version.GetString(); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_REPAIRED; 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (new_version.CompareTo(**current_version) > 0) { 2397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (base::PathExists(new_chrome_exe)) { 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Version updated to " << new_version.GetString() 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " while running " << (*current_version)->GetString(); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::IN_USE_UPDATED; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Version updated to " << new_version.GetString(); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::NEW_VERSION_UPDATED; 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Not sure how we got here while updating" 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << ", new version: " << new_version.GetString() 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << ", old version: " << (*current_version)->GetString(); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_FAILED; 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Deletes the old "Uninstall Google Chrome" shortcut in the Start menu and, if 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this is a system-level install, also deletes the old Default user Quick 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Launch shortcut. Both of these were created prior to Chrome 24; in Chrome 24, 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the uninstall shortcut was removed and the Default user Quick Launch shortcut 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// was replaced by per-user shortcuts created via Active Setup. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CleanupLegacyShortcuts(const InstallerState& installer_state, 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& chrome_exe) { 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShellChange shortcut_level = installer_state.system_install() ? 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER; 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath uninstall_shortcut_path; 266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) dist, shortcut_level, &uninstall_shortcut_path); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uninstall_shortcut_path = uninstall_shortcut_path.Append( 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dist->GetUninstallLinkName() + installer::kLnkExt); 2707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::DeleteFile(uninstall_shortcut_path, false); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (installer_state.system_install()) { 273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::RemoveShortcuts( 274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist, 275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::SYSTEM_LEVEL, chrome_exe); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the appropriate shortcut operations for App Launcher, 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// based on state of installation and master_preferences. 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)installer::InstallShortcutOperation GetAppLauncherShortcutOperation( 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state) { 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const installer::ProductState* original_app_host_state = 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) original_state.GetProductState(installer_state.system_install(), 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution::CHROME_APP_HOST); 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool app_launcher_exists = original_app_host_state && 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) original_app_host_state->uninstall_command() 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .HasSwitch(installer::switches::kChromeAppLauncher); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!app_launcher_exists) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_SHORTCUT_CREATE_ALL; 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return installer::INSTALL_SHORTCUT_REPLACE_EXISTING; 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // end namespace 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace installer { 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) { 301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::ReplaceChars(*att_value, L"&", L"&", att_value); 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::ReplaceChars(*att_value, L"'", L"'", att_value); 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::ReplaceChars(*att_value, L"<", L"<", att_value); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool CreateVisualElementsManifest(const base::FilePath& src_path, 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& version) { 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Construct the relative path to the versioned VisualElements directory. 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 elements_dir(ASCIIToUTF16(version.GetString())); 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) elements_dir.push_back(base::FilePath::kSeparators[0]); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) elements_dir.append(installer::kVisualElements); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some distributions of Chromium may not include visual elements. Only 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // proceed if this distribution does. 3157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::PathExists(src_path.Append(elements_dir))) { 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "No visual elements found, not writing " 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << installer::kVisualElementsManifest << " to " << src_path.value(); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A printf_p-style format string for generating the visual elements 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // manifest. Required arguments, in order, are: 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - Localized display name for the product. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - Relative path to the VisualElements directory. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char kManifestTemplate[] = 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "<Application>\r\n" 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <VisualElements\r\n" 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " DisplayName='%1$ls'\r\n" 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " Logo='%2$ls\\Logo.png'\r\n" 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " SmallLogo='%2$ls\\SmallLogo.png'\r\n" 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " ForegroundText='light'\r\n" 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " BackgroundColor='#323232'>\r\n" 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <DefaultTile ShowName='allLogos'/>\r\n" 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n" 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " </VisualElements>\r\n" 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "</Application>"; 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 manifest_template(ASCIIToUTF16(kManifestTemplate)); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution::CHROME_BROWSER); 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(grt): http://crbug.com/75152 Write a reference to a localized 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // resource for |display_name|. 3433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) string16 display_name(dist->GetDisplayName()); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EscapeXmlAttributeValueInSingleQuotes(&display_name); 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fill the manifest with the desired values. 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 manifest16(base::StringPrintf(manifest_template.c_str(), 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) display_name.c_str(), 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) elements_dir.c_str())); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Write the manifest to |src_path|. 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string manifest(UTF16ToUTF8(manifest16)); 35368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int size = base::checked_numeric_cast<int>(manifest.size()); 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (file_util::WriteFile( 35568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) src_path.Append(installer::kVisualElementsManifest), 35668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) manifest.c_str(), size) == size) { 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " to " << src_path.value(); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << " to " << src_path.value(); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreateOrUpdateShortcuts( 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& target, 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& product, 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MasterPreferences& prefs, 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutLevel install_level, 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation) { 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool do_not_create_any_shortcuts = false; 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts, 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &do_not_create_any_shortcuts); 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (do_not_create_any_shortcuts) 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extract shortcut preferences from |prefs|. 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool do_not_create_desktop_shortcut = false; 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool do_not_create_quick_launch_shortcut = false; 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool do_not_create_taskbar_shortcut = false; 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool alternate_desktop_shortcut = false; 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut, 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &do_not_create_desktop_shortcut); 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut, 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &do_not_create_quick_launch_shortcut); 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs.GetBool(master_preferences::kDoNotCreateTaskbarShortcut, 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &do_not_create_taskbar_shortcut); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kAltShortcutText, 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &alternate_desktop_shortcut); 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = product.distribution(); 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default operation on update is to overwrite shortcuts with the 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // currently desired properties, but do so only for shortcuts that still 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // exist. 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutOperation shortcut_operation; 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (install_operation) { 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case INSTALL_SHORTCUT_CREATE_ALL: 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL: 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation = ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING; 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Shortcuts are always installed per-user unless specified. 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ? 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER); 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |base_properties|: The basic properties to set on every shortcut installed 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (to be refined on a per-shortcut basis). 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties base_properties(shortcut_level); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) product.AddDefaultShortcutProperties(target, &base_properties); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!do_not_create_desktop_shortcut || 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties desktop_properties(base_properties); 4253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (alternate_desktop_shortcut) { 4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) desktop_properties.set_shortcut_name( 4273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) dist->GetShortcutName( 4283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) BrowserDistribution::SHORTCUT_CHROME_ALTERNATE)); 4293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties, 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On update there is no harm in always trying to update the alternate 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Desktop shortcut. 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!alternate_desktop_shortcut && 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) desktop_properties.set_shortcut_name( 4393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) dist->GetShortcutName( 4403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) BrowserDistribution::SHORTCUT_CHROME_ALTERNATE)); 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, desktop_properties, 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation); 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!do_not_create_quick_launch_shortcut || 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_operation == ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING) { 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // There is no such thing as an all-users Quick Launch shortcut, always 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // install the per-user shortcut. 4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::ShortcutProperties quick_launch_properties(base_properties); 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) quick_launch_properties.level = ShellUtil::CURRENT_USER; 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExecuteAndLogShortcutOperation( 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist, 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) quick_launch_properties, shortcut_operation); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutProperties start_menu_properties(base_properties); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IMPORTANT: Only the default (no arguments and default browserappid) browser 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcut in the Start menu (Start screen on Win8+) should be made dual 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // mode. 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) start_menu_properties.set_dual_mode(true); 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!do_not_create_taskbar_shortcut && 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS || 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shortcut_operation == 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)) { 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) start_menu_properties.set_pin_to_taskbar(true); 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExecuteAndLogShortcutOperation( 470a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist, 471a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) start_menu_properties, shortcut_operation); 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RegisterChromeOnMachine(const InstallerState& installer_state, 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& product, 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool make_chrome_default) { 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(product.is_chrome()); 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try to add Chrome to Media Player shim inclusion list. We don't do any 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // error checking here because this operation will fail if user doesn't 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have admin rights and we want to ignore the error. 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddChromeToMediaPlayerList(); 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make Chrome the default browser if desired when possible. Otherwise, only 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // register it with Windows. 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = product.distribution(); 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 chrome_exe( 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(installer::kChromeExe).value()); 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Registering Chrome as browser: " << chrome_exe; 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) { 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int level = ShellUtil::CURRENT_USER; 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (installer_state.system_install()) 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) level = level | ShellUtil::SYSTEM_LEVEL; 4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)InstallStatus InstallOrUpdateProduct( 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallationState& original_state, 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstallerState& installer_state, 5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& setup_path, 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& archive_path, 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& install_temp_path, 5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& src_path, 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& prefs_path, 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MasterPreferences& prefs, 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Version& new_version) { 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(robertshield): Removing the pending on-reboot moves should be done 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // elsewhere. 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(erikwright): Understand why this is Chrome Frame only and whether 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it also applies to App Host. Shouldn't it apply to any multi-install too? 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Products& products = installer_state.products(); 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(products.size()); 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure that we don't end up deleting installed files on next reboot. 51868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!RemoveFromMovesPendingReboot(installer_state.target_path())) 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(ERROR) << "Error accessing pending moves value."; 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create VisualElementManifest.xml in |src_path| (if required) so that it 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // looks as if it had been extracted from the archive when calling 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // InstallNewVersion() below. 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST); 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateVisualElementsManifest(src_path, new_version); 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Version> existing_version; 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallStatus result = InstallNewVersion(original_state, installer_state, 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setup_path, archive_path, src_path, install_temp_path, new_version, 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &existing_version); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(robertshield): Everything below this line should instead be captured 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by WorkItems. 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!InstallUtil::GetInstallReturnCode(result)) { 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::UPDATING_CHANNELS); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the modifiers on the channel values for the product(s) being 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // installed and for the binaries in case of multi-install. 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateChannels(); 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CopyPreferenceFileForFirstRun(installer_state, prefs_path); 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CREATING_SHORTCUTS); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product* app_launcher_product = 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST); 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates shortcuts for App Launcher. 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (app_launcher_product) { 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(huangs): Remove this check once we have system-level App Host. 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!installer_state.system_install()); 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath app_host_exe( 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(kChromeAppHostExe)); 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation app_launcher_shortcut_operation = 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetAppLauncherShortcutOperation(original_state, installer_state); 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Always install per-user shortcuts for App Launcher. 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts(app_host_exe, *app_launcher_product, prefs, 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CURRENT_USER, app_launcher_shortcut_operation); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product* chrome_product = 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates shortcuts for Chrome. 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chrome_product) { 5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserDistribution* chrome_dist = chrome_product->distribution(); 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath chrome_exe( 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().Append(kChromeExe)); 5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe); 5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Install per-user shortcuts on user-level installs and all-users 5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts on system-level installs. Note that Active Setup will take 5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // care of installing missing per-user shortcuts on system-level install 5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // (i.e., quick launch, taskbar pin, and possibly deleted all-users 5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts). 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InstallShortcutLevel install_level = installer_state.system_install() ? 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ALL_USERS : CURRENT_USER; 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation = 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_REPLACE_EXISTING; 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == installer::FIRST_INSTALL_SUCCESS || 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result == installer::INSTALL_REPAIRED || 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !original_state.GetProductState(installer_state.system_install(), 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome_dist->GetType())) { 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Always create the shortcuts on a new install, a repair install, and 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when the Chrome product is being added to the current install. 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_operation = INSTALL_SHORTCUT_CREATE_ALL; 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateOrUpdateShortcuts(chrome_exe, *chrome_product, prefs, install_level, 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_operation); 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chrome_product) { 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Register Chrome and, if requested, make Chrome the default browser. 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REGISTERING_CHROME); 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool make_chrome_default = false; 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kMakeChromeDefault, 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &make_chrome_default); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this is not the user's first Chrome install, but they have chosen 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome to become their default browser on the download page, we must 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // force it here because the master_preferences file will not get copied 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // into the build. 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool force_chrome_default_for_user = false; 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == NEW_VERSION_UPDATED || 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result == INSTALL_REPAIRED) { 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool(master_preferences::kMakeChromeDefaultForUser, 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &force_chrome_default_for_user); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterChromeOnMachine(installer_state, *chrome_product, 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) make_chrome_default || force_chrome_default_for_user); 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Configure auto-launch. 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result == FIRST_INSTALL_SUCCESS) { 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH); 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add auto-launch key if specified in master_preferences. 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool auto_launch_chrome = false; 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) prefs.GetBool( 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::master_preferences::kAutoLaunchChrome, 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &auto_launch_chrome); 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (auto_launch_chrome) { 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_launch_util::EnableForegroundStartAtLogin( 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASCIIToUTF16(chrome::kInitialProfile), 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path()); 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.RemoveOldVersionDirectories( 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new_version, 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) existing_version.get(), 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) install_temp_path); 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void HandleOsUpgradeForBrowser(const InstallerState& installer_state, 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& chrome) { 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(chrome.is_chrome()); 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome, so that Metro Chrome would work if Chrome is the default browser. 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Updating and registering shortcuts."; 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read master_preferences copied beside chrome.exe at install. 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MasterPreferences prefs( 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer_state.target_path().AppendASCII(kDefaultMasterPrefs)); 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Unfortunately, if this is a system-level install, we can't update the 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcuts of each individual user (this only matters if this is an OS 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // upgrade from XP/Vista to Win7+ as some properties are only set on 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shortcuts as of Win7). 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // At least attempt to update potentially existing all-users shortcuts. 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutLevel level = installer_state.system_install() ? 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ALL_USERS : CURRENT_USER; 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe)); 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts( 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome_exe, chrome, prefs, level, INSTALL_SHORTCUT_REPLACE_EXISTING); 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterChromeOnMachine(installer_state, chrome, false); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in install_worker.cc needs to be increased for Active Setup to invoke this 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// again for all users of this install. 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void HandleActiveSetupForBrowser(const base::FilePath& installation_root, 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Product& chrome, 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool force) { 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(chrome.is_chrome()); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Only create shortcuts on Active Setup if the first run sentinel is not 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // present for this user (as some shortcuts used to be installed on first 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // run and this could otherwise re-install shortcuts for users that have 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // already deleted them in the past). 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath first_run_sentinel; 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallUtil::GetSentinelFilePath( 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::kFirstRunSentinel, chrome.distribution(), &first_run_sentinel); 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Decide whether to create the shortcuts or simply replace existing 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shortcuts; if the decision is to create them, only shortcuts whose matching 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // all-users shortcut isn't present on the system will be created. 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallShortcutOperation install_operation = 6907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch (!force && base::PathExists(first_run_sentinel) ? 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_REPLACE_EXISTING : 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read master_preferences copied beside chrome.exe at install. 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath chrome_exe(installation_root.Append(kChromeExe)); 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateOrUpdateShortcuts( 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool InstallFromWebstore(const std::string& app_code) { 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath app_host_path(chrome_launcher_support::GetAnyAppHostPath()); 7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (app_host_path.empty()) 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandLine cmd(app_host_path); 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) cmd.AppendSwitchASCII(::switches::kInstallFromWebstore, app_code); 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VLOG(1) << "App install command: " << cmd.GetCommandLineString(); 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return base::LaunchProcess(cmd, base::LaunchOptions(), NULL); 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace installer 713