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

Side by Side Diff: chrome/installer/setup/install.cc

Issue 159539: Refactoring of master preferences parsing before adding a new preference. (Closed)
Patch Set: rename variable Created 11 years, 4 months 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
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/setup_main.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <shlobj.h> 5 #include <shlobj.h>
6 #include <time.h> 6 #include <time.h>
7 7
8 #include "chrome/installer/setup/install.h" 8 #include "chrome/installer/setup/install.h"
9 9
10 #include "base/command_line.h"
11 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/registry.h" 13 #include "base/registry.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/string_util.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/installer/setup/setup_constants.h" 15 #include "chrome/installer/setup/setup_constants.h"
18 #include "chrome/installer/util/browser_distribution.h" 16 #include "chrome/installer/util/browser_distribution.h"
19 #include "chrome/installer/util/create_reg_key_work_item.h" 17 #include "chrome/installer/util/create_reg_key_work_item.h"
20 #include "chrome/installer/util/google_update_constants.h" 18 #include "chrome/installer/util/google_update_constants.h"
21 #include "chrome/installer/util/helper.h" 19 #include "chrome/installer/util/helper.h"
22 #include "chrome/installer/util/install_util.h" 20 #include "chrome/installer/util/install_util.h"
21 #include "chrome/installer/util/master_preferences.h"
23 #include "chrome/installer/util/set_reg_value_work_item.h" 22 #include "chrome/installer/util/set_reg_value_work_item.h"
24 #include "chrome/installer/util/shell_util.h" 23 #include "chrome/installer/util/shell_util.h"
25 #include "chrome/installer/util/util_constants.h" 24 #include "chrome/installer/util/util_constants.h"
26 #include "chrome/installer/util/work_item.h"
27 #include "chrome/installer/util/version.h"
28 #include "chrome/installer/util/work_item_list.h" 25 #include "chrome/installer/util/work_item_list.h"
29 26
30 // Build-time generated include file. 27 // Build-time generated include file.
31 #include "installer_util_strings.h" 28 #include "installer_util_strings.h"
32 #include "registered_dlls.h" 29 #include "registered_dlls.h"
33 30
34 namespace { 31 namespace {
35 32
36 std::wstring AppendPath(const std::wstring& parent_path, 33 std::wstring AppendPath(const std::wstring& parent_path,
37 const std::wstring& path) { 34 const std::wstring& path) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // uninstalling chrome. 150 // uninstalling chrome.
154 // If first_install is false, the function only updates the shortcut for 151 // If first_install is false, the function only updates the shortcut for
155 // uninstalling chrome. According to 152 // uninstalling chrome. According to
156 // http://blogs.msdn.com/oldnewthing/archive/2005/11/24/496690.aspx, 153 // http://blogs.msdn.com/oldnewthing/archive/2005/11/24/496690.aspx,
157 // updating uninstall shortcut should not trigger Windows "new application 154 // updating uninstall shortcut should not trigger Windows "new application
158 // installed" notification. 155 // installed" notification.
159 // 156 //
160 // If the shortcuts do not exist, the function does not recreate them during 157 // If the shortcuts do not exist, the function does not recreate them during
161 // update. 158 // update.
162 bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path, 159 bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path,
163 int options, 160 const std::wstring& install_path,
161 const std::wstring& new_version,
164 installer_util::InstallStatus install_status, 162 installer_util::InstallStatus install_status,
165 const std::wstring& install_path, 163 bool system_install,
166 const std::wstring& new_version) { 164 bool create_all_shortcut,
167 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; 165 bool alt_shortcut) {
168 FilePath shortcut_path; 166 FilePath shortcut_path;
169 int dir_enum = (system_install) ? base::DIR_COMMON_START_MENU : 167 int dir_enum = (system_install) ? base::DIR_COMMON_START_MENU :
170 base::DIR_START_MENU; 168 base::DIR_START_MENU;
171 if (!PathService::Get(dir_enum, &shortcut_path)) { 169 if (!PathService::Get(dir_enum, &shortcut_path)) {
172 LOG(ERROR) << "Failed to get location for shortcut."; 170 LOG(ERROR) << "Failed to get location for shortcut.";
173 return false; 171 return false;
174 } 172 }
175 173
176 // The location of Start->Programs->Google Chrome folder 174 // The location of Start->Programs->Google Chrome folder
177 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 175 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 ret = ret && file_util::CreateShortcutLink(setup_exe.c_str(), 233 ret = ret && file_util::CreateShortcutLink(setup_exe.c_str(),
236 uninstall_link.value().c_str(), 234 uninstall_link.value().c_str(),
237 NULL, 235 NULL,
238 arguments.c_str(), 236 arguments.c_str(),
239 NULL, setup_exe.c_str(), 0); 237 NULL, setup_exe.c_str(), 0);
240 } 238 }
241 239
242 // Update Desktop and Quick Launch shortcuts. If --create-new-shortcuts 240 // Update Desktop and Quick Launch shortcuts. If --create-new-shortcuts
243 // is specified we want to create them, otherwise we update them only if 241 // is specified we want to create them, otherwise we update them only if
244 // they exist. 242 // they exist.
245 bool create = (options & installer_util::CREATE_ALL_SHORTCUTS) != 0;
246 // In some cases the main desktop shortcut has an alternate name.
247 bool alt_shortcut = (options & installer_util::ALT_DESKTOP_SHORTCUT) != 0;
248
249 if (system_install) { 243 if (system_install) {
250 ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe, 244 ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe,
251 product_desc, ShellUtil::SYSTEM_LEVEL, alt_shortcut, create); 245 product_desc, ShellUtil::SYSTEM_LEVEL, alt_shortcut,
246 create_all_shortcut);
252 ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe, 247 ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe,
253 ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, create); 248 ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, create_all_shortcut);
254 } else { 249 } else {
255 ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe, 250 ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe,
256 product_desc, ShellUtil::CURRENT_USER, alt_shortcut, create); 251 product_desc, ShellUtil::CURRENT_USER, alt_shortcut,
252 create_all_shortcut);
257 ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe, 253 ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe,
258 ShellUtil::CURRENT_USER, create); 254 ShellUtil::CURRENT_USER, create_all_shortcut);
259 } 255 }
260 256
261 return ret; 257 return ret;
262 } 258 }
263 259
264 // This method tells if we are running on 64 bit platform so that we can copy 260 // This method tells if we are running on 64 bit platform so that we can copy
265 // one extra exe. If the API call to determine 64 bit fails, we play it safe 261 // one extra exe. If the API call to determine 64 bit fails, we play it safe
266 // and return true anyway so that the executable can be copied. 262 // and return true anyway so that the executable can be copied.
267 bool Is64bit() { 263 bool Is64bit() {
268 typedef BOOL (WINAPI *WOW_FUNC)(HANDLE, PBOOL); 264 typedef BOOL (WINAPI *WOW_FUNC)(HANDLE, PBOOL);
269 BOOL is64 = FALSE; 265 BOOL is64 = FALSE;
270 266
271 HANDLE handle = GetCurrentProcess(); 267 HANDLE handle = GetCurrentProcess();
272 HMODULE module = GetModuleHandle(L"kernel32.dll"); 268 HMODULE module = GetModuleHandle(L"kernel32.dll");
273 WOW_FUNC p = reinterpret_cast<WOW_FUNC>(GetProcAddress(module, 269 WOW_FUNC p = reinterpret_cast<WOW_FUNC>(GetProcAddress(module,
274 "IsWow64Process")); 270 "IsWow64Process"));
275 if ((p != NULL) && (!(p)(handle, &is64) || (is64 != FALSE))) { 271 if ((p != NULL) && (!(p)(handle, &is64) || (is64 != FALSE))) {
276 return true; 272 return true;
277 } 273 }
278 274
279 return false; 275 return false;
280 } 276 }
281 277
282 void RegisterChromeOnMachine(const std::wstring& install_path, int options) { 278 void RegisterChromeOnMachine(const std::wstring& install_path,
283 bool system_level = (options & installer_util::SYSTEM_LEVEL) != 0; 279 bool system_level,
280 bool make_chrome_default) {
284 // Try to add Chrome to Media Player shim inclusion list. We don't do any 281 // Try to add Chrome to Media Player shim inclusion list. We don't do any
285 // error checking here because this operation will fail if user doesn't 282 // error checking here because this operation will fail if user doesn't
286 // have admin rights and we want to ignore the error. 283 // have admin rights and we want to ignore the error.
287 AddChromeToMediaPlayerList(); 284 AddChromeToMediaPlayerList();
288 285
289 // Is --make-chrome-default option is given we make Chrome default browser 286 // Is --make-chrome-default option is given we make Chrome default browser
290 // otherwise we only register it on the machine as a valid browser. 287 // otherwise we only register it on the machine as a valid browser.
291 std::wstring chrome_exe(install_path); 288 std::wstring chrome_exe(install_path);
292 file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); 289 file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe);
293 LOG(INFO) << "Registering Chrome as browser"; 290 LOG(INFO) << "Registering Chrome as browser";
294 if (options & installer_util::MAKE_CHROME_DEFAULT) { 291 if (make_chrome_default) {
295 int level = ShellUtil::CURRENT_USER; 292 int level = ShellUtil::CURRENT_USER;
296 if (system_level) 293 if (system_level)
297 level = level | ShellUtil::SYSTEM_LEVEL; 294 level = level | ShellUtil::SYSTEM_LEVEL;
298 ShellUtil::MakeChromeDefault(level, chrome_exe, true); 295 ShellUtil::MakeChromeDefault(level, chrome_exe, true);
299 } else { 296 } else {
300 ShellUtil::RegisterChromeBrowser(chrome_exe, L"", false); 297 ShellUtil::RegisterChromeBrowser(chrome_exe, L"", false);
301 } 298 }
302 } 299 }
303 } // namespace 300 } // namespace
304 301
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (!success) { 473 if (!success) {
477 LOG(ERROR) << "Install failed, rolling back... "; 474 LOG(ERROR) << "Install failed, rolling back... ";
478 install_list->Rollback(); 475 install_list->Rollback();
479 LOG(ERROR) << "Rollback complete. "; 476 LOG(ERROR) << "Rollback complete. ";
480 } 477 }
481 return success; 478 return success;
482 } 479 }
483 480
484 installer_util::InstallStatus installer::InstallOrUpdateChrome( 481 installer_util::InstallStatus installer::InstallOrUpdateChrome(
485 const std::wstring& exe_path, const std::wstring& archive_path, 482 const std::wstring& exe_path, const std::wstring& archive_path,
486 const std::wstring& install_temp_path, int options, 483 const std::wstring& install_temp_path, const DictionaryValue* prefs,
487 const Version& new_version, const Version* installed_version) { 484 const Version& new_version, const Version* installed_version) {
488 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; 485 bool system_install = installer_util::GetDistroBooleanPreference(prefs,
486 installer_util::master_preferences::kSystemLevel);
489 std::wstring install_path(GetChromeInstallPath(system_install)); 487 std::wstring install_path(GetChromeInstallPath(system_install));
490 if (install_path.empty()) { 488 if (install_path.empty()) {
491 LOG(ERROR) << "Could not get installation destination path."; 489 LOG(ERROR) << "Could not get installation destination path.";
492 return installer_util::INSTALL_FAILED; 490 return installer_util::INSTALL_FAILED;
493 } else { 491 } else {
494 LOG(INFO) << "install destination path: " << install_path; 492 LOG(INFO) << "install destination path: " << install_path;
495 } 493 }
496 494
497 std::wstring src_path(install_temp_path); 495 std::wstring src_path(install_temp_path);
498 file_util::AppendToPath(&src_path, std::wstring(kInstallSourceDir)); 496 file_util::AppendToPath(&src_path, std::wstring(kInstallSourceDir));
(...skipping 20 matching lines...) Expand all
519 } else { 517 } else {
520 LOG(ERROR) << "Not sure how we got here." 518 LOG(ERROR) << "Not sure how we got here."
521 << " New version: " << new_version.GetString() 519 << " New version: " << new_version.GetString()
522 << ", installed version: " << installed_version->GetString(); 520 << ", installed version: " << installed_version->GetString();
523 // This should never happen but we are seeing some inconsistent exit 521 // This should never happen but we are seeing some inconsistent exit
524 // code reports in Omaha logs. We will treat this case as update to 522 // code reports in Omaha logs. We will treat this case as update to
525 // see if the inconsistency goes away. 523 // see if the inconsistency goes away.
526 result = installer_util::NEW_VERSION_UPDATED; 524 result = installer_util::NEW_VERSION_UPDATED;
527 } 525 }
528 526
529 if (!CreateOrUpdateChromeShortcuts(exe_path, options, result, 527 bool create_all_shortcut = installer_util::GetDistroBooleanPreference(prefs,
530 install_path, new_version.GetString())) 528 installer_util::master_preferences::kCreateAllShortcuts);
529 bool alt_shortcut = installer_util::GetDistroBooleanPreference(prefs,
530 installer_util::master_preferences::kAltShortcutText);
531 if (!CreateOrUpdateChromeShortcuts(exe_path, install_path,
532 new_version.GetString(), result,
533 system_install, create_all_shortcut,
534 alt_shortcut))
531 LOG(WARNING) << "Failed to create/update start menu shortcut."; 535 LOG(WARNING) << "Failed to create/update start menu shortcut.";
532 536
533 RemoveOldVersionDirs(install_path, new_version.GetString()); 537 RemoveOldVersionDirs(install_path, new_version.GetString());
534 538
535 RegisterChromeOnMachine(install_path, options); 539 bool make_chrome_default = installer_util::GetDistroBooleanPreference(prefs,
540 installer_util::master_preferences::kMakeChromeDefault);
541 RegisterChromeOnMachine(install_path, system_install, make_chrome_default);
536 } 542 }
537 543
538 return result; 544 return result;
539 } 545 }
540 546
541 std::wstring installer::GetInstallerPathUnderChrome( 547 std::wstring installer::GetInstallerPathUnderChrome(
542 const std::wstring& install_path, const std::wstring& new_version) { 548 const std::wstring& install_path, const std::wstring& new_version) {
543 std::wstring installer_path(install_path); 549 std::wstring installer_path(install_path);
544 file_util::AppendToPath(&installer_path, new_version); 550 file_util::AppendToPath(&installer_path, new_version);
545 file_util::AppendToPath(&installer_path, installer_util::kInstallerDir); 551 file_util::AppendToPath(&installer_path, installer_util::kInstallerDir);
546 return installer_path; 552 return installer_path;
547 } 553 }
548 554
OLDNEW
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/setup_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698