Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/setup/install.h" | 5 #include "chrome/installer/setup/install.h" |
| 6 | 6 |
| 7 #include <shlobj.h> | 7 #include <shlobj.h> |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 #include <winuser.h> | 9 #include <winuser.h> |
| 10 | 10 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 | 258 |
| 259 void CreateOrUpdateStartMenuAndTaskbarShortcuts( | 259 void CreateOrUpdateStartMenuAndTaskbarShortcuts( |
| 260 const InstallerState& installer_state, | 260 const InstallerState& installer_state, |
| 261 const FilePath& setup_exe, | 261 const FilePath& setup_exe, |
| 262 const Product& product, | 262 const Product& product, |
| 263 uint32 options) { | 263 uint32 options) { |
| 264 // TODO(tommi): Change this function to use WorkItemList. | 264 // TODO(tommi): Change this function to use WorkItemList. |
| 265 DCHECK(product.is_chrome()); | 265 DCHECK(product.is_chrome()); |
| 266 | 266 |
| 267 // Information used for all shortcut types | 267 // Information used for all shortcut types |
| 268 BrowserDistribution* browser_dist = product.distribution(); | 268 BrowserDistribution* dist = product.distribution(); |
| 269 const string16 product_name(browser_dist->GetAppShortCutName()); | 269 const string16 product_desc(dist->GetAppDescription()); |
| 270 const string16 product_desc(browser_dist->GetAppDescription()); | |
| 271 // Chrome link target | 270 // Chrome link target |
| 272 FilePath chrome_exe( | 271 FilePath chrome_exe( |
| 273 installer_state.target_path().Append(installer::kChromeExe)); | 272 installer_state.target_path().Append(installer::kChromeExe)); |
| 274 | 273 |
| 275 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); | 274 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); |
| 276 const char* operation = create_always ? "Creating" : "Updating"; | 275 const char* operation = create_always ? "Creating" : "Updating"; |
| 277 | 276 |
| 278 // Create Start Menu shortcuts. | 277 VLOG(1) << operation << " Start Menu shortcut for " << chrome_exe.value() |
| 279 // The location of Start->Programs->Google Chrome folder | 278 << ((create_always && |
| 280 FilePath start_menu_folder_path; | 279 base::win::GetVersion() >= base::win::VERSION_WIN7) ? |
| 281 int dir_enum = installer_state.system_install() ? | 280 " and pinning it to the taskbar." : "."); |
| 282 base::DIR_COMMON_START_MENU : base::DIR_START_MENU; | 281 if (!ShellUtil::CreateOrUpdateChromeShortcut( |
| 283 if (!PathService::Get(dir_enum, &start_menu_folder_path)) { | 282 ShellUtil::SHORTCUT_START_MENU, dist, chrome_exe.value(), |
| 284 LOG(ERROR) << "Failed to get start menu path."; | 283 product_desc, string16(), string16(), chrome_exe.value(), |
| 285 return; | 284 dist->GetIconIndex(), options | ShellUtil::SHORTCUT_PIN_TO_TASKBAR)) { |
|
robertshield
2012/08/22 21:39:07
one arg per line please
| |
| 286 } | 285 LOG(WARNING) << operation << " Start Menu shortcut (or pinning it) failed."; |
| 287 | |
| 288 start_menu_folder_path = start_menu_folder_path.Append(product_name); | |
| 289 | |
| 290 // Create/update Chrome link (points to chrome.exe) & Uninstall Chrome link | |
| 291 // (which points to setup.exe) under |start_menu_folder_path|. | |
| 292 | |
| 293 // Chrome link (launches Chrome) | |
| 294 FilePath chrome_link(start_menu_folder_path.Append(product_name + L".lnk")); | |
| 295 | |
| 296 if (create_always && !file_util::PathExists(start_menu_folder_path)) | |
| 297 file_util::CreateDirectoryW(start_menu_folder_path); | |
| 298 | |
| 299 VLOG(1) << operation << " shortcut to " << chrome_exe.value() << " at " | |
| 300 << chrome_link.value(); | |
| 301 if (!ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), | |
| 302 chrome_link.value(), string16(), product_desc, chrome_exe.value(), | |
| 303 browser_dist->GetIconIndex(), options)) { | |
| 304 LOG(WARNING) << operation << " shortcut at " << chrome_link.value() | |
| 305 << " failed."; | |
| 306 } else if (create_always && | |
| 307 base::win::GetVersion() >= base::win::VERSION_WIN7) { | |
| 308 // If the Start Menu shortcut was successfully created and |create_always|, | |
| 309 // proceed to pin the Start Menu shortcut to the taskbar on Win7+. | |
| 310 VLOG(1) << "Pinning new shortcut at " << chrome_link.value() | |
| 311 << " to taskbar"; | |
| 312 if (!file_util::TaskbarPinShortcutLink(chrome_link.value().c_str())) { | |
| 313 LOG(ERROR) << "Failed to pin shortcut to taskbar: " | |
| 314 << chrome_link.value(); | |
| 315 } | |
| 316 } | 286 } |
| 317 | 287 |
| 318 // Create/update uninstall link if we are not an MSI install. MSI | 288 // Create/update uninstall link if we are not an MSI install. MSI |
| 319 // installations are, for the time being, managed only through the | 289 // installations are, for the time being, managed only through the |
| 320 // Add/Remove Programs dialog. | 290 // Add/Remove Programs dialog. |
| 321 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here. | 291 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here. |
| 322 if (!installer_state.is_msi()) { | 292 if (!installer_state.is_msi()) { |
| 323 // Uninstall Chrome link | 293 // Uninstall Chrome link |
| 324 FilePath uninstall_link(start_menu_folder_path.Append( | |
| 325 browser_dist->GetUninstallLinkName() + L".lnk")); | |
| 326 | |
| 327 CommandLine arguments(CommandLine::NO_PROGRAM); | 294 CommandLine arguments(CommandLine::NO_PROGRAM); |
| 328 AppendUninstallCommandLineFlags(installer_state, product, &arguments); | 295 AppendUninstallCommandLineFlags(installer_state, product, &arguments); |
| 329 VLOG(1) << operation << " uninstall link at " << uninstall_link.value(); | 296 VLOG(1) << operation << " uninstall link to " << setup_exe.value() |
| 330 if (!file_util::CreateOrUpdateShortcutLink(setup_exe.value().c_str(), | 297 << arguments.GetCommandLineString(); |
| 331 uninstall_link.value().c_str(), NULL, | 298 if (!ShellUtil::CreateOrUpdateChromeShortcut( |
|
robertshield
2012/08/22 21:39:07
one arg per line please
| |
| 332 arguments.GetCommandLineString().c_str(), NULL, | 299 ShellUtil::SHORTCUT_START_MENU_UNINSTALL, dist, |
| 333 setup_exe.value().c_str(), 0, NULL, | 300 setup_exe.value().c_str(), string16(), string16(), |
| 334 create_always ? file_util::SHORTCUT_CREATE_ALWAYS : | 301 arguments.GetCommandLineString().c_str(), setup_exe.value().c_str(), |
| 335 file_util::SHORTCUT_NO_OPTIONS)) { | 302 0, options)) { |
| 336 LOG(WARNING) << operation << " uninstall link at " | 303 LOG(WARNING) << operation << " uninstall link failed."; |
| 337 << uninstall_link.value() << " failed."; | |
| 338 } | 304 } |
| 339 } | 305 } |
| 340 } | 306 } |
| 341 | 307 |
| 342 void CreateOrUpdateDesktopAndQuickLaunchShortcuts( | 308 void CreateOrUpdateDesktopAndQuickLaunchShortcuts( |
| 343 const InstallerState& installer_state, | 309 const InstallerState& installer_state, |
| 344 const Product& product, | 310 const Product& product, |
| 345 uint32 options) { | 311 uint32 options) { |
| 346 // TODO(tommi): Change this function to use WorkItemList. | 312 // TODO(tommi): Change this function to use WorkItemList. |
| 347 DCHECK(product.is_chrome()); | 313 DCHECK(product.is_chrome()); |
| 348 | 314 |
| 349 // Information used for all shortcut types | 315 // Information used for all shortcut types |
| 350 BrowserDistribution* browser_dist = product.distribution(); | 316 BrowserDistribution* dist = product.distribution(); |
| 351 const string16 product_name(browser_dist->GetAppShortCutName()); | 317 const string16 product_desc(dist->GetAppDescription()); |
| 352 const string16 product_desc(browser_dist->GetAppDescription()); | |
| 353 // Chrome link target | 318 // Chrome link target |
| 354 FilePath chrome_exe( | 319 FilePath chrome_exe( |
| 355 installer_state.target_path().Append(installer::kChromeExe)); | 320 installer_state.target_path().Append(installer::kChromeExe)); |
| 356 | 321 |
| 357 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); | 322 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); |
| 358 const char* operation = create_always ? "Creating" : "Updating"; | 323 const char* operation = create_always ? "Creating" : "Updating"; |
| 359 | 324 |
| 360 ShellUtil::ShellChange desktop_level = ShellUtil::CURRENT_USER; | |
| 361 int quick_launch_levels = ShellUtil::CURRENT_USER; | |
| 362 if (installer_state.system_install()) { | |
| 363 desktop_level = ShellUtil::SYSTEM_LEVEL; | |
| 364 quick_launch_levels |= ShellUtil::SYSTEM_LEVEL; | |
| 365 } | |
| 366 | |
| 367 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value(); | 325 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value(); |
| 368 if (!ShellUtil::CreateChromeDesktopShortcut( | 326 if (!ShellUtil::CreateOrUpdateChromeShortcut( |
| 369 browser_dist, chrome_exe.value(), product_desc, string16(), | 327 ShellUtil::SHORTCUT_DESKTOP, |
|
robertshield
2012/08/22 21:39:07
one arg per line please
| |
| 370 string16(), chrome_exe.value(), browser_dist->GetIconIndex(), | 328 dist, chrome_exe.value(), product_desc, string16(), |
| 371 desktop_level, options)) { | 329 string16(), chrome_exe.value(), dist->GetIconIndex(), options)) { |
| 372 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value() | 330 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value() |
| 373 << " failed."; | 331 << " failed."; |
| 374 } | 332 } |
| 375 | 333 |
| 376 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value(); | 334 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value(); |
| 377 if (!ShellUtil::CreateChromeQuickLaunchShortcut( | 335 if (!ShellUtil::CreateOrUpdateChromeShortcut( |
| 378 browser_dist, chrome_exe.value(), quick_launch_levels, options)) { | 336 ShellUtil::SHORTCUT_QUICK_LAUNCH, |
| 337 dist, chrome_exe.value(), product_desc, string16(), | |
| 338 string16(), chrome_exe.value(), dist->GetIconIndex(), options)) { | |
|
robertshield
2012/08/22 21:39:07
ditto
| |
| 379 LOG(WARNING) << operation << " quick launch shortcut for " | 339 LOG(WARNING) << operation << " quick launch shortcut for " |
| 380 << chrome_exe.value() << " failed."; | 340 << chrome_exe.value() << " failed."; |
| 381 } | 341 } |
| 342 | |
| 343 if (installer_state.system_install() && | |
| 344 (options & ShellUtil::SHORTCUT_CREATE_ALWAYS)) { | |
| 345 // On system-level installs, also create the user-level quick launch | |
| 346 // shortcut for the user running the install. | |
| 347 uint32 user_options = options & !ShellUtil::SHORTCUT_SYSTEM_LEVEL; | |
| 348 VLOG(1) << operation << " user-level quick launch shortcut for " | |
| 349 << chrome_exe.value(); | |
| 350 if (!ShellUtil::CreateOrUpdateChromeShortcut( | |
| 351 ShellUtil::SHORTCUT_QUICK_LAUNCH, | |
| 352 dist, chrome_exe.value(), product_desc, string16(), | |
| 353 string16(), chrome_exe.value(), dist->GetIconIndex(), | |
| 354 user_options)) { | |
| 355 LOG(WARNING) << operation << " user-level quick launch shortcut for " | |
| 356 << chrome_exe.value() << " failed."; | |
| 357 } | |
| 358 } | |
| 382 } | 359 } |
| 383 | 360 |
| 384 void RegisterChromeOnMachine(const InstallerState& installer_state, | 361 void RegisterChromeOnMachine(const InstallerState& installer_state, |
| 385 const Product& product, | 362 const Product& product, |
| 386 bool make_chrome_default) { | 363 bool make_chrome_default) { |
| 387 DCHECK(product.is_chrome()); | 364 DCHECK(product.is_chrome()); |
| 388 | 365 |
| 389 // Try to add Chrome to Media Player shim inclusion list. We don't do any | 366 // Try to add Chrome to Media Player shim inclusion list. We don't do any |
| 390 // error checking here because this operation will fail if user doesn't | 367 // error checking here because this operation will fail if user doesn't |
| 391 // have admin rights and we want to ignore the error. | 368 // have admin rights and we want to ignore the error. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 CreateOrUpdateDesktopAndQuickLaunchShortcuts( | 470 CreateOrUpdateDesktopAndQuickLaunchShortcuts( |
| 494 installer_state, *chrome_install, shortcut_options); | 471 installer_state, *chrome_install, shortcut_options); |
| 495 | 472 |
| 496 if (result == installer::FIRST_INSTALL_SUCCESS || | 473 if (result == installer::FIRST_INSTALL_SUCCESS || |
| 497 result == installer::INSTALL_REPAIRED) { | 474 result == installer::INSTALL_REPAIRED) { |
| 498 // On new installs and repaired installs, always create Start Menu | 475 // On new installs and repaired installs, always create Start Menu |
| 499 // and taskbar shortcuts (i.e. even if they were previously deleted by | 476 // and taskbar shortcuts (i.e. even if they were previously deleted by |
| 500 // the user). | 477 // the user). |
| 501 shortcut_options |= ShellUtil::SHORTCUT_CREATE_ALWAYS; | 478 shortcut_options |= ShellUtil::SHORTCUT_CREATE_ALWAYS; |
| 502 } | 479 } |
| 480 | |
| 481 if (installer_state.system_install()) | |
| 482 shortcut_options |= ShellUtil::SHORTCUT_SYSTEM_LEVEL; | |
| 483 | |
| 503 FilePath setup_exe(installer_state.GetInstallerDirectory(new_version) | 484 FilePath setup_exe(installer_state.GetInstallerDirectory(new_version) |
| 504 .Append(setup_path.BaseName())); | 485 .Append(setup_path.BaseName())); |
| 505 CreateOrUpdateStartMenuAndTaskbarShortcuts( | 486 CreateOrUpdateStartMenuAndTaskbarShortcuts( |
| 506 installer_state, setup_exe, *chrome_install, shortcut_options); | 487 installer_state, setup_exe, *chrome_install, shortcut_options); |
| 507 | 488 |
| 508 bool make_chrome_default = false; | 489 bool make_chrome_default = false; |
| 509 prefs.GetBool(master_preferences::kMakeChromeDefault, | 490 prefs.GetBool(master_preferences::kMakeChromeDefault, |
| 510 &make_chrome_default); | 491 &make_chrome_default); |
| 511 | 492 |
| 512 // If this is not the user's first Chrome install, but they have chosen | 493 // If this is not the user's first Chrome install, but they have chosen |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 installer_state.RemoveOldVersionDirectories( | 527 installer_state.RemoveOldVersionDirectories( |
| 547 new_version, | 528 new_version, |
| 548 existing_version.get(), | 529 existing_version.get(), |
| 549 install_temp_path); | 530 install_temp_path); |
| 550 } | 531 } |
| 551 | 532 |
| 552 return result; | 533 return result; |
| 553 } | 534 } |
| 554 | 535 |
| 555 } // namespace installer | 536 } // namespace installer |
| OLD | NEW |