Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / installer / util / chrome_browser_operations.cc
blob133fa9f0a5551489c397327896aba97bfe05a8ab
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/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"
22 namespace installer {
24 void ChromeBrowserOperations::ReadOptions(const MasterPreferences& prefs,
25 std::set<base::string16>* options)
26 const {
27 DCHECK(options);
29 bool pref_value;
31 if (prefs.GetBool(master_preferences::kMultiInstall, &pref_value) &&
32 pref_value) {
33 options->insert(kOptionMultiInstall);
37 void ChromeBrowserOperations::ReadOptions(
38 const base::CommandLine& uninstall_command,
39 std::set<base::string16>* options) const {
40 DCHECK(options);
42 if (uninstall_command.HasSwitch(switches::kMultiInstall))
43 options->insert(kOptionMultiInstall);
46 void 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));
53 void ChromeBrowserOperations::AddComDllList(
54 const std::set<base::string16>& options,
55 std::vector<base::FilePath>* com_dll_list) const {
58 void ChromeBrowserOperations::AppendProductFlags(
59 const std::set<base::string16>& options,
60 base::CommandLine* cmd_line) const {
61 DCHECK(cmd_line);
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);
68 // --chrome is only needed in multi-install.
69 cmd_line->AppendSwitch(switches::kChrome);
73 void ChromeBrowserOperations::AppendRenameFlags(
74 const std::set<base::string16>& options,
75 base::CommandLine* cmd_line) const {
76 DCHECK(cmd_line);
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);
85 bool 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 bool chrome_changed = channel_info->SetChrome(set);
92 // Remove App Launcher's channel flags, since App Launcher does not exist as
93 // an independent product, and is a part of Chrome.
94 bool app_launcher_changed = channel_info->SetAppLauncher(false);
95 return chrome_changed || app_launcher_changed;
96 #else
97 return false;
98 #endif
101 bool ChromeBrowserOperations::ShouldCreateUninstallEntry(
102 const std::set<base::string16>& options) const {
103 return true;
106 // Modifies a ShortcutProperties object by adding default values to
107 // uninitialized members. Tries to assign:
108 // - target: |chrome_exe|.
109 // - icon: from |chrome_exe|.
110 // - icon_index: |dist|'s icon index (possibly overridden by
111 // khromeShortcutIconIndex in master_preferences)
112 // - app_id: the browser model id for the current install.
113 // - description: |dist|'s description.
114 void ChromeBrowserOperations::AddDefaultShortcutProperties(
115 BrowserDistribution* dist,
116 const base::FilePath& target_exe,
117 ShellUtil::ShortcutProperties* properties) const {
118 if (!properties->has_target())
119 properties->set_target(target_exe);
121 if (!properties->has_icon()) {
122 int icon_index =
123 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME);
124 base::FilePath prefs_path(target_exe.DirName().AppendASCII(
125 installer::kDefaultMasterPrefs));
126 if (base::PathExists(prefs_path)) {
127 installer::MasterPreferences prefs(prefs_path);
128 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex,
129 &icon_index);
131 properties->set_icon(target_exe, icon_index);
134 if (!properties->has_app_id()) {
135 bool is_per_user_install = InstallUtil::IsPerUserInstall(target_exe);
136 properties->set_app_id(
137 ShellUtil::GetBrowserModelId(dist, is_per_user_install));
140 if (!properties->has_description())
141 properties->set_description(dist->GetAppDescription());
144 void ChromeBrowserOperations::LaunchUserExperiment(
145 const base::FilePath& setup_path,
146 const std::set<base::string16>& options,
147 InstallStatus status,
148 bool system_level) const {
149 base::CommandLine base_command(setup_path);
150 AppendProductFlags(options, &base_command);
151 installer::LaunchBrowserUserExperiment(base_command, status, system_level);
154 } // namespace installer