OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/util/master_preferences.h" | 5 #include "chrome/installer/util/master_preferences.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 << "Root item must be a dictionary."; | 68 << "Root item must be a dictionary."; |
69 return NULL; | 69 return NULL; |
70 } | 70 } |
71 return static_cast<base::DictionaryValue*>(root.release()); | 71 return static_cast<base::DictionaryValue*>(root.release()); |
72 } | 72 } |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 namespace installer { | 76 namespace installer { |
77 | 77 |
78 MasterPreferences::MasterPreferences() : distribution_(NULL), | 78 MasterPreferences::MasterPreferences() { |
79 preferences_read_from_file_(false), | |
80 chrome_(true), | |
81 multi_install_(false) { | |
82 InitializeFromCommandLine(*base::CommandLine::ForCurrentProcess()); | 79 InitializeFromCommandLine(*base::CommandLine::ForCurrentProcess()); |
83 } | 80 } |
84 | 81 |
85 MasterPreferences::MasterPreferences(const base::CommandLine& cmd_line) | 82 MasterPreferences::MasterPreferences(const base::CommandLine& cmd_line) { |
86 : distribution_(NULL), | |
87 preferences_read_from_file_(false), | |
88 chrome_(true), | |
89 multi_install_(false) { | |
90 InitializeFromCommandLine(cmd_line); | 83 InitializeFromCommandLine(cmd_line); |
91 } | 84 } |
92 | 85 |
93 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) | 86 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) { |
94 : distribution_(NULL), | |
95 preferences_read_from_file_(false), | |
96 chrome_(true), | |
97 multi_install_(false) { | |
98 InitializeFromFilePath(prefs_path); | 87 InitializeFromFilePath(prefs_path); |
99 } | 88 } |
100 | 89 |
101 MasterPreferences::MasterPreferences(const std::string& prefs) | 90 MasterPreferences::MasterPreferences(const std::string& prefs) { |
102 : distribution_(NULL), | |
103 preferences_read_from_file_(false), | |
104 chrome_(true), | |
105 multi_install_(false) { | |
106 InitializeFromString(prefs); | 91 InitializeFromString(prefs); |
107 } | 92 } |
108 | 93 |
109 MasterPreferences::~MasterPreferences() { | 94 MasterPreferences::~MasterPreferences() { |
110 } | 95 } |
111 | 96 |
112 void MasterPreferences::InitializeFromCommandLine( | 97 void MasterPreferences::InitializeFromCommandLine( |
113 const base::CommandLine& cmd_line) { | 98 const base::CommandLine& cmd_line) { |
114 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
115 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { | 100 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { |
116 base::FilePath prefs_path(cmd_line.GetSwitchValuePath( | 101 base::FilePath prefs_path(cmd_line.GetSwitchValuePath( |
117 installer::switches::kInstallerData)); | 102 installer::switches::kInstallerData)); |
118 InitializeFromFilePath(prefs_path); | 103 InitializeFromFilePath(prefs_path); |
119 } else { | 104 } else { |
120 master_dictionary_.reset(new base::DictionaryValue()); | 105 master_dictionary_.reset(new base::DictionaryValue()); |
121 } | 106 } |
122 | 107 |
123 DCHECK(master_dictionary_.get()); | 108 DCHECK(master_dictionary_.get()); |
124 | 109 |
125 // A simple map from command line switches to equivalent switches in the | 110 // A simple map from command line switches to equivalent switches in the |
126 // distribution dictionary. Currently all switches added will be set to | 111 // distribution dictionary. Currently all switches added will be set to |
127 // 'true'. | 112 // 'true'. |
128 static const struct CmdLineSwitchToDistributionSwitch { | 113 static const struct CmdLineSwitchToDistributionSwitch { |
129 const char* cmd_line_switch; | 114 const char* cmd_line_switch; |
130 const char* distribution_switch; | 115 const char* distribution_switch; |
131 } translate_switches[] = { | 116 } translate_switches[] = { |
132 { installer::switches::kChrome, | |
133 installer::master_preferences::kChrome }, | |
134 { installer::switches::kDisableLogging, | 117 { installer::switches::kDisableLogging, |
135 installer::master_preferences::kDisableLogging }, | 118 installer::master_preferences::kDisableLogging }, |
136 { installer::switches::kMsi, | 119 { installer::switches::kMsi, |
137 installer::master_preferences::kMsi }, | 120 installer::master_preferences::kMsi }, |
138 { installer::switches::kMultiInstall, | |
139 installer::master_preferences::kMultiInstall }, | |
140 { installer::switches::kDoNotRegisterForUpdateLaunch, | 121 { installer::switches::kDoNotRegisterForUpdateLaunch, |
141 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, | 122 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, |
142 { installer::switches::kDoNotLaunchChrome, | 123 { installer::switches::kDoNotLaunchChrome, |
143 installer::master_preferences::kDoNotLaunchChrome }, | 124 installer::master_preferences::kDoNotLaunchChrome }, |
144 { installer::switches::kMakeChromeDefault, | 125 { installer::switches::kMakeChromeDefault, |
145 installer::master_preferences::kMakeChromeDefault }, | 126 installer::master_preferences::kMakeChromeDefault }, |
146 { installer::switches::kSystemLevel, | 127 { installer::switches::kSystemLevel, |
147 installer::master_preferences::kSystemLevel }, | 128 installer::master_preferences::kSystemLevel }, |
148 { installer::switches::kVerboseLogging, | 129 { installer::switches::kVerboseLogging, |
149 installer::master_preferences::kVerboseLogging }, | 130 installer::master_preferences::kVerboseLogging }, |
(...skipping 24 matching lines...) Expand all Loading... | |
174 std::string is_machine_var; | 155 std::string is_machine_var; |
175 env->GetVar(env_vars::kGoogleUpdateIsMachineEnvVar, &is_machine_var); | 156 env->GetVar(env_vars::kGoogleUpdateIsMachineEnvVar, &is_machine_var); |
176 if (is_machine_var == "1") { | 157 if (is_machine_var == "1") { |
177 VLOG(1) << "Taking system-level from environment."; | 158 VLOG(1) << "Taking system-level from environment."; |
178 name.assign(installer::master_preferences::kDistroDict); | 159 name.assign(installer::master_preferences::kDistroDict); |
179 name.append(".").append(installer::master_preferences::kSystemLevel); | 160 name.append(".").append(installer::master_preferences::kSystemLevel); |
180 master_dictionary_->SetBoolean(name, true); | 161 master_dictionary_->SetBoolean(name, true); |
181 } | 162 } |
182 } | 163 } |
183 | 164 |
165 // Strip multi-install from the dictionary, if present. | |
166 master_dictionary_->Remove(std::string(master_preferences::kDistroDict) + | |
167 '.' + master_preferences::kMultiInstall, | |
gab
2016/12/12 21:38:16
Why bother stripping it? We're not stripping kChro
grt (UTC plus 2)
2016/12/13 09:20:37
This is an insurance policy against code that look
gab
2016/12/14 16:33:38
Got it, can you clarify the comment to that effect
| |
168 nullptr); | |
169 | |
184 // Cache a pointer to the distribution dictionary. Ignore errors if any. | 170 // Cache a pointer to the distribution dictionary. Ignore errors if any. |
185 master_dictionary_->GetDictionary(installer::master_preferences::kDistroDict, | 171 master_dictionary_->GetDictionary(installer::master_preferences::kDistroDict, |
186 &distribution_); | 172 &distribution_); |
187 | |
188 InitializeProductFlags(); | |
189 #endif | 173 #endif |
190 } | 174 } |
191 | 175 |
192 void MasterPreferences::InitializeFromFilePath( | 176 void MasterPreferences::InitializeFromFilePath( |
193 const base::FilePath& prefs_path) { | 177 const base::FilePath& prefs_path) { |
194 std::string json_data; | 178 std::string json_data; |
195 // Failure to read the file is ignored as |json_data| will be the empty string | 179 // Failure to read the file is ignored as |json_data| will be the empty string |
196 // and the remainder of this MasterPreferences object should still be | 180 // and the remainder of this MasterPreferences object should still be |
197 // initialized as best as possible. | 181 // initialized as best as possible. |
198 if (base::PathExists(prefs_path) && | 182 if (base::PathExists(prefs_path) && |
(...skipping 11 matching lines...) Expand all Loading... | |
210 bool data_is_valid = true; | 194 bool data_is_valid = true; |
211 if (!master_dictionary_.get()) { | 195 if (!master_dictionary_.get()) { |
212 master_dictionary_.reset(new base::DictionaryValue()); | 196 master_dictionary_.reset(new base::DictionaryValue()); |
213 data_is_valid = false; | 197 data_is_valid = false; |
214 } else { | 198 } else { |
215 // Cache a pointer to the distribution dictionary. | 199 // Cache a pointer to the distribution dictionary. |
216 master_dictionary_->GetDictionary( | 200 master_dictionary_->GetDictionary( |
217 installer::master_preferences::kDistroDict, &distribution_); | 201 installer::master_preferences::kDistroDict, &distribution_); |
218 } | 202 } |
219 | 203 |
220 InitializeProductFlags(); | |
221 EnforceLegacyPreferences(); | 204 EnforceLegacyPreferences(); |
222 return data_is_valid; | 205 return data_is_valid; |
223 } | 206 } |
224 | 207 |
225 void MasterPreferences::InitializeProductFlags() { | |
226 // Make sure we start out with the correct defaults. | |
227 multi_install_ = false; | |
228 chrome_ = true; | |
229 | |
230 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); | |
231 | |
232 // When multi-install is specified, the checks are pretty simple (in theory): | |
233 // In order to be installed/uninstalled, each product must have its switch | |
234 // present on the command line. | |
235 // When multi-install is not set, operate on Chrome. | |
236 if (multi_install_) { | |
237 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) | |
238 chrome_ = false; | |
239 } else { | |
240 chrome_ = true; | |
241 } | |
242 } | |
243 | |
244 void MasterPreferences::EnforceLegacyPreferences() { | 208 void MasterPreferences::EnforceLegacyPreferences() { |
245 // If create_all_shortcuts was explicitly set to false, set | 209 // If create_all_shortcuts was explicitly set to false, set |
246 // do_not_create_(desktop|quick_launch)_shortcut to true. | 210 // do_not_create_(desktop|quick_launch)_shortcut to true. |
247 bool create_all_shortcuts = true; | 211 bool create_all_shortcuts = true; |
248 GetBool(installer::master_preferences::kCreateAllShortcuts, | 212 GetBool(installer::master_preferences::kCreateAllShortcuts, |
249 &create_all_shortcuts); | 213 &create_all_shortcuts); |
250 if (!create_all_shortcuts) { | 214 if (!create_all_shortcuts) { |
251 distribution_->SetBoolean( | 215 distribution_->SetBoolean( |
252 installer::master_preferences::kDoNotCreateDesktopShortcut, true); | 216 installer::master_preferences::kDoNotCreateDesktopShortcut, true); |
253 distribution_->SetBoolean( | 217 distribution_->SetBoolean( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 } | 273 } |
310 return result; | 274 return result; |
311 } | 275 } |
312 | 276 |
313 // static | 277 // static |
314 const MasterPreferences& MasterPreferences::ForCurrentProcess() { | 278 const MasterPreferences& MasterPreferences::ForCurrentProcess() { |
315 return g_master_preferences.Get(); | 279 return g_master_preferences.Get(); |
316 } | 280 } |
317 | 281 |
318 } // namespace installer | 282 } // namespace installer |
OLD | NEW |