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