1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/installer/util/chrome_browser_operations.h"
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"
24 void ChromeBrowserOperations::ReadOptions(const MasterPreferences& prefs,
25 std::set<string16>* options) const {
30 if (prefs.GetBool(master_preferences::kMultiInstall, &pref_value) &&
32 options->insert(kOptionMultiInstall);
36 void ChromeBrowserOperations::ReadOptions(const CommandLine& uninstall_command,
37 std::set<string16>* options) const {
40 if (uninstall_command.HasSwitch(switches::kMultiInstall))
41 options->insert(kOptionMultiInstall);
44 void ChromeBrowserOperations::AddKeyFiles(
45 const std::set<string16>& options,
46 std::vector<base::FilePath>* key_files) const {
48 key_files->push_back(base::FilePath(installer::kChromeDll));
51 void ChromeBrowserOperations::AddComDllList(
52 const std::set<string16>& options,
53 std::vector<base::FilePath>* com_dll_list) const {
56 void ChromeBrowserOperations::AppendProductFlags(
57 const std::set<string16>& options,
58 CommandLine* cmd_line) const {
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);
66 // --chrome is only needed in multi-install.
67 cmd_line->AppendSwitch(switches::kChrome);
71 void ChromeBrowserOperations::AppendRenameFlags(
72 const std::set<string16>& options,
73 CommandLine* cmd_line) const {
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);
83 bool ChromeBrowserOperations::SetChannelFlags(const std::set<string16>& options,
85 ChannelInfo* channel_info) const {
86 #if defined(GOOGLE_CHROME_BUILD)
88 return channel_info->SetChrome(set);
94 bool ChromeBrowserOperations::ShouldCreateUninstallEntry(
95 const std::set<string16>& options) const {
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);
114 if (!properties->has_icon()) {
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,
124 properties->set_icon(target_exe, icon_index);
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));
134 if (!properties->has_description())
135 properties->set_description(dist->GetAppDescription());
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);
148 } // namespace installer