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_frame_operations.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "chrome/installer/util/channel_info.h"
11 #include "chrome/installer/util/helper.h"
12 #include "chrome/installer/util/master_preferences.h"
13 #include "chrome/installer/util/master_preferences_constants.h"
14 #include "chrome/installer/util/util_constants.h"
18 // Remove ready-mode if not multi-install.
19 void ChromeFrameOperations::NormalizeOptions(
20 std::set
<string16
>* options
) const {
21 std::set
<string16
>::iterator
ready_mode(options
->find(kOptionReadyMode
));
22 if (ready_mode
!= options
->end() &&
23 options
->find(kOptionMultiInstall
) == options
->end()) {
24 LOG(WARNING
) << "--ready-mode option does not apply when --multi-install "
25 "is not also specified; ignoring.";
26 options
->erase(ready_mode
);
30 void ChromeFrameOperations::ReadOptions(const MasterPreferences
& prefs
,
31 std::set
<string16
>* options
) const {
34 static const struct PrefToOption
{
35 const char* pref_name
;
36 const wchar_t* option_name
;
38 { master_preferences::kChromeFrameReadyMode
, kOptionReadyMode
},
39 { master_preferences::kMultiInstall
, kOptionMultiInstall
}
44 for (const PrefToOption
* scan
= &map
[0], *end
= &map
[arraysize(map
)];
45 scan
!= end
; ++scan
) {
46 if (prefs
.GetBool(scan
->pref_name
, &pref_value
) && pref_value
)
47 options
->insert(scan
->option_name
);
50 NormalizeOptions(options
);
53 void ChromeFrameOperations::ReadOptions(const CommandLine
& uninstall_command
,
54 std::set
<string16
>* options
) const {
57 static const struct FlagToOption
{
58 const char* flag_name
;
59 const wchar_t* option_name
;
61 { switches::kChromeFrameReadyMode
, kOptionReadyMode
},
62 { switches::kMultiInstall
, kOptionMultiInstall
}
65 for (const FlagToOption
* scan
= &map
[0], *end
= &map
[arraysize(map
)];
66 scan
!= end
; ++scan
) {
67 if (uninstall_command
.HasSwitch(scan
->flag_name
))
68 options
->insert(scan
->option_name
);
71 NormalizeOptions(options
);
74 void ChromeFrameOperations::AddKeyFiles(
75 const std::set
<string16
>& options
,
76 std::vector
<base::FilePath
>* key_files
) const {
78 key_files
->push_back(base::FilePath(installer::kChromeFrameDll
));
79 key_files
->push_back(base::FilePath(installer::kChromeFrameHelperExe
));
82 void ChromeFrameOperations::AddComDllList(
83 const std::set
<string16
>& options
,
84 std::vector
<base::FilePath
>* com_dll_list
) const {
86 com_dll_list
->push_back(base::FilePath(installer::kChromeFrameDll
));
89 void ChromeFrameOperations::AppendProductFlags(
90 const std::set
<string16
>& options
,
91 CommandLine
* cmd_line
) const {
93 bool is_multi_install
= options
.find(kOptionMultiInstall
) != options
.end();
95 // Add --multi-install if it isn't already there.
96 if (is_multi_install
&& !cmd_line
->HasSwitch(switches::kMultiInstall
))
97 cmd_line
->AppendSwitch(switches::kMultiInstall
);
99 // --chrome-frame is always needed.
100 cmd_line
->AppendSwitch(switches::kChromeFrame
);
102 // ready-mode is only supported in multi-installs of Chrome Frame.
103 if (is_multi_install
&& options
.find(kOptionReadyMode
) != options
.end())
104 cmd_line
->AppendSwitch(switches::kChromeFrameReadyMode
);
107 void ChromeFrameOperations::AppendRenameFlags(const std::set
<string16
>& options
,
108 CommandLine
* cmd_line
) const {
110 bool is_multi_install
= options
.find(kOptionMultiInstall
) != options
.end();
112 // Add --multi-install if it isn't already there.
113 if (is_multi_install
&& !cmd_line
->HasSwitch(switches::kMultiInstall
))
114 cmd_line
->AppendSwitch(switches::kMultiInstall
);
116 // --chrome-frame is needed for single installs.
117 if (!is_multi_install
)
118 cmd_line
->AppendSwitch(switches::kChromeFrame
);
121 bool ChromeFrameOperations::SetChannelFlags(const std::set
<string16
>& options
,
123 ChannelInfo
* channel_info
) const {
124 #if defined(GOOGLE_CHROME_BUILD)
125 DCHECK(channel_info
);
126 bool modified
= channel_info
->SetChromeFrame(set
);
128 // Always remove the options if we're called to remove flags or if the
129 // corresponding option isn't set.
130 modified
|= channel_info
->SetReadyMode(
131 set
&& options
.find(kOptionReadyMode
) != options
.end());
139 bool ChromeFrameOperations::ShouldCreateUninstallEntry(
140 const std::set
<string16
>& options
) const {
141 return options
.find(kOptionReadyMode
) == options
.end();
144 void ChromeFrameOperations::AddDefaultShortcutProperties(
145 BrowserDistribution
* dist
,
146 const base::FilePath
& target_exe
,
147 ShellUtil::ShortcutProperties
* properties
) const {
148 NOTREACHED() << "Chrome Frame does not create shortcuts.";
151 void ChromeFrameOperations::LaunchUserExperiment(
152 const base::FilePath
& setup_path
,
153 const std::set
<string16
>& options
,
154 InstallStatus status
,
155 bool system_level
) const {
156 // No experiments yet. If adding some in the future, need to have
157 // ChromeFrameDistribution::HasUserExperiments() return true.
161 } // namespace installer