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

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

Issue 4342001: Refactoring the master_preferences functions.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « chrome/installer/util/install_util.h ('k') | chrome/installer/util/master_preferences.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // See the corresponding header file for description of the functions in this 5 // See the corresponding header file for description of the functions in this
6 // file. 6 // file.
7 7
8 #include "chrome/installer/util/install_util.h" 8 #include "chrome/installer/util/install_util.h"
9 9
10 #include <shellapi.h> 10 #include <shellapi.h>
11 #include <shlobj.h> 11 #include <shlobj.h>
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "base/win/registry.h" 22 #include "base/win/registry.h"
23 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
24 #include "chrome/common/json_value_serializer.h" 24 #include "chrome/common/json_value_serializer.h"
25 #include "chrome/installer/util/browser_distribution.h" 25 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/google_update_constants.h" 26 #include "chrome/installer/util/google_update_constants.h"
27 #include "chrome/installer/util/l10n_string_util.h" 27 #include "chrome/installer/util/l10n_string_util.h"
28 #include "chrome/installer/util/master_preferences.h" 28 #include "chrome/installer/util/master_preferences_constants.h"
29 #include "chrome/installer/util/util_constants.h" 29 #include "chrome/installer/util/util_constants.h"
30 #include "chrome/installer/util/work_item_list.h" 30 #include "chrome/installer/util/work_item_list.h"
31 31
32 using base::win::RegKey; 32 using base::win::RegKey;
33 using installer_util::MasterPreferences;
34
35 const MasterPreferences& InstallUtil::GetMasterPreferencesForCurrentProcess() {
36 static MasterPreferences prefs(*CommandLine::ForCurrentProcess());
37 return prefs;
38 }
33 39
34 bool InstallUtil::ExecuteExeAsAdmin(const std::wstring& exe, 40 bool InstallUtil::ExecuteExeAsAdmin(const std::wstring& exe,
35 const std::wstring& params, 41 const std::wstring& params,
36 DWORD* exit_code) { 42 DWORD* exit_code) {
37 SHELLEXECUTEINFO info = {0}; 43 SHELLEXECUTEINFO info = {0};
38 info.cbSize = sizeof(SHELLEXECUTEINFO); 44 info.cbSize = sizeof(SHELLEXECUTEINFO);
39 info.fMask = SEE_MASK_NOCLOSEPROCESS; 45 info.fMask = SEE_MASK_NOCLOSEPROCESS;
40 info.lpVerb = L"runas"; 46 info.lpVerb = L"runas";
41 info.lpFile = exe.c_str(); 47 info.lpFile = exe.c_str();
42 info.lpParameters = params.c_str(); 48 info.lpParameters = params.c_str();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 131 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
126 SHGFP_TYPE_CURRENT, program_files_path))) { 132 SHGFP_TYPE_CURRENT, program_files_path))) {
127 return !StartsWith(exe_path, program_files_path, false); 133 return !StartsWith(exe_path, program_files_path, false);
128 } else { 134 } else {
129 NOTREACHED(); 135 NOTREACHED();
130 } 136 }
131 return true; 137 return true;
132 } 138 }
133 139
134 bool InstallUtil::IsChromeFrameProcess() { 140 bool InstallUtil::IsChromeFrameProcess() {
135 CommandLine* command_line = CommandLine::ForCurrentProcess();
136 DCHECK(command_line)
137 << "IsChromeFrameProcess() called before ComamandLine::Init()";
138
139 FilePath module_path; 141 FilePath module_path;
140 PathService::Get(base::FILE_MODULE, &module_path); 142 PathService::Get(base::FILE_MODULE, &module_path);
141 std::wstring module_name(module_path.BaseName().value()); 143 std::wstring module_name(module_path.BaseName().value());
142 144
143 scoped_ptr<DictionaryValue> prefs(installer_util::GetInstallPreferences( 145 const MasterPreferences& prefs = GetMasterPreferencesForCurrentProcess();
144 *command_line));
145 DCHECK(prefs.get());
146 bool is_cf = false; 146 bool is_cf = false;
147 installer_util::GetDistroBooleanPreference(prefs.get(), 147 prefs.GetBool(installer_util::master_preferences::kChromeFrame, &is_cf);
148 installer_util::master_preferences::kChromeFrame, &is_cf);
149 148
150 // Also assume this to be a ChromeFrame process if we are running inside 149 // Also assume this to be a ChromeFrame process if we are running inside
151 // the Chrome Frame DLL. 150 // the Chrome Frame DLL.
152 return is_cf || module_name == installer_util::kChromeFrameDll; 151 return is_cf || module_name == installer_util::kChromeFrameDll;
153 } 152 }
154 153
155 bool InstallUtil::IsChromeSxSProcess() { 154 bool InstallUtil::IsChromeSxSProcess() {
156 CommandLine* command_line = CommandLine::ForCurrentProcess(); 155 CommandLine* command_line = CommandLine::ForCurrentProcess();
157 CHECK(command_line); 156 CHECK(command_line);
158 157
159 if (command_line->HasSwitch(installer_util::switches::kChromeSxS)) 158 if (command_line->HasSwitch(installer_util::switches::kChromeSxS))
160 return true; 159 return true;
161 160
162 // Also return true if we are running from Chrome SxS installed path. 161 // Also return true if we are running from Chrome SxS installed path.
163 FilePath exe_dir; 162 FilePath exe_dir;
164 PathService::Get(base::DIR_EXE, &exe_dir); 163 PathService::Get(base::DIR_EXE, &exe_dir);
165 std::wstring chrome_sxs_dir(installer_util::kGoogleChromeInstallSubDir2); 164 std::wstring chrome_sxs_dir(installer_util::kGoogleChromeInstallSubDir2);
166 chrome_sxs_dir.append(installer_util::kSxSSuffix); 165 chrome_sxs_dir.append(installer_util::kSxSSuffix);
167 return FilePath::CompareEqualIgnoreCase(exe_dir.BaseName().value(), 166 return FilePath::CompareEqualIgnoreCase(exe_dir.BaseName().value(),
168 installer_util::kInstallBinaryDir) && 167 installer_util::kInstallBinaryDir) &&
169 FilePath::CompareEqualIgnoreCase(exe_dir.DirName().BaseName().value(), 168 FilePath::CompareEqualIgnoreCase(exe_dir.DirName().BaseName().value(),
170 chrome_sxs_dir); 169 chrome_sxs_dir);
171 } 170 }
172 171
173 bool InstallUtil::IsMSIProcess(bool system_level) { 172 bool InstallUtil::IsMSIProcess(bool system_level) {
174 // Initialize the static msi flags. 173 // Initialize the static msi flags.
175 static bool is_msi_ = false; 174 static bool is_msi_ = false;
176 static bool msi_checked_ = false; 175 static bool msi_checked_ = false;
177 176
178 CommandLine* command_line = CommandLine::ForCurrentProcess();
179 CHECK(command_line);
180
181 if (!msi_checked_) { 177 if (!msi_checked_) {
182 msi_checked_ = true; 178 msi_checked_ = true;
183 179
184 scoped_ptr<DictionaryValue> prefs(installer_util::GetInstallPreferences( 180 const MasterPreferences& prefs = GetMasterPreferencesForCurrentProcess();
185 *command_line)); 181
186 DCHECK(prefs.get());
187 bool is_msi = false; 182 bool is_msi = false;
188 installer_util::GetDistroBooleanPreference(prefs.get(), 183 prefs.GetBool(installer_util::master_preferences::kMsi, &is_msi);
189 installer_util::master_preferences::kMsi, &is_msi);
190 184
191 if (!is_msi) { 185 if (!is_msi) {
192 // We didn't find it in the preferences, try looking in the registry. 186 // We didn't find it in the preferences, try looking in the registry.
193 HKEY reg_root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 187 HKEY reg_root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
194 RegKey key; 188 RegKey key;
195 DWORD msi_value; 189 DWORD msi_value;
196 190
197 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 191 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
198 DCHECK(dist); 192 DCHECK(dist);
199 193
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 const std::wstring& value_name) { 268 const std::wstring& value_name) {
275 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); 269 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS);
276 VLOG(1) << "Deleting registry value " << value_name; 270 VLOG(1) << "Deleting registry value " << value_name;
277 if (key.ValueExists(value_name.c_str()) && 271 if (key.ValueExists(value_name.c_str()) &&
278 !key.DeleteValue(value_name.c_str())) { 272 !key.DeleteValue(value_name.c_str())) {
279 LOG(ERROR) << "Failed to delete registry value: " << value_name; 273 LOG(ERROR) << "Failed to delete registry value: " << value_name;
280 return false; 274 return false;
281 } 275 }
282 return true; 276 return true;
283 } 277 }
OLDNEW
« no previous file with comments | « chrome/installer/util/install_util.h ('k') | chrome/installer/util/master_preferences.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698