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

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

Issue 165382: Merge 22284 - Refactoring of master preferences parsing before adding a new p... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: 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 | Annotate | Revision Log
« 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')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/chrome/installer/setup/install.cc:r69-2775
Merged /trunk/src/chrome/installer/setup/install.cc:r22284
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 // We try to register Chrome as a valid browser on local machine. This 286 // We try to register Chrome as a valid browser on local machine. This
290 // will work only if current user has admin rights. 287 // will work only if current user has admin rights.
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 ShellUtil::RegisterStatus ret = ShellUtil::FAILURE; 291 if (make_chrome_default) {
295 if (options & installer_util::MAKE_CHROME_DEFAULT) {
296 ret = ShellUtil::AddChromeToSetAccessDefaults(chrome_exe, false); 292 ret = ShellUtil::AddChromeToSetAccessDefaults(chrome_exe, false);
297 if (ret == ShellUtil::SUCCESS) { 293 if (ret == ShellUtil::SUCCESS) {
298 if (system_level) { 294 if (system_level) {
299 ShellUtil::MakeChromeDefault( 295 ShellUtil::MakeChromeDefault(
300 ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, chrome_exe); 296 ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, chrome_exe);
301 } else { 297 } else {
302 ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, chrome_exe); 298 ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, chrome_exe);
303 } 299 }
304 } 300 }
305 } else { 301 } else {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (!success) { 479 if (!success) {
484 LOG(ERROR) << "Install failed, rolling back... "; 480 LOG(ERROR) << "Install failed, rolling back... ";
485 install_list->Rollback(); 481 install_list->Rollback();
486 LOG(ERROR) << "Rollback complete. "; 482 LOG(ERROR) << "Rollback complete. ";
487 } 483 }
488 return success; 484 return success;
489 } 485 }
490 486
491 installer_util::InstallStatus installer::InstallOrUpdateChrome( 487 installer_util::InstallStatus installer::InstallOrUpdateChrome(
492 const std::wstring& exe_path, const std::wstring& archive_path, 488 const std::wstring& exe_path, const std::wstring& archive_path,
493 const std::wstring& install_temp_path, int options, 489 const std::wstring& install_temp_path, const DictionaryValue* prefs,
494 const Version& new_version, const Version* installed_version) { 490 const Version& new_version, const Version* installed_version) {
495 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; 491 bool system_install = installer_util::GetDistroBooleanPreference(prefs,
492 installer_util::master_preferences::kSystemLevel);
496 std::wstring install_path(GetChromeInstallPath(system_install)); 493 std::wstring install_path(GetChromeInstallPath(system_install));
497 if (install_path.empty()) { 494 if (install_path.empty()) {
498 LOG(ERROR) << "Could not get installation destination path."; 495 LOG(ERROR) << "Could not get installation destination path.";
499 return installer_util::INSTALL_FAILED; 496 return installer_util::INSTALL_FAILED;
500 } else { 497 } else {
501 LOG(INFO) << "install destination path: " << install_path; 498 LOG(INFO) << "install destination path: " << install_path;
502 } 499 }
503 500
504 std::wstring src_path(install_temp_path); 501 std::wstring src_path(install_temp_path);
505 file_util::AppendToPath(&src_path, std::wstring(kInstallSourceDir)); 502 file_util::AppendToPath(&src_path, std::wstring(kInstallSourceDir));
(...skipping 20 matching lines...) Expand all
526 } else { 523 } else {
527 LOG(ERROR) << "Not sure how we got here." 524 LOG(ERROR) << "Not sure how we got here."
528 << " New version: " << new_version.GetString() 525 << " New version: " << new_version.GetString()
529 << ", installed version: " << installed_version->GetString(); 526 << ", installed version: " << installed_version->GetString();
530 // This should never happen but we are seeing some inconsistent exit 527 // This should never happen but we are seeing some inconsistent exit
531 // code reports in Omaha logs. We will treat this case as update to 528 // code reports in Omaha logs. We will treat this case as update to
532 // see if the inconsistency goes away. 529 // see if the inconsistency goes away.
533 result = installer_util::NEW_VERSION_UPDATED; 530 result = installer_util::NEW_VERSION_UPDATED;
534 } 531 }
535 532
536 if (!CreateOrUpdateChromeShortcuts(exe_path, options, result, 533 bool create_all_shortcut = installer_util::GetDistroBooleanPreference(prefs,
537 install_path, new_version.GetString())) 534 installer_util::master_preferences::kCreateAllShortcuts);
535 bool alt_shortcut = installer_util::GetDistroBooleanPreference(prefs,
536 installer_util::master_preferences::kAltShortcutText);
537 if (!CreateOrUpdateChromeShortcuts(exe_path, install_path,
538 new_version.GetString(), result,
539 system_install, create_all_shortcut,
540 alt_shortcut))
538 LOG(WARNING) << "Failed to create/update start menu shortcut."; 541 LOG(WARNING) << "Failed to create/update start menu shortcut.";
539 542
540 RemoveOldVersionDirs(install_path, new_version.GetString()); 543 RemoveOldVersionDirs(install_path, new_version.GetString());
541 544
542 RegisterChromeOnMachine(install_path, options); 545 bool make_chrome_default = installer_util::GetDistroBooleanPreference(prefs,
546 installer_util::master_preferences::kMakeChromeDefault);
547 RegisterChromeOnMachine(install_path, system_install, make_chrome_default);
543 } 548 }
544 549
545 return result; 550 return result;
546 } 551 }
547 552
548 std::wstring installer::GetInstallerPathUnderChrome( 553 std::wstring installer::GetInstallerPathUnderChrome(
549 const std::wstring& install_path, const std::wstring& new_version) { 554 const std::wstring& install_path, const std::wstring& new_version) {
550 std::wstring installer_path(install_path); 555 std::wstring installer_path(install_path);
551 file_util::AppendToPath(&installer_path, new_version); 556 file_util::AppendToPath(&installer_path, new_version);
552 file_util::AppendToPath(&installer_path, installer_util::kInstallerDir); 557 file_util::AppendToPath(&installer_path, installer_util::kInstallerDir);
553 return installer_path; 558 return installer_path;
554 } 559 }
555 560
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