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