1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/installer/util/chrome_browser_operations.h" 6 7#include "base/command_line.h" 8#include "base/files/file_path.h" 9#include "base/files/file_util.h" 10#include "base/logging.h" 11#include "base/strings/string_util.h" 12#include "chrome/installer/util/browser_distribution.h" 13#include "chrome/installer/util/channel_info.h" 14#include "chrome/installer/util/helper.h" 15#include "chrome/installer/util/install_util.h" 16#include "chrome/installer/util/master_preferences.h" 17#include "chrome/installer/util/master_preferences_constants.h" 18#include "chrome/installer/util/shell_util.h" 19#include "chrome/installer/util/user_experiment.h" 20#include "chrome/installer/util/util_constants.h" 21 22namespace installer { 23 24void ChromeBrowserOperations::ReadOptions(const MasterPreferences& prefs, 25 std::set<base::string16>* options) 26 const { 27 DCHECK(options); 28 29 bool pref_value; 30 31 if (prefs.GetBool(master_preferences::kMultiInstall, &pref_value) && 32 pref_value) { 33 options->insert(kOptionMultiInstall); 34 } 35} 36 37void ChromeBrowserOperations::ReadOptions(const CommandLine& uninstall_command, 38 std::set<base::string16>* options) 39 const { 40 DCHECK(options); 41 42 if (uninstall_command.HasSwitch(switches::kMultiInstall)) 43 options->insert(kOptionMultiInstall); 44} 45 46void ChromeBrowserOperations::AddKeyFiles( 47 const std::set<base::string16>& options, 48 std::vector<base::FilePath>* key_files) const { 49 DCHECK(key_files); 50 key_files->push_back(base::FilePath(installer::kChromeDll)); 51} 52 53void ChromeBrowserOperations::AddComDllList( 54 const std::set<base::string16>& options, 55 std::vector<base::FilePath>* com_dll_list) const { 56} 57 58void ChromeBrowserOperations::AppendProductFlags( 59 const std::set<base::string16>& options, 60 CommandLine* cmd_line) const { 61 DCHECK(cmd_line); 62 63 if (options.find(kOptionMultiInstall) != options.end()) { 64 // Add --multi-install if it isn't already there. 65 if (!cmd_line->HasSwitch(switches::kMultiInstall)) 66 cmd_line->AppendSwitch(switches::kMultiInstall); 67 68 // --chrome is only needed in multi-install. 69 cmd_line->AppendSwitch(switches::kChrome); 70 } 71} 72 73void ChromeBrowserOperations::AppendRenameFlags( 74 const std::set<base::string16>& options, 75 CommandLine* cmd_line) const { 76 DCHECK(cmd_line); 77 78 // Add --multi-install if it isn't already there. 79 if (options.find(kOptionMultiInstall) != options.end() && 80 !cmd_line->HasSwitch(switches::kMultiInstall)) { 81 cmd_line->AppendSwitch(switches::kMultiInstall); 82 } 83} 84 85bool ChromeBrowserOperations::SetChannelFlags( 86 const std::set<base::string16>& options, 87 bool set, 88 ChannelInfo* channel_info) const { 89#if defined(GOOGLE_CHROME_BUILD) 90 DCHECK(channel_info); 91 return channel_info->SetChrome(set); 92#else 93 return false; 94#endif 95} 96 97bool ChromeBrowserOperations::ShouldCreateUninstallEntry( 98 const std::set<base::string16>& options) const { 99 return true; 100} 101 102// Modifies a ShortcutProperties object by adding default values to 103// uninitialized members. Tries to assign: 104// - target: |chrome_exe|. 105// - icon: from |chrome_exe|. 106// - icon_index: |dist|'s icon index (possibly overridden by 107// khromeShortcutIconIndex in master_preferences) 108// - app_id: the browser model id for the current install. 109// - description: |dist|'s description. 110void ChromeBrowserOperations::AddDefaultShortcutProperties( 111 BrowserDistribution* dist, 112 const base::FilePath& target_exe, 113 ShellUtil::ShortcutProperties* properties) const { 114 if (!properties->has_target()) 115 properties->set_target(target_exe); 116 117 if (!properties->has_icon()) { 118 int icon_index = 119 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); 120 base::FilePath prefs_path(target_exe.DirName().AppendASCII( 121 installer::kDefaultMasterPrefs)); 122 if (base::PathExists(prefs_path)) { 123 installer::MasterPreferences prefs(prefs_path); 124 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, 125 &icon_index); 126 } 127 properties->set_icon(target_exe, icon_index); 128 } 129 130 if (!properties->has_app_id()) { 131 bool is_per_user_install = 132 InstallUtil::IsPerUserInstall(target_exe.value().c_str()); 133 properties->set_app_id( 134 ShellUtil::GetBrowserModelId(dist, is_per_user_install)); 135 } 136 137 if (!properties->has_description()) 138 properties->set_description(dist->GetAppDescription()); 139} 140 141void ChromeBrowserOperations::LaunchUserExperiment( 142 const base::FilePath& setup_path, 143 const std::set<base::string16>& options, 144 InstallStatus status, 145 bool system_level) const { 146 CommandLine base_command(setup_path); 147 AppendProductFlags(options, &base_command); 148 installer::LaunchBrowserUserExperiment(base_command, status, system_level); 149} 150 151} // namespace installer 152