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