| 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 "base/environment.h" | 7 #include "base/environment.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace installer { | 72 namespace installer { |
| 73 | 73 |
| 74 MasterPreferences::MasterPreferences() : distribution_(NULL), | 74 MasterPreferences::MasterPreferences() : distribution_(NULL), |
| 75 preferences_read_from_file_(false), | 75 preferences_read_from_file_(false), |
| 76 chrome_(true), | 76 chrome_(true), |
| 77 chrome_app_launcher_(false), | 77 chrome_app_launcher_(false), |
| 78 chrome_frame_(false), |
| 78 multi_install_(false) { | 79 multi_install_(false) { |
| 79 InitializeFromCommandLine(*CommandLine::ForCurrentProcess()); | 80 InitializeFromCommandLine(*CommandLine::ForCurrentProcess()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 MasterPreferences::MasterPreferences(const CommandLine& cmd_line) | 83 MasterPreferences::MasterPreferences(const CommandLine& cmd_line) |
| 83 : distribution_(NULL), | 84 : distribution_(NULL), |
| 84 preferences_read_from_file_(false), | 85 preferences_read_from_file_(false), |
| 85 chrome_(true), | 86 chrome_(true), |
| 86 chrome_app_launcher_(false), | 87 chrome_app_launcher_(false), |
| 88 chrome_frame_(false), |
| 87 multi_install_(false) { | 89 multi_install_(false) { |
| 88 InitializeFromCommandLine(cmd_line); | 90 InitializeFromCommandLine(cmd_line); |
| 89 } | 91 } |
| 90 | 92 |
| 91 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) | 93 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) |
| 92 : distribution_(NULL), | 94 : distribution_(NULL), |
| 93 preferences_read_from_file_(false), | 95 preferences_read_from_file_(false), |
| 94 chrome_(true), | 96 chrome_(true), |
| 95 chrome_app_launcher_(false), | 97 chrome_app_launcher_(false), |
| 98 chrome_frame_(false), |
| 96 multi_install_(false) { | 99 multi_install_(false) { |
| 97 std::string json_data; | 100 std::string json_data; |
| 98 // Failure to read the file is ignored as |json_data| will be the empty string | 101 // Failure to read the file is ignored as |json_data| will be the empty string |
| 99 // and the remainder of this MasterPreferences object should still be | 102 // and the remainder of this MasterPreferences object should still be |
| 100 // initialized as best as possible. | 103 // initialized as best as possible. |
| 101 if (base::PathExists(prefs_path) && | 104 if (base::PathExists(prefs_path) && |
| 102 !base::ReadFileToString(prefs_path, &json_data)) { | 105 !base::ReadFileToString(prefs_path, &json_data)) { |
| 103 LOG(ERROR) << "Failed to read preferences from " << prefs_path.value(); | 106 LOG(ERROR) << "Failed to read preferences from " << prefs_path.value(); |
| 104 } | 107 } |
| 105 if (InitializeFromString(json_data)) | 108 if (InitializeFromString(json_data)) |
| 106 preferences_read_from_file_ = true; | 109 preferences_read_from_file_ = true; |
| 107 } | 110 } |
| 108 | 111 |
| 109 MasterPreferences::MasterPreferences(const std::string& prefs) | 112 MasterPreferences::MasterPreferences(const std::string& prefs) |
| 110 : distribution_(NULL), | 113 : distribution_(NULL), |
| 111 preferences_read_from_file_(false), | 114 preferences_read_from_file_(false), |
| 112 chrome_(true), | 115 chrome_(true), |
| 113 chrome_app_launcher_(false), | 116 chrome_app_launcher_(false), |
| 117 chrome_frame_(false), |
| 114 multi_install_(false) { | 118 multi_install_(false) { |
| 115 InitializeFromString(prefs); | 119 InitializeFromString(prefs); |
| 116 } | 120 } |
| 117 | 121 |
| 118 MasterPreferences::~MasterPreferences() { | 122 MasterPreferences::~MasterPreferences() { |
| 119 } | 123 } |
| 120 | 124 |
| 121 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { | 125 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { |
| 122 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
| 123 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { | 127 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 const char* distribution_switch; | 142 const char* distribution_switch; |
| 139 } translate_switches[] = { | 143 } translate_switches[] = { |
| 140 { installer::switches::kAutoLaunchChrome, | 144 { installer::switches::kAutoLaunchChrome, |
| 141 installer::master_preferences::kAutoLaunchChrome }, | 145 installer::master_preferences::kAutoLaunchChrome }, |
| 142 { installer::switches::kChromeAppHostDeprecated, | 146 { installer::switches::kChromeAppHostDeprecated, |
| 143 installer::master_preferences::kChromeAppHostDeprecated }, | 147 installer::master_preferences::kChromeAppHostDeprecated }, |
| 144 { installer::switches::kChromeAppLauncher, | 148 { installer::switches::kChromeAppLauncher, |
| 145 installer::master_preferences::kChromeAppLauncher }, | 149 installer::master_preferences::kChromeAppLauncher }, |
| 146 { installer::switches::kChrome, | 150 { installer::switches::kChrome, |
| 147 installer::master_preferences::kChrome }, | 151 installer::master_preferences::kChrome }, |
| 152 { installer::switches::kChromeFrame, |
| 153 installer::master_preferences::kChromeFrame }, |
| 148 { installer::switches::kDisableLogging, | 154 { installer::switches::kDisableLogging, |
| 149 installer::master_preferences::kDisableLogging }, | 155 installer::master_preferences::kDisableLogging }, |
| 150 { installer::switches::kMsi, | 156 { installer::switches::kMsi, |
| 151 installer::master_preferences::kMsi }, | 157 installer::master_preferences::kMsi }, |
| 152 { installer::switches::kMultiInstall, | 158 { installer::switches::kMultiInstall, |
| 153 installer::master_preferences::kMultiInstall }, | 159 installer::master_preferences::kMultiInstall }, |
| 154 { installer::switches::kDoNotRegisterForUpdateLaunch, | 160 { installer::switches::kDoNotRegisterForUpdateLaunch, |
| 155 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, | 161 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, |
| 156 { installer::switches::kDoNotLaunchChrome, | 162 { installer::switches::kDoNotLaunchChrome, |
| 157 installer::master_preferences::kDoNotLaunchChrome }, | 163 installer::master_preferences::kDoNotLaunchChrome }, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 224 } |
| 219 | 225 |
| 220 InitializeProductFlags(); | 226 InitializeProductFlags(); |
| 221 EnforceLegacyPreferences(); | 227 EnforceLegacyPreferences(); |
| 222 return data_is_valid; | 228 return data_is_valid; |
| 223 } | 229 } |
| 224 | 230 |
| 225 void MasterPreferences::InitializeProductFlags() { | 231 void MasterPreferences::InitializeProductFlags() { |
| 226 // Make sure we start out with the correct defaults. | 232 // Make sure we start out with the correct defaults. |
| 227 multi_install_ = false; | 233 multi_install_ = false; |
| 234 chrome_frame_ = false; |
| 228 chrome_app_launcher_ = false; | 235 chrome_app_launcher_ = false; |
| 229 chrome_ = true; | 236 chrome_ = true; |
| 230 | 237 |
| 231 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); | 238 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); |
| 239 GetBool(installer::master_preferences::kChromeFrame, &chrome_frame_); |
| 232 | 240 |
| 233 GetBool(installer::master_preferences::kChromeAppLauncher, | 241 GetBool(installer::master_preferences::kChromeAppLauncher, |
| 234 &chrome_app_launcher_); | 242 &chrome_app_launcher_); |
| 235 | 243 |
| 236 // The deprecated switch --app-host behaves like --app-launcher. | 244 // The deprecated switch --app-host behaves like --app-launcher. |
| 237 bool chrome_app_host = false; | 245 bool chrome_app_host = false; |
| 238 GetBool(installer::master_preferences::kChromeAppHostDeprecated, | 246 GetBool(installer::master_preferences::kChromeAppHostDeprecated, |
| 239 &chrome_app_host); | 247 &chrome_app_host); |
| 240 chrome_app_launcher_ = chrome_app_launcher_ || chrome_app_host; | 248 chrome_app_launcher_ = chrome_app_launcher_ || chrome_app_host; |
| 241 | 249 |
| 242 // When multi-install is specified, the checks are pretty simple (in theory): | 250 // When multi-install is specified, the checks are pretty simple (in theory): |
| 243 // In order to be installed/uninstalled, each product must have its switch | 251 // In order to be installed/uninstalled, each product must have its switch |
| 244 // present on the command line. | 252 // present on the command line. |
| 245 // When multi-install is not set, operate on Chrome. | 253 // Before multi-install was introduced however, we only supported installing |
| 254 // two products, Chrome and Chrome Frame. For the time being we need to |
| 255 // continue to support this mode where multi-install is not set. |
| 256 // So, when multi-install is not set, we continue to support mutually |
| 257 // exclusive installation of Chrome and Chrome Frame. |
| 246 if (multi_install_) { | 258 if (multi_install_) { |
| 247 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) | 259 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) |
| 248 chrome_ = false; | 260 chrome_ = false; |
| 249 } else { | 261 } else { |
| 250 chrome_ = true; | 262 // If chrome-frame is on the command line however, we only install CF. |
| 263 chrome_ = !chrome_frame_; |
| 251 } | 264 } |
| 252 } | 265 } |
| 253 | 266 |
| 254 void MasterPreferences::EnforceLegacyPreferences() { | 267 void MasterPreferences::EnforceLegacyPreferences() { |
| 255 // If create_all_shortcuts was explicitly set to false, set | 268 // If create_all_shortcuts was explicitly set to false, set |
| 256 // do_not_create_(desktop|quick_launch)_shortcut to true. | 269 // do_not_create_(desktop|quick_launch)_shortcut to true. |
| 257 bool create_all_shortcuts = true; | 270 bool create_all_shortcuts = true; |
| 258 GetBool(installer::master_preferences::kCreateAllShortcuts, | 271 GetBool(installer::master_preferences::kCreateAllShortcuts, |
| 259 &create_all_shortcuts); | 272 &create_all_shortcuts); |
| 260 if (!create_all_shortcuts) { | 273 if (!create_all_shortcuts) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 master_dictionary_->GetString(prefs::kVariationsSeed, &variations_seed); | 328 master_dictionary_->GetString(prefs::kVariationsSeed, &variations_seed); |
| 316 return variations_seed; | 329 return variations_seed; |
| 317 } | 330 } |
| 318 | 331 |
| 319 // static | 332 // static |
| 320 const MasterPreferences& MasterPreferences::ForCurrentProcess() { | 333 const MasterPreferences& MasterPreferences::ForCurrentProcess() { |
| 321 return g_master_preferences.Get(); | 334 return g_master_preferences.Get(); |
| 322 } | 335 } |
| 323 | 336 |
| 324 } // namespace installer | 337 } // namespace installer |
| OLD | NEW |