Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: chrome/installer/util/master_preferences.cc

Issue 5756007: Revert 69165 - Merge the installer, installer_util and setup_util namespaces ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 { 78 namespace installer_util {
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
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::switches::kInstallerData)) { 120 if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) {
121 FilePath prefs_path(cmd_line.GetSwitchValuePath( 121 FilePath prefs_path(cmd_line.GetSwitchValuePath(
122 installer::switches::kInstallerData)); 122 installer_util::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::switches::kCeee, 137 { installer_util::switches::kCeee,
138 installer::master_preferences::kCeee }, 138 installer_util::master_preferences::kCeee },
139 { installer::switches::kChrome, 139 { installer_util::switches::kChrome,
140 installer::master_preferences::kChrome }, 140 installer_util::master_preferences::kChrome },
141 { installer::switches::kChromeFrame, 141 { installer_util::switches::kChromeFrame,
142 installer::master_preferences::kChromeFrame }, 142 installer_util::master_preferences::kChromeFrame },
143 { installer::switches::kCreateAllShortcuts, 143 { installer_util::switches::kCreateAllShortcuts,
144 installer::master_preferences::kCreateAllShortcuts }, 144 installer_util::master_preferences::kCreateAllShortcuts },
145 { installer::switches::kDisableLogging, 145 { installer_util::switches::kDisableLogging,
146 installer::master_preferences::kDisableLogging }, 146 installer_util::master_preferences::kDisableLogging },
147 { installer::switches::kDoNotCreateShortcuts, 147 { installer_util::switches::kDoNotCreateShortcuts,
148 installer::master_preferences::kDoNotCreateShortcuts }, 148 installer_util::master_preferences::kDoNotCreateShortcuts },
149 { installer::switches::kMsi, 149 { installer_util::switches::kMsi,
150 installer::master_preferences::kMsi }, 150 installer_util::master_preferences::kMsi },
151 { installer::switches::kMultiInstall, 151 { installer_util::switches::kMultiInstall,
152 installer::master_preferences::kMultiInstall }, 152 installer_util::master_preferences::kMultiInstall },
153 { installer::switches::kDoNotRegisterForUpdateLaunch, 153 { installer_util::switches::kDoNotRegisterForUpdateLaunch,
154 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, 154 installer_util::master_preferences::kDoNotRegisterForUpdateLaunch },
155 { installer::switches::kDoNotLaunchChrome, 155 { installer_util::switches::kDoNotLaunchChrome,
156 installer::master_preferences::kDoNotLaunchChrome }, 156 installer_util::master_preferences::kDoNotLaunchChrome },
157 { installer::switches::kMakeChromeDefault, 157 { installer_util::switches::kMakeChromeDefault,
158 installer::master_preferences::kMakeChromeDefault }, 158 installer_util::master_preferences::kMakeChromeDefault },
159 { installer::switches::kSystemLevel, 159 { installer_util::switches::kSystemLevel,
160 installer::master_preferences::kSystemLevel }, 160 installer_util::master_preferences::kSystemLevel },
161 { installer::switches::kVerboseLogging, 161 { installer_util::switches::kVerboseLogging,
162 installer::master_preferences::kVerboseLogging }, 162 installer_util::master_preferences::kVerboseLogging },
163 { installer::switches::kAltDesktopShortcut, 163 { installer_util::switches::kAltDesktopShortcut,
164 installer::master_preferences::kAltShortcutText }, 164 installer_util::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::switches::kLogFile)); 178 installer_util::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::master_preferences::kLogFile); 181 name.append(".").append(installer_util::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::master_preferences::kMultiInstall, &multi_install_); 199 GetBool(installer_util::master_preferences::kMultiInstall, &multi_install_);
200 GetBool(installer::master_preferences::kChromeFrame, &chrome_frame_); 200 GetBool(installer_util::master_preferences::kChromeFrame, &chrome_frame_);
201 GetBool(installer::master_preferences::kCeee, &ceee_); 201 GetBool(installer_util::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::master_preferences::kChrome, &chrome_)) 219 if (!GetBool(installer_util::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
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
OLDNEW
« no previous file with comments | « chrome/installer/util/master_preferences.h ('k') | chrome/installer/util/master_preferences_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698