| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/common/json_value_serializer.h" | 12 #include "chrome/common/json_value_serializer.h" |
| 13 #include "chrome/installer/util/master_preferences_constants.h" | 13 #include "chrome/installer/util/master_preferences_constants.h" |
| 14 #include "chrome/installer/util/util_constants.h" | 14 #include "chrome/installer/util/util_constants.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kDistroDict[] = "distribution"; | 19 const char kDistroDict[] = "distribution"; |
| 20 const char kFirstRunTabs[] = "first_run_tabs"; | 20 const char kFirstRunTabs[] = "first_run_tabs"; |
| 21 | 21 |
| 22 base::LazyInstance<installer_util::MasterPreferences> g_master_preferences( | 22 base::LazyInstance<installer::MasterPreferences> g_master_preferences( |
| 23 base::LINKER_INITIALIZED); | 23 base::LINKER_INITIALIZED); |
| 24 | 24 |
| 25 bool GetGURLFromValue(const Value* in_value, GURL* out_value) { | 25 bool GetGURLFromValue(const Value* in_value, GURL* out_value) { |
| 26 if (!in_value || !out_value) | 26 if (!in_value || !out_value) |
| 27 return false; | 27 return false; |
| 28 std::string url; | 28 std::string url; |
| 29 in_value->GetAsString(&url); | 29 in_value->GetAsString(&url); |
| 30 GURL gurl(url); | 30 GURL gurl(url); |
| 31 *out_value = gurl; | 31 *out_value = gurl; |
| 32 return true; | 32 return true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (!root->IsType(Value::TYPE_DICTIONARY)) { | 68 if (!root->IsType(Value::TYPE_DICTIONARY)) { |
| 69 LOG(WARNING) << "Failed to parse master prefs file: " | 69 LOG(WARNING) << "Failed to parse master prefs file: " |
| 70 << "Root item must be a dictionary."; | 70 << "Root item must be a dictionary."; |
| 71 return NULL; | 71 return NULL; |
| 72 } | 72 } |
| 73 return static_cast<DictionaryValue*>(root.release()); | 73 return static_cast<DictionaryValue*>(root.release()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 namespace installer_util { | 78 namespace installer { |
| 79 | 79 |
| 80 MasterPreferences::MasterPreferences() : distribution_(NULL), | 80 MasterPreferences::MasterPreferences() : distribution_(NULL), |
| 81 preferences_read_from_file_(false), | 81 preferences_read_from_file_(false), |
| 82 ceee_(false), | 82 ceee_(false), |
| 83 chrome_(true), | 83 chrome_(true), |
| 84 chrome_frame_(false), | 84 chrome_frame_(false), |
| 85 multi_install_(false) { | 85 multi_install_(false) { |
| 86 InitializeFromCommandLine(*CommandLine::ForCurrentProcess()); | 86 InitializeFromCommandLine(*CommandLine::ForCurrentProcess()); |
| 87 } | 87 } |
| 88 | 88 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 InitializeProductFlags(); | 112 InitializeProductFlags(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 MasterPreferences::~MasterPreferences() { | 115 MasterPreferences::~MasterPreferences() { |
| 116 } | 116 } |
| 117 | 117 |
| 118 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { | 118 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { |
| 119 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 120 if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) { | 120 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { |
| 121 FilePath prefs_path(cmd_line.GetSwitchValuePath( | 121 FilePath prefs_path(cmd_line.GetSwitchValuePath( |
| 122 installer_util::switches::kInstallerData)); | 122 installer::switches::kInstallerData)); |
| 123 this->MasterPreferences::MasterPreferences(prefs_path); | 123 this->MasterPreferences::MasterPreferences(prefs_path); |
| 124 } else { | 124 } else { |
| 125 master_dictionary_.reset(new DictionaryValue()); | 125 master_dictionary_.reset(new DictionaryValue()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 DCHECK(master_dictionary_.get()); | 128 DCHECK(master_dictionary_.get()); |
| 129 | 129 |
| 130 // A simple map from command line switches to equivalent switches in the | 130 // A simple map from command line switches to equivalent switches in the |
| 131 // distribution dictionary. Currently all switches added will be set to | 131 // distribution dictionary. Currently all switches added will be set to |
| 132 // 'true'. | 132 // 'true'. |
| 133 static const struct CmdLineSwitchToDistributionSwitch { | 133 static const struct CmdLineSwitchToDistributionSwitch { |
| 134 const char* cmd_line_switch; | 134 const char* cmd_line_switch; |
| 135 const char* distribution_switch; | 135 const char* distribution_switch; |
| 136 } translate_switches[] = { | 136 } translate_switches[] = { |
| 137 { installer_util::switches::kCeee, | 137 { installer::switches::kCeee, |
| 138 installer_util::master_preferences::kCeee }, | 138 installer::master_preferences::kCeee }, |
| 139 { installer_util::switches::kChrome, | 139 { installer::switches::kChrome, |
| 140 installer_util::master_preferences::kChrome }, | 140 installer::master_preferences::kChrome }, |
| 141 { installer_util::switches::kChromeFrame, | 141 { installer::switches::kChromeFrame, |
| 142 installer_util::master_preferences::kChromeFrame }, | 142 installer::master_preferences::kChromeFrame }, |
| 143 { installer_util::switches::kCreateAllShortcuts, | 143 { installer::switches::kCreateAllShortcuts, |
| 144 installer_util::master_preferences::kCreateAllShortcuts }, | 144 installer::master_preferences::kCreateAllShortcuts }, |
| 145 { installer_util::switches::kDisableLogging, | 145 { installer::switches::kDisableLogging, |
| 146 installer_util::master_preferences::kDisableLogging }, | 146 installer::master_preferences::kDisableLogging }, |
| 147 { installer_util::switches::kDoNotCreateShortcuts, | 147 { installer::switches::kDoNotCreateShortcuts, |
| 148 installer_util::master_preferences::kDoNotCreateShortcuts }, | 148 installer::master_preferences::kDoNotCreateShortcuts }, |
| 149 { installer_util::switches::kMsi, | 149 { installer::switches::kMsi, |
| 150 installer_util::master_preferences::kMsi }, | 150 installer::master_preferences::kMsi }, |
| 151 { installer_util::switches::kMultiInstall, | 151 { installer::switches::kMultiInstall, |
| 152 installer_util::master_preferences::kMultiInstall }, | 152 installer::master_preferences::kMultiInstall }, |
| 153 { installer_util::switches::kDoNotRegisterForUpdateLaunch, | 153 { installer::switches::kDoNotRegisterForUpdateLaunch, |
| 154 installer_util::master_preferences::kDoNotRegisterForUpdateLaunch }, | 154 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, |
| 155 { installer_util::switches::kDoNotLaunchChrome, | 155 { installer::switches::kDoNotLaunchChrome, |
| 156 installer_util::master_preferences::kDoNotLaunchChrome }, | 156 installer::master_preferences::kDoNotLaunchChrome }, |
| 157 { installer_util::switches::kMakeChromeDefault, | 157 { installer::switches::kMakeChromeDefault, |
| 158 installer_util::master_preferences::kMakeChromeDefault }, | 158 installer::master_preferences::kMakeChromeDefault }, |
| 159 { installer_util::switches::kSystemLevel, | 159 { installer::switches::kSystemLevel, |
| 160 installer_util::master_preferences::kSystemLevel }, | 160 installer::master_preferences::kSystemLevel }, |
| 161 { installer_util::switches::kVerboseLogging, | 161 { installer::switches::kVerboseLogging, |
| 162 installer_util::master_preferences::kVerboseLogging }, | 162 installer::master_preferences::kVerboseLogging }, |
| 163 { installer_util::switches::kAltDesktopShortcut, | 163 { installer::switches::kAltDesktopShortcut, |
| 164 installer_util::master_preferences::kAltShortcutText }, | 164 installer::master_preferences::kAltShortcutText }, |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 std::string name(kDistroDict); | 167 std::string name(kDistroDict); |
| 168 for (int i = 0; i < arraysize(translate_switches); ++i) { | 168 for (int i = 0; i < arraysize(translate_switches); ++i) { |
| 169 if (cmd_line.HasSwitch(translate_switches[i].cmd_line_switch)) { | 169 if (cmd_line.HasSwitch(translate_switches[i].cmd_line_switch)) { |
| 170 name.resize(arraysize(kDistroDict) - 1); | 170 name.resize(arraysize(kDistroDict) - 1); |
| 171 name.append(".").append(translate_switches[i].distribution_switch); | 171 name.append(".").append(translate_switches[i].distribution_switch); |
| 172 master_dictionary_->SetBoolean(name, true); | 172 master_dictionary_->SetBoolean(name, true); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // See if the log file path was specified on the command line. | 176 // See if the log file path was specified on the command line. |
| 177 std::wstring str_value(cmd_line.GetSwitchValueNative( | 177 std::wstring str_value(cmd_line.GetSwitchValueNative( |
| 178 installer_util::switches::kLogFile)); | 178 installer::switches::kLogFile)); |
| 179 if (!str_value.empty()) { | 179 if (!str_value.empty()) { |
| 180 name.resize(arraysize(kDistroDict) - 1); | 180 name.resize(arraysize(kDistroDict) - 1); |
| 181 name.append(".").append(installer_util::master_preferences::kLogFile); | 181 name.append(".").append(installer::master_preferences::kLogFile); |
| 182 master_dictionary_->SetString(name, str_value); | 182 master_dictionary_->SetString(name, str_value); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Cache a pointer to the distribution dictionary. Ignore errors if any. | 185 // Cache a pointer to the distribution dictionary. Ignore errors if any. |
| 186 master_dictionary_->GetDictionary(kDistroDict, &distribution_); | 186 master_dictionary_->GetDictionary(kDistroDict, &distribution_); |
| 187 | 187 |
| 188 InitializeProductFlags(); | 188 InitializeProductFlags(); |
| 189 #endif | 189 #endif |
| 190 } | 190 } |
| 191 | 191 |
| 192 void MasterPreferences::InitializeProductFlags() { | 192 void MasterPreferences::InitializeProductFlags() { |
| 193 // Make sure we start out with the correct defaults. | 193 // Make sure we start out with the correct defaults. |
| 194 multi_install_ = false; | 194 multi_install_ = false; |
| 195 chrome_frame_ = false; | 195 chrome_frame_ = false; |
| 196 ceee_ = false; | 196 ceee_ = false; |
| 197 chrome_ = true; | 197 chrome_ = true; |
| 198 | 198 |
| 199 GetBool(installer_util::master_preferences::kMultiInstall, &multi_install_); | 199 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); |
| 200 GetBool(installer_util::master_preferences::kChromeFrame, &chrome_frame_); | 200 GetBool(installer::master_preferences::kChromeFrame, &chrome_frame_); |
| 201 GetBool(installer_util::master_preferences::kCeee, &ceee_); | 201 GetBool(installer::master_preferences::kCeee, &ceee_); |
| 202 | 202 |
| 203 // When multi-install is specified, the checks are pretty simple (in theory): | 203 // When multi-install is specified, the checks are pretty simple (in theory): |
| 204 // In order to be installed/uninstalled, each product must have its switch | 204 // In order to be installed/uninstalled, each product must have its switch |
| 205 // present on the command line. | 205 // present on the command line. |
| 206 // Before multi-install was introduced however, we only supported installing | 206 // Before multi-install was introduced however, we only supported installing |
| 207 // two products, Chrome and Chrome Frame. For the time being we need to | 207 // two products, Chrome and Chrome Frame. For the time being we need to |
| 208 // continue to support this mode where multi-install is not set. | 208 // continue to support this mode where multi-install is not set. |
| 209 // So, when multi-install is not set, we continue to support mutually | 209 // So, when multi-install is not set, we continue to support mutually |
| 210 // exclusive installation of Chrome and Chrome Frame in addition to supporting | 210 // exclusive installation of Chrome and Chrome Frame in addition to supporting |
| 211 // installation of CEEE with Chrome Frame. | 211 // installation of CEEE with Chrome Frame. |
| 212 | 212 |
| 213 // Regardless of multi install being present, CEEE always needs CF to | 213 // Regardless of multi install being present, CEEE always needs CF to |
| 214 // be installed. | 214 // be installed. |
| 215 if (ceee_) | 215 if (ceee_) |
| 216 chrome_frame_ = true; | 216 chrome_frame_ = true; |
| 217 | 217 |
| 218 if (multi_install_) { | 218 if (multi_install_) { |
| 219 if (!GetBool(installer_util::master_preferences::kChrome, &chrome_)) | 219 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) |
| 220 chrome_ = false; | 220 chrome_ = false; |
| 221 } else { | 221 } else { |
| 222 // If chrome-frame is on the command line however, we only install CF. | 222 // If chrome-frame is on the command line however, we only install CF. |
| 223 chrome_ = !chrome_frame_; | 223 chrome_ = !chrome_frame_; |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 bool MasterPreferences::GetBool(const std::string& name, bool* value) const { | 227 bool MasterPreferences::GetBool(const std::string& name, bool* value) const { |
| 228 bool ret = false; | 228 bool ret = false; |
| 229 if (distribution_) | 229 if (distribution_) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 253 bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const { | 253 bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const { |
| 254 return master_dictionary_->GetDictionary( | 254 return master_dictionary_->GetDictionary( |
| 255 master_preferences::kExtensionsBlock, extensions); | 255 master_preferences::kExtensionsBlock, extensions); |
| 256 } | 256 } |
| 257 | 257 |
| 258 // static | 258 // static |
| 259 const MasterPreferences& MasterPreferences::ForCurrentProcess() { | 259 const MasterPreferences& MasterPreferences::ForCurrentProcess() { |
| 260 return g_master_preferences.Get(); | 260 return g_master_preferences.Get(); |
| 261 } | 261 } |
| 262 } // installer_util | 262 } // installer_util |
| OLD | NEW |