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_frame_operations.h"
6
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"
15
16 namespace installer {
17
ReadOptions(const MasterPreferences & prefs,std::set<string16> * options) const18 void ChromeFrameOperations::ReadOptions(const MasterPreferences& prefs,
19 std::set<string16>* options) const {
20 DCHECK(options);
21
22 static const struct PrefToOption {
23 const char* pref_name;
24 const wchar_t* option_name;
25 } map[] = {
26 { master_preferences::kMultiInstall, kOptionMultiInstall }
27 };
28
29 bool pref_value;
30
31 for (const PrefToOption* scan = &map[0], *end = &map[arraysize(map)];
32 scan != end; ++scan) {
33 if (prefs.GetBool(scan->pref_name, &pref_value) && pref_value)
34 options->insert(scan->option_name);
35 }
36 }
37
ReadOptions(const CommandLine & uninstall_command,std::set<string16> * options) const38 void ChromeFrameOperations::ReadOptions(const CommandLine& uninstall_command,
39 std::set<string16>* options) const {
40 DCHECK(options);
41
42 static const struct FlagToOption {
43 const char* flag_name;
44 const wchar_t* option_name;
45 } map[] = {
46 { switches::kMultiInstall, kOptionMultiInstall }
47 };
48
49 for (const FlagToOption* scan = &map[0], *end = &map[arraysize(map)];
50 scan != end; ++scan) {
51 if (uninstall_command.HasSwitch(scan->flag_name))
52 options->insert(scan->option_name);
53 }
54 }
55
AddKeyFiles(const std::set<string16> & options,std::vector<base::FilePath> * key_files) const56 void ChromeFrameOperations::AddKeyFiles(
57 const std::set<string16>& options,
58 std::vector<base::FilePath>* key_files) const {
59 DCHECK(key_files);
60 key_files->push_back(base::FilePath(installer::kChromeFrameDll));
61 key_files->push_back(base::FilePath(installer::kChromeFrameHelperExe));
62 }
63
AddComDllList(const std::set<string16> & options,std::vector<base::FilePath> * com_dll_list) const64 void ChromeFrameOperations::AddComDllList(
65 const std::set<string16>& options,
66 std::vector<base::FilePath>* com_dll_list) const {
67 DCHECK(com_dll_list);
68 com_dll_list->push_back(base::FilePath(installer::kChromeFrameDll));
69 }
70
AppendProductFlags(const std::set<string16> & options,CommandLine * cmd_line) const71 void ChromeFrameOperations::AppendProductFlags(
72 const std::set<string16>& options,
73 CommandLine* cmd_line) const {
74 DCHECK(cmd_line);
75 bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
76
77 // Add --multi-install if it isn't already there.
78 if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
79 cmd_line->AppendSwitch(switches::kMultiInstall);
80
81 // --chrome-frame is always needed.
82 cmd_line->AppendSwitch(switches::kChromeFrame);
83 }
84
AppendRenameFlags(const std::set<string16> & options,CommandLine * cmd_line) const85 void ChromeFrameOperations::AppendRenameFlags(const std::set<string16>& options,
86 CommandLine* cmd_line) const {
87 DCHECK(cmd_line);
88 bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
89
90 // Add --multi-install if it isn't already there.
91 if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
92 cmd_line->AppendSwitch(switches::kMultiInstall);
93
94 // --chrome-frame is needed for single installs.
95 if (!is_multi_install)
96 cmd_line->AppendSwitch(switches::kChromeFrame);
97 }
98
SetChannelFlags(const std::set<string16> & options,bool set,ChannelInfo * channel_info) const99 bool ChromeFrameOperations::SetChannelFlags(const std::set<string16>& options,
100 bool set,
101 ChannelInfo* channel_info) const {
102 #if defined(GOOGLE_CHROME_BUILD)
103 DCHECK(channel_info);
104 bool modified = channel_info->SetChromeFrame(set);
105
106 // Unconditionally remove the legacy -readymode flag.
107 modified |= channel_info->SetReadyMode(false);
108
109 return modified;
110 #else
111 return false;
112 #endif
113 }
114
ShouldCreateUninstallEntry(const std::set<string16> & options) const115 bool ChromeFrameOperations::ShouldCreateUninstallEntry(
116 const std::set<string16>& options) const {
117 return true;
118 }
119
AddDefaultShortcutProperties(BrowserDistribution * dist,const base::FilePath & target_exe,ShellUtil::ShortcutProperties * properties) const120 void ChromeFrameOperations::AddDefaultShortcutProperties(
121 BrowserDistribution* dist,
122 const base::FilePath& target_exe,
123 ShellUtil::ShortcutProperties* properties) const {
124 NOTREACHED() << "Chrome Frame does not create shortcuts.";
125 }
126
LaunchUserExperiment(const base::FilePath & setup_path,const std::set<string16> & options,InstallStatus status,bool system_level) const127 void ChromeFrameOperations::LaunchUserExperiment(
128 const base::FilePath& setup_path,
129 const std::set<string16>& options,
130 InstallStatus status,
131 bool system_level) const {
132 // No experiments yet. If adding some in the future, need to have
133 // ChromeFrameDistribution::HasUserExperiments() return true.
134 NOTREACHED();
135 }
136
137 } // namespace installer
138