| 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. This ensures that any |
| 166 // code that probes the dictionary directly to check for multi-install (rather |
| 167 // than calling is_multi_install()) receives false. The updated dictionary is |
| 168 // not written back to disk. |
| 169 master_dictionary_->Remove(std::string(master_preferences::kDistroDict) + |
| 170 '.' + master_preferences::kMultiInstall, |
| 171 nullptr); |
| 172 |
| 184 // Cache a pointer to the distribution dictionary. Ignore errors if any. | 173 // Cache a pointer to the distribution dictionary. Ignore errors if any. |
| 185 master_dictionary_->GetDictionary(installer::master_preferences::kDistroDict, | 174 master_dictionary_->GetDictionary(installer::master_preferences::kDistroDict, |
| 186 &distribution_); | 175 &distribution_); |
| 187 | |
| 188 InitializeProductFlags(); | |
| 189 #endif | 176 #endif |
| 190 } | 177 } |
| 191 | 178 |
| 192 void MasterPreferences::InitializeFromFilePath( | 179 void MasterPreferences::InitializeFromFilePath( |
| 193 const base::FilePath& prefs_path) { | 180 const base::FilePath& prefs_path) { |
| 194 std::string json_data; | 181 std::string json_data; |
| 195 // Failure to read the file is ignored as |json_data| will be the empty string | 182 // 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 | 183 // and the remainder of this MasterPreferences object should still be |
| 197 // initialized as best as possible. | 184 // initialized as best as possible. |
| 198 if (base::PathExists(prefs_path) && | 185 if (base::PathExists(prefs_path) && |
| (...skipping 11 matching lines...) Expand all Loading... |
| 210 bool data_is_valid = true; | 197 bool data_is_valid = true; |
| 211 if (!master_dictionary_.get()) { | 198 if (!master_dictionary_.get()) { |
| 212 master_dictionary_.reset(new base::DictionaryValue()); | 199 master_dictionary_.reset(new base::DictionaryValue()); |
| 213 data_is_valid = false; | 200 data_is_valid = false; |
| 214 } else { | 201 } else { |
| 215 // Cache a pointer to the distribution dictionary. | 202 // Cache a pointer to the distribution dictionary. |
| 216 master_dictionary_->GetDictionary( | 203 master_dictionary_->GetDictionary( |
| 217 installer::master_preferences::kDistroDict, &distribution_); | 204 installer::master_preferences::kDistroDict, &distribution_); |
| 218 } | 205 } |
| 219 | 206 |
| 220 InitializeProductFlags(); | |
| 221 EnforceLegacyPreferences(); | 207 EnforceLegacyPreferences(); |
| 222 return data_is_valid; | 208 return data_is_valid; |
| 223 } | 209 } |
| 224 | 210 |
| 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() { | 211 void MasterPreferences::EnforceLegacyPreferences() { |
| 245 // If create_all_shortcuts was explicitly set to false, set | 212 // If create_all_shortcuts was explicitly set to false, set |
| 246 // do_not_create_(desktop|quick_launch)_shortcut to true. | 213 // do_not_create_(desktop|quick_launch)_shortcut to true. |
| 247 bool create_all_shortcuts = true; | 214 bool create_all_shortcuts = true; |
| 248 GetBool(installer::master_preferences::kCreateAllShortcuts, | 215 GetBool(installer::master_preferences::kCreateAllShortcuts, |
| 249 &create_all_shortcuts); | 216 &create_all_shortcuts); |
| 250 if (!create_all_shortcuts) { | 217 if (!create_all_shortcuts) { |
| 251 distribution_->SetBoolean( | 218 distribution_->SetBoolean( |
| 252 installer::master_preferences::kDoNotCreateDesktopShortcut, true); | 219 installer::master_preferences::kDoNotCreateDesktopShortcut, true); |
| 253 distribution_->SetBoolean( | 220 distribution_->SetBoolean( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 276 } |
| 310 return result; | 277 return result; |
| 311 } | 278 } |
| 312 | 279 |
| 313 // static | 280 // static |
| 314 const MasterPreferences& MasterPreferences::ForCurrentProcess() { | 281 const MasterPreferences& MasterPreferences::ForCurrentProcess() { |
| 315 return g_master_preferences.Get(); | 282 return g_master_preferences.Get(); |
| 316 } | 283 } |
| 317 | 284 |
| 318 } // namespace installer | 285 } // namespace installer |
| OLD | NEW |