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

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

Issue 11359013: Adding App Launcher shortcuts on install. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
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 <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <time.h> 9 #include <time.h>
10 #include <winuser.h> 10 #include <winuser.h>
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_path.h" 15 #include "base/file_path.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/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/win/shortcut.h" 23 #include "base/win/shortcut.h"
24 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
25 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/installer/setup/install_worker.h" 27 #include "chrome/installer/setup/install_worker.h"
27 #include "chrome/installer/setup/setup_constants.h" 28 #include "chrome/installer/setup/setup_constants.h"
28 #include "chrome/installer/util/auto_launch_util.h" 29 #include "chrome/installer/util/auto_launch_util.h"
29 #include "chrome/installer/util/browser_distribution.h" 30 #include "chrome/installer/util/browser_distribution.h"
30 #include "chrome/installer/util/create_reg_key_work_item.h" 31 #include "chrome/installer/util/create_reg_key_work_item.h"
31 #include "chrome/installer/util/delete_after_reboot_helper.h" 32 #include "chrome/installer/util/delete_after_reboot_helper.h"
32 #include "chrome/installer/util/google_update_constants.h" 33 #include "chrome/installer/util/google_update_constants.h"
33 #include "chrome/installer/util/helper.h" 34 #include "chrome/installer/util/helper.h"
34 #include "chrome/installer/util/install_util.h" 35 #include "chrome/installer/util/install_util.h"
35 #include "chrome/installer/util/master_preferences.h" 36 #include "chrome/installer/util/master_preferences.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 dist->GetUninstallLinkName() + installer::kLnkExt); 278 dist->GetUninstallLinkName() + installer::kLnkExt);
278 file_util::Delete(uninstall_shortcut_path, false); 279 file_util::Delete(uninstall_shortcut_path, false);
279 280
280 if (installer_state.system_install()) { 281 if (installer_state.system_install()) {
281 ShellUtil::RemoveChromeShortcut( 282 ShellUtil::RemoveChromeShortcut(
282 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist, chrome_exe.value(), 283 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist, chrome_exe.value(),
283 ShellUtil::SYSTEM_LEVEL, NULL); 284 ShellUtil::SYSTEM_LEVEL, NULL);
284 } 285 }
285 } 286 }
286 287
288 // Returns the appropriate shortcut operations for App Launcher,
289 // based on state of installation and master preference.
gab 2012/11/01 04:46:19 s/master preference/master_preferences
huangs 2012/11/01 19:20:38 Done. Also s/master preference/master_preferences
290 installer::InstallShortcutOperation GetAppLauncherShortcutOperation(
291 const InstallationState& original_state,
292 const InstallerState& installer_state) {
293 const installer::ProductState* original_app_host_state =
294 original_state.GetProductState(installer_state.system_install(),
295 BrowserDistribution::CHROME_APP_HOST);
296 bool app_launcher_exists = original_app_host_state &&
297 CommandLine(original_app_host_state->uninstall_command()).
gab 2012/11/01 04:46:19 nit: '.' on the next line to make it more obvious
huangs 2012/11/01 19:20:38 Done.
298 HasSwitch(installer::switches::kChromeAppLauncher);
gab 2012/11/01 04:46:19 I feel like checking the presence of a flag on the
huangs 2012/11/01 19:20:38 I followed grt@'s recommendation regarding using u
erikwright (departed) 2012/11/01 20:02:20 This is standard practice. The uninstall string is
gab 2012/11/02 04:19:58 Ok, sgtm.
299 if (!app_launcher_exists)
300 return installer::INSTALL_SHORTCUT_CREATE_ALL;
301
302 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING;
303 }
304
287 } // end namespace 305 } // end namespace
288 306
289 namespace installer { 307 namespace installer {
290 308
291 void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) { 309 void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) {
292 ReplaceChars(*att_value, L"&", L"&amp;", att_value); 310 ReplaceChars(*att_value, L"&", L"&amp;", att_value);
293 ReplaceChars(*att_value, L"'", L"&apos;", att_value); 311 ReplaceChars(*att_value, L"'", L"&apos;", att_value);
294 ReplaceChars(*att_value, L"<", L"&lt;", att_value); 312 ReplaceChars(*att_value, L"<", L"&lt;", att_value);
295 } 313 }
296 314
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return true; 367 return true;
350 } else { 368 } else {
351 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest 369 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
352 << " to " << src_path.value(); 370 << " to " << src_path.value();
353 return false; 371 return false;
354 } 372 }
355 } 373 }
356 } 374 }
357 375
358 void CreateOrUpdateShortcuts( 376 void CreateOrUpdateShortcuts(
359 const FilePath& chrome_exe, 377 const FilePath& target,
360 const Product& product, 378 const Product& product,
361 const MasterPreferences& prefs, 379 const MasterPreferences& prefs,
362 InstallShortcutLevel install_level, 380 InstallShortcutLevel install_level,
363 InstallShortcutOperation install_operation) { 381 InstallShortcutOperation install_operation) {
364 // TODO(tommi): Change this function to use WorkItemList. 382 // TODO(tommi): Change this function to use WorkItemList.
365 DCHECK(product.is_chrome()); 383 DCHECK(product.is_chrome() || product.is_chrome_app_host());
366 384
367 // Extract shortcut preferences from |prefs|. 385 // Extract shortcut preferences from |prefs|.
368 bool do_not_create_desktop_shortcut = false; 386 bool do_not_create_desktop_shortcut = false;
369 bool do_not_create_quick_launch_shortcut = false; 387 bool do_not_create_quick_launch_shortcut = false;
370 bool alternate_desktop_shortcut = false; 388 bool alternate_desktop_shortcut = false;
371 prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut, 389 prefs.GetBool(master_preferences::kDoNotCreateDesktopShortcut,
372 &do_not_create_desktop_shortcut); 390 &do_not_create_desktop_shortcut);
373 prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut, 391 prefs.GetBool(master_preferences::kDoNotCreateQuickLaunchShortcut,
374 &do_not_create_quick_launch_shortcut); 392 &do_not_create_quick_launch_shortcut);
375 prefs.GetBool(master_preferences::kAltShortcutText, 393 prefs.GetBool(master_preferences::kAltShortcutText,
376 &alternate_desktop_shortcut); 394 &alternate_desktop_shortcut);
377 395
378 BrowserDistribution* dist = product.distribution(); 396 BrowserDistribution* dist = product.distribution();
379 // Shortcuts are always installed per-user unless specified.
380 ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ?
381 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER);
382 397
383 // The default operation on update is to overwrite shortcuts with the 398 // The default operation on update is to overwrite shortcuts with the
384 // currently desired properties, but do so only for shortcuts that still 399 // currently desired properties, but do so only for shortcuts that still
385 // exist. 400 // exist.
386 ShellUtil::ChromeShortcutOperation shortcut_operation; 401 ShellUtil::ChromeShortcutOperation shortcut_operation;
387 switch (install_operation) { 402 switch (install_operation) {
388 case INSTALL_SHORTCUT_CREATE_ALL: 403 case INSTALL_SHORTCUT_CREATE_ALL:
389 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS; 404 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS;
390 break; 405 break;
391 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL: 406 case INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL:
392 shortcut_operation = ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; 407 shortcut_operation = ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL;
393 break; 408 break;
394 default: 409 default:
395 DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING); 410 DCHECK(install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING);
396 shortcut_operation = ShellUtil::SHORTCUT_REPLACE_EXISTING; 411 shortcut_operation = ShellUtil::SHORTCUT_REPLACE_EXISTING;
397 break; 412 break;
398 } 413 }
399 414
415 // Shortcuts are always installed per-user unless specified.
erikwright (departed) 2012/11/01 01:21:50 any reason for this moving from above?
huangs 2012/11/01 19:20:38 shortcut_level exists solely to initialize base_pr
gab 2012/11/02 04:19:58 Ah right, it used to be used for other stuff that
416 ShellUtil::ShellChange shortcut_level = (install_level == ALL_USERS ?
417 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER);
418
400 // |base_properties|: The basic properties to set on every shortcut installed 419 // |base_properties|: The basic properties to set on every shortcut installed
401 // (to be refined on a per-shortcut basis). 420 // (to be refined on a per-shortcut basis).
402 ShellUtil::ChromeShortcutProperties base_properties(shortcut_level); 421 ShellUtil::ChromeShortcutProperties base_properties(shortcut_level);
403 base_properties.set_chrome_exe(chrome_exe); 422 base_properties.set_chrome_exe(target);
gab 2012/11/01 04:46:19 The reason the ShellUtil::ChromeShortcutProperties
huangs 2012/11/01 19:20:38 I went through the flow, and found app_id is assig
erikwright (departed) 2012/11/01 20:02:20 We agreed F2F on the following: We will rename Sh
gab 2012/11/02 04:19:58 sgtm, though there are more methods than this that
423
424 if (product.is_chrome_app_host()) {
grt (UTC plus 2) 2012/11/01 01:50:04 consider if it makes sense to add to Product and P
huangs 2012/11/01 19:20:38 Eventually App Host and App Launcher will be the s
erikwright (departed) 2012/11/01 20:02:20 Based on the above response to gab@, I suppose we
erikwright (departed) 2012/11/01 20:43:36 What grt meant was all the stuff inside the if ()
gab 2012/11/02 04:19:58 sgtm
grt (UTC plus 2) 2012/11/02 19:55:30 sure
425 DCHECK(product.HasOption(kOptionAppHostIsLauncher));
426 // Should consult AppListController::GetAppListCommandLine().
erikwright (departed) 2012/11/01 01:21:50 Can you provide some context to this comment?
huangs 2012/11/01 19:20:38 In AppListController::GetAppListCommandLine(), a s
427 CommandLine app_host_args(CommandLine::NO_PROGRAM);
428 // This is cleaner than appending strings, but as a result we'll get
erikwright (departed) 2012/11/01 01:21:50 An extra space in the command line does not merit
huangs 2012/11/01 19:20:38 The extra space is really annoying. Can I add an
erikwright (departed) 2012/11/01 20:43:36 Does it require code changes somewhere? If not, wh
gab 2012/11/02 04:19:58 This is probably just a tiny bug in GetCommandLine
429 // 2 spaces: "app_host.exe --show-app-list".
430 app_host_args.AppendSwitch(::switches::kShowAppList);
huangs 2012/10/31 22:09:03 Note the insertion of 2 spaces!
431 base_properties.set_arguments(app_host_args.GetCommandLineString());
gab 2012/11/01 04:46:19 Things like this that are meant as a property for
huangs 2012/11/01 19:20:38 The command line to run the App Launcher is app_h
432 }
404 433
405 if (!do_not_create_desktop_shortcut || 434 if (!do_not_create_desktop_shortcut ||
406 shortcut_operation == ShellUtil::SHORTCUT_REPLACE_EXISTING) { 435 shortcut_operation == ShellUtil::SHORTCUT_REPLACE_EXISTING) {
407 ShellUtil::ChromeShortcutProperties desktop_properties(base_properties); 436 ShellUtil::ChromeShortcutProperties desktop_properties(base_properties);
408 if (alternate_desktop_shortcut) 437 if (alternate_desktop_shortcut)
409 desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName()); 438 desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName());
410 ExecuteAndLogShortcutOperation( 439 ExecuteAndLogShortcutOperation(
411 ShellUtil::SHORTCUT_DESKTOP, dist, desktop_properties, 440 ShellUtil::SHORTCUT_DESKTOP, dist, desktop_properties,
412 shortcut_operation); 441 shortcut_operation);
413 442
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 549
521 // Update the modifiers on the channel values for the product(s) being 550 // Update the modifiers on the channel values for the product(s) being
522 // installed and for the binaries in case of multi-install. 551 // installed and for the binaries in case of multi-install.
523 installer_state.UpdateChannels(); 552 installer_state.UpdateChannels();
524 553
525 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); 554 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE);
526 555
527 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) 556 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty())
528 CopyPreferenceFileForFirstRun(installer_state, prefs_path); 557 CopyPreferenceFileForFirstRun(installer_state, prefs_path);
529 558
530 // Currently this only creates shortcuts for Chrome, but for other products 559 // Creates shortcuts for App Launcher.
531 // we might want to create shortcuts. 560 const Product* app_launcher_product =
561 installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST);
562 if (app_launcher_product &&
563 app_launcher_product->HasOption(kOptionAppHostIsLauncher)) {
564 installer_state.UpdateStage(installer::CREATING_SHORTCUTS);
gab 2012/11/01 04:46:19 Should we introduce a new stage constant? I think
huangs 2012/11/01 19:20:38 Yeah, it's weird to have UpdateState((installer::C
erikwright (departed) 2012/11/01 20:02:20 Let's just set this on line 558. It will encompass
gab 2012/11/02 04:19:58 SGTM, although it might be cleaner if we split the
565
566 const FilePath app_host_exe(
567 installer_state.target_path().Append(kChromeAppHostExe));
568 InstallShortcutOperation app_launcher_shortcut_operation =
569 GetAppLauncherShortcutOperation(original_state, installer_state);
570
571 // Always install per-user shortcuts for App Launcher.
572 CreateOrUpdateShortcuts(app_host_exe, *app_launcher_product, prefs,
573 CURRENT_USER, app_launcher_shortcut_operation);
574 }
575
576 // Creates shortcuts for Chrome.
532 const Product* chrome_install = 577 const Product* chrome_install =
533 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); 578 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER);
534 if (chrome_install) { 579 if (chrome_install) {
535 installer_state.UpdateStage(installer::CREATING_SHORTCUTS); 580 installer_state.UpdateStage(installer::CREATING_SHORTCUTS);
536 581
537 BrowserDistribution* dist = chrome_install->distribution(); 582 BrowserDistribution* dist = chrome_install->distribution();
538 const FilePath chrome_exe( 583 const FilePath chrome_exe(
539 installer_state.target_path().Append(kChromeExe)); 584 installer_state.target_path().Append(kChromeExe));
540 CleanupLegacyShortcuts(installer_state, dist, chrome_exe); 585 CleanupLegacyShortcuts(installer_state, dist, chrome_exe);
541 586
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 693 INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
649 694
650 // Read master_preferences copied beside chrome.exe at install. 695 // Read master_preferences copied beside chrome.exe at install.
651 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 696 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
652 FilePath chrome_exe(installation_root.Append(kChromeExe)); 697 FilePath chrome_exe(installation_root.Append(kChromeExe));
653 CreateOrUpdateShortcuts( 698 CreateOrUpdateShortcuts(
654 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 699 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
655 } 700 }
656 701
657 } // namespace installer 702 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698