chrome_browser_operations.cc revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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
22namespace installer {
23
24void 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
36void 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
44void 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
51void ChromeBrowserOperations::AddComDllList(
52    const std::set<string16>& options,
53    std::vector<base::FilePath>* com_dll_list) const {
54}
55
56void 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
71void 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
83bool 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
94bool 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.
107void 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 = dist->GetIconIndex();
116    base::FilePath prefs_path(target_exe.DirName().AppendASCII(
117        installer::kDefaultMasterPrefs));
118    if (file_util::PathExists(prefs_path)) {
119      installer::MasterPreferences prefs(prefs_path);
120      prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex,
121                   &icon_index);
122    }
123    properties->set_icon(target_exe, icon_index);
124  }
125
126  if (!properties->has_app_id()) {
127    bool is_per_user_install =
128        InstallUtil::IsPerUserInstall(target_exe.value().c_str());
129    properties->set_app_id(
130        ShellUtil::GetBrowserModelId(dist, is_per_user_install));
131  }
132
133  if (!properties->has_description())
134    properties->set_description(dist->GetAppDescription());
135}
136
137void ChromeBrowserOperations::LaunchUserExperiment(
138    const base::FilePath& setup_path,
139    const std::set<string16>& options,
140    InstallStatus status,
141    bool system_level) const {
142  CommandLine base_command(setup_path);
143  AppendProductFlags(options, &base_command);
144  installer::LaunchBrowserUserExperiment(base_command, status, system_level);
145}
146
147}  // namespace installer
148