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

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

Issue 10823437: Callback flow to register Chrome and update shortcuts after OS upgrade to Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactoring and nits. Created 8 years, 3 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
OLDNEW
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 << " to " << src_path.value(); 249 << " to " << src_path.value();
250 return true; 250 return true;
251 } else { 251 } else {
252 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest 252 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
253 << " to " << src_path.value(); 253 << " to " << src_path.value();
254 return false; 254 return false;
255 } 255 }
256 } 256 }
257 } 257 }
258 258
259 void CreateOrUpdateStartMenuAndTaskbarShortcuts( 259 bool 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 bool success = true;
264 // TODO(tommi): Change this function to use WorkItemList. 265 // TODO(tommi): Change this function to use WorkItemList.
265 DCHECK(product.is_chrome()); 266 DCHECK(product.is_chrome());
266 267
267 // Information used for all shortcut types 268 // Information used for all shortcut types
268 BrowserDistribution* browser_dist = product.distribution(); 269 BrowserDistribution* browser_dist = product.distribution();
269 const string16 product_name(browser_dist->GetAppShortCutName()); 270 const string16 product_name(browser_dist->GetAppShortCutName());
270 const string16 product_desc(browser_dist->GetAppDescription()); 271 const string16 product_desc(browser_dist->GetAppDescription());
271 // Chrome link target 272 // Chrome link target
272 FilePath chrome_exe( 273 FilePath chrome_exe(
273 installer_state.target_path().Append(installer::kChromeExe)); 274 installer_state.target_path().Append(installer::kChromeExe));
274 275
275 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); 276 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0);
276 const char* operation = create_always ? "Creating" : "Updating"; 277 const char* operation = create_always ? "Creating" : "Updating";
277 278
278 // Create Start Menu shortcuts. 279 // Create Start Menu shortcuts.
279 // The location of Start->Programs->Google Chrome folder 280 // The location of Start->Programs->Google Chrome folder
280 FilePath start_menu_folder_path; 281 FilePath start_menu_folder_path;
281 int dir_enum = installer_state.system_install() ? 282 int dir_enum = installer_state.system_install() ?
282 base::DIR_COMMON_START_MENU : base::DIR_START_MENU; 283 base::DIR_COMMON_START_MENU : base::DIR_START_MENU;
283 if (!PathService::Get(dir_enum, &start_menu_folder_path)) { 284 if (!PathService::Get(dir_enum, &start_menu_folder_path)) {
284 LOG(ERROR) << "Failed to get start menu path."; 285 LOG(ERROR) << "Failed to get start menu path.";
285 return; 286 return false;
286 } 287 }
287 288
288 start_menu_folder_path = start_menu_folder_path.Append(product_name); 289 start_menu_folder_path = start_menu_folder_path.Append(product_name);
289 290
290 // Create/update Chrome link (points to chrome.exe) & Uninstall Chrome link 291 // Create/update Chrome link (points to chrome.exe) & Uninstall Chrome link
291 // (which points to setup.exe) under |start_menu_folder_path|. 292 // (which points to setup.exe) under |start_menu_folder_path|.
292 293
293 // Chrome link (launches Chrome) 294 // Chrome link (launches Chrome)
294 FilePath chrome_link(start_menu_folder_path.Append(product_name + L".lnk")); 295 FilePath chrome_link(start_menu_folder_path.Append(product_name + L".lnk"));
295 296
296 if (create_always && !file_util::PathExists(start_menu_folder_path)) 297 if (create_always && !file_util::PathExists(start_menu_folder_path))
297 file_util::CreateDirectoryW(start_menu_folder_path); 298 file_util::CreateDirectoryW(start_menu_folder_path);
298 299
299 VLOG(1) << operation << " shortcut to " << chrome_exe.value() << " at " 300 VLOG(1) << operation << " shortcut to " << chrome_exe.value() << " at "
300 << chrome_link.value(); 301 << chrome_link.value();
301 if (!ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), 302 if (!ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(),
302 chrome_link.value(), string16(), product_desc, chrome_exe.value(), 303 chrome_link.value(), string16(), product_desc, chrome_exe.value(),
303 browser_dist->GetIconIndex(), options)) { 304 browser_dist->GetIconIndex(), options)) {
304 LOG(WARNING) << operation << " shortcut at " << chrome_link.value() 305 LOG(WARNING) << operation << " shortcut at " << chrome_link.value()
305 << " failed."; 306 << " failed.";
307 success = false;
grt (UTC plus 2) 2012/08/31 00:41:36 UpdateChromeShortcut will return false in certain
gab 2012/08/31 01:31:06 Ah yes indeed, UpdateChromeShortcut() currently fa
huangs 2012/08/31 20:50:17 Removing all these, per discussion.
306 } else if (create_always && 308 } else if (create_always &&
307 base::win::GetVersion() >= base::win::VERSION_WIN7) { 309 base::win::GetVersion() >= base::win::VERSION_WIN7) {
308 // If the Start Menu shortcut was successfully created and |create_always|, 310 // If the Start Menu shortcut was successfully created and |create_always|,
309 // proceed to pin the Start Menu shortcut to the taskbar on Win7+. 311 // proceed to pin the Start Menu shortcut to the taskbar on Win7+.
310 VLOG(1) << "Pinning new shortcut at " << chrome_link.value() 312 VLOG(1) << "Pinning new shortcut at " << chrome_link.value()
311 << " to taskbar"; 313 << " to taskbar";
312 if (!file_util::TaskbarPinShortcutLink(chrome_link.value().c_str())) { 314 if (!file_util::TaskbarPinShortcutLink(chrome_link.value().c_str())) {
313 LOG(ERROR) << "Failed to pin shortcut to taskbar: " 315 LOG(ERROR) << "Failed to pin shortcut to taskbar: "
314 << chrome_link.value(); 316 << chrome_link.value();
315 } 317 }
318 success = false;
316 } 319 }
317 320
318 // Create/update uninstall link if we are not an MSI install. MSI 321 // Create/update uninstall link if we are not an MSI install. MSI
319 // installations are, for the time being, managed only through the 322 // installations are, for the time being, managed only through the
320 // Add/Remove Programs dialog. 323 // Add/Remove Programs dialog.
321 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here. 324 // TODO(robertshield): We could add a shortcut to msiexec /X {GUID} here.
322 if (!installer_state.is_msi()) { 325 if (!installer_state.is_msi()) {
323 // Uninstall Chrome link 326 // Uninstall Chrome link
324 FilePath uninstall_link(start_menu_folder_path.Append( 327 FilePath uninstall_link(start_menu_folder_path.Append(
325 browser_dist->GetUninstallLinkName() + L".lnk")); 328 browser_dist->GetUninstallLinkName() + L".lnk"));
326 329
327 CommandLine arguments(CommandLine::NO_PROGRAM); 330 CommandLine arguments(CommandLine::NO_PROGRAM);
328 AppendUninstallCommandLineFlags(installer_state, product, &arguments); 331 AppendUninstallCommandLineFlags(installer_state, product, &arguments);
329 VLOG(1) << operation << " uninstall link at " << uninstall_link.value(); 332 VLOG(1) << operation << " uninstall link at " << uninstall_link.value();
330 if (!file_util::CreateOrUpdateShortcutLink(setup_exe.value().c_str(), 333 if (!file_util::CreateOrUpdateShortcutLink(setup_exe.value().c_str(),
331 uninstall_link.value().c_str(), NULL, 334 uninstall_link.value().c_str(), NULL,
332 arguments.GetCommandLineString().c_str(), NULL, 335 arguments.GetCommandLineString().c_str(), NULL,
333 setup_exe.value().c_str(), 0, NULL, 336 setup_exe.value().c_str(), 0, NULL,
334 create_always ? file_util::SHORTCUT_CREATE_ALWAYS : 337 create_always ? file_util::SHORTCUT_CREATE_ALWAYS :
335 file_util::SHORTCUT_NO_OPTIONS)) { 338 file_util::SHORTCUT_NO_OPTIONS)) {
336 LOG(WARNING) << operation << " uninstall link at " 339 LOG(WARNING) << operation << " uninstall link at "
337 << uninstall_link.value() << " failed."; 340 << uninstall_link.value() << " failed.";
341 success = false;
338 } 342 }
339 } 343 }
344 return success;
340 } 345 }
341 346
342 void CreateOrUpdateDesktopAndQuickLaunchShortcuts( 347 bool CreateOrUpdateDesktopAndQuickLaunchShortcuts(
343 const InstallerState& installer_state, 348 const InstallerState& installer_state,
344 const Product& product, 349 const Product& product,
345 uint32 options) { 350 uint32 options) {
351 bool success = true;
346 // TODO(tommi): Change this function to use WorkItemList. 352 // TODO(tommi): Change this function to use WorkItemList.
347 DCHECK(product.is_chrome()); 353 DCHECK(product.is_chrome());
348 354
349 // Information used for all shortcut types 355 // Information used for all shortcut types
350 BrowserDistribution* browser_dist = product.distribution(); 356 BrowserDistribution* browser_dist = product.distribution();
351 const string16 product_name(browser_dist->GetAppShortCutName()); 357 const string16 product_name(browser_dist->GetAppShortCutName());
352 const string16 product_desc(browser_dist->GetAppDescription()); 358 const string16 product_desc(browser_dist->GetAppDescription());
353 // Chrome link target 359 // Chrome link target
354 FilePath chrome_exe( 360 FilePath chrome_exe(
355 installer_state.target_path().Append(installer::kChromeExe)); 361 installer_state.target_path().Append(installer::kChromeExe));
356 362
357 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0); 363 bool create_always = ((options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0);
358 const char* operation = create_always ? "Creating" : "Updating"; 364 const char* operation = create_always ? "Creating" : "Updating";
359 365
360 ShellUtil::ShellChange desktop_level = ShellUtil::CURRENT_USER; 366 ShellUtil::ShellChange desktop_level = ShellUtil::CURRENT_USER;
361 int quick_launch_levels = ShellUtil::CURRENT_USER; 367 int quick_launch_levels = ShellUtil::CURRENT_USER;
362 if (installer_state.system_install()) { 368 if (installer_state.system_install()) {
363 desktop_level = ShellUtil::SYSTEM_LEVEL; 369 desktop_level = ShellUtil::SYSTEM_LEVEL;
364 quick_launch_levels |= ShellUtil::SYSTEM_LEVEL; 370 quick_launch_levels |= ShellUtil::SYSTEM_LEVEL;
365 } 371 }
366 372
367 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value(); 373 VLOG(1) << operation << " desktop shortcut for " << chrome_exe.value();
368 if (!ShellUtil::CreateChromeDesktopShortcut( 374 if (!ShellUtil::CreateChromeDesktopShortcut(
369 browser_dist, chrome_exe.value(), product_desc, string16(), 375 browser_dist, chrome_exe.value(), product_desc, string16(),
370 string16(), chrome_exe.value(), browser_dist->GetIconIndex(), 376 string16(), chrome_exe.value(), browser_dist->GetIconIndex(),
371 desktop_level, options)) { 377 desktop_level, options)) {
372 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value() 378 LOG(WARNING) << operation << " desktop shortcut for " << chrome_exe.value()
373 << " failed."; 379 << " failed.";
380 success = false;
374 } 381 }
375 382
376 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value(); 383 VLOG(1) << operation << " quick launch shortcut for " << chrome_exe.value();
377 if (!ShellUtil::CreateChromeQuickLaunchShortcut( 384 if (!ShellUtil::CreateChromeQuickLaunchShortcut(
378 browser_dist, chrome_exe.value(), quick_launch_levels, options)) { 385 browser_dist, chrome_exe.value(), quick_launch_levels, options)) {
379 LOG(WARNING) << operation << " quick launch shortcut for " 386 LOG(WARNING) << operation << " quick launch shortcut for "
380 << chrome_exe.value() << " failed."; 387 << chrome_exe.value() << " failed.";
388 success = false;
381 } 389 }
390 return success;
382 } 391 }
383 392
384 void RegisterChromeOnMachine(const InstallerState& installer_state, 393 bool RegisterChromeOnMachine(const InstallerState& installer_state,
385 const Product& product, 394 const Product& product,
386 bool make_chrome_default) { 395 bool make_chrome_default) {
387 DCHECK(product.is_chrome()); 396 DCHECK(product.is_chrome());
388 397
389 // Try to add Chrome to Media Player shim inclusion list. We don't do any 398 // 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 399 // error checking here because this operation will fail if user doesn't
391 // have admin rights and we want to ignore the error. 400 // have admin rights and we want to ignore the error.
392 AddChromeToMediaPlayerList(); 401 AddChromeToMediaPlayerList();
393 402
394 // Make Chrome the default browser if desired when possible. Otherwise, only 403 // Make Chrome the default browser if desired when possible. Otherwise, only
395 // register it with Windows. 404 // register it with Windows.
396 BrowserDistribution* dist = product.distribution(); 405 BrowserDistribution* dist = product.distribution();
397 const string16 chrome_exe( 406 const string16 chrome_exe(
398 installer_state.target_path().Append(installer::kChromeExe).value()); 407 installer_state.target_path().Append(installer::kChromeExe).value());
399 VLOG(1) << "Registering Chrome as browser: " << chrome_exe; 408 VLOG(1) << "Registering Chrome as browser: " << chrome_exe;
400 if (make_chrome_default) { 409 if (make_chrome_default) {
401 if (ShellUtil::CanMakeChromeDefaultUnattended()) { 410 if (ShellUtil::CanMakeChromeDefaultUnattended()) {
402 int level = ShellUtil::CURRENT_USER; 411 int level = ShellUtil::CURRENT_USER;
403 if (installer_state.system_install()) 412 if (installer_state.system_install())
404 level = level | ShellUtil::SYSTEM_LEVEL; 413 level = level | ShellUtil::SYSTEM_LEVEL;
405 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true); 414 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true);
406 } else if (IsInteractiveProcess()) { 415 } else if (IsInteractiveProcess()) {
407 ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe); 416 ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe);
408 } else { 417 } else {
409 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false); 418 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false);
410 } 419 }
411 } else { 420 } else {
412 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false); 421 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, string16(), false);
413 } 422 }
423 return true;
gab 2012/08/30 21:12:03 A bunch of things can fail above, simply returning
robertshield 2012/08/31 02:24:17 We never cared about failure here before. This cha
huangs 2012/08/31 20:50:17 Done.
414 } 424 }
415 425
416 InstallStatus InstallOrUpdateProduct( 426 InstallStatus InstallOrUpdateProduct(
417 const InstallationState& original_state, 427 const InstallationState& original_state,
418 const InstallerState& installer_state, 428 const InstallerState& installer_state,
419 const FilePath& setup_path, 429 const FilePath& setup_path,
420 const FilePath& archive_path, 430 const FilePath& archive_path,
421 const FilePath& install_temp_path, 431 const FilePath& install_temp_path,
422 const FilePath& prefs_path, 432 const FilePath& prefs_path,
423 const MasterPreferences& prefs, 433 const MasterPreferences& prefs,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 555
546 installer_state.RemoveOldVersionDirectories( 556 installer_state.RemoveOldVersionDirectories(
547 new_version, 557 new_version,
548 existing_version.get(), 558 existing_version.get(),
549 install_temp_path); 559 install_temp_path);
550 } 560 }
551 561
552 return result; 562 return result;
553 } 563 }
554 564
565 bool HandleOsUpgradeForBrowser(const InstallerState& installer_state,
566 const Product& chrome,
567 const FilePath& setup_exe) {
568 DCHECK(chrome.is_chrome());
569 bool success = true;
570 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
571 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
572 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
573 VLOG(1) << "Updating and registering shortcuts.";
574 uint32 shortcut_options = ShellUtil::SHORTCUT_DUAL_MODE;
575 success = CreateOrUpdateDesktopAndQuickLaunchShortcuts(
576 installer_state, chrome, shortcut_options) && success;
577 success = CreateOrUpdateStartMenuAndTaskbarShortcuts(
578 installer_state, setup_exe, chrome, shortcut_options) && success;
579 success = RegisterChromeOnMachine(installer_state, chrome, false)
580 && success;
gab 2012/08/30 20:51:07 nit: && should be on the line above and the 2nd co
huangs 2012/08/31 20:50:17 Okay, but removing this.
581 }
582 return success;
583 }
584
555 } // namespace installer 585 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698