Commit d7a322e4 authored by calamity@chromium.org's avatar calamity@chromium.org

Remove --show-app-list-shortcut flag and implement new app launcher enable logic.

The app launcher now adds itself to the start menu on the first run of chrome
past this patch.

The webstore enable of the app launcher will create shortcuts on the desktop
and pin an icon to the taskbar.

The app launcher should never be disabled after it is enabled.

BUG=233434
TBR=benwells@chromium.org

Review URL: https://chromiumcodereview.appspot.com/13940006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195158 0039d316-1c4b-4281-b951-d872f2087c98
parent 1ce9bfec
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "apps/app_launcher.h" #include "apps/app_launcher.h"
#include "apps/pref_names.h" #include "apps/pref_names.h"
#include "apps/switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -35,40 +34,18 @@ AppLauncherState SynchronousAppLauncherChecks() { ...@@ -35,40 +34,18 @@ AppLauncherState SynchronousAppLauncherChecks() {
#elif !defined(OS_WIN) #elif !defined(OS_WIN)
return APP_LAUNCHER_DISABLED; return APP_LAUNCHER_DISABLED;
#else #else
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kShowAppListShortcut)) {
return APP_LAUNCHER_ENABLED;
}
#if defined(USE_ASH) #if defined(USE_ASH)
if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
return APP_LAUNCHER_ENABLED; return APP_LAUNCHER_ENABLED;
#endif #endif
if (!BrowserDistribution::GetDistribution()->AppHostIsSupported())
return APP_LAUNCHER_DISABLED;
return APP_LAUNCHER_UNKNOWN;
#endif
}
#if defined(OS_WIN)
void UpdatePrefAndCallCallbackOnUI(
bool result,
const OnAppLauncherEnabledCompleted& completion_callback) {
PrefService* prefs = g_browser_process->local_state(); PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result); // In some tests, the prefs aren't initialised.
completion_callback.Run(result); if (!prefs)
} return APP_LAUNCHER_UNKNOWN;
return prefs->GetBoolean(prefs::kAppLauncherHasBeenEnabled) ?
void IsAppLauncherInstalledOnBlockingPool( APP_LAUNCHER_ENABLED : APP_LAUNCHER_DISABLED;
const OnAppLauncherEnabledCompleted& completion_callback) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
bool result = chrome_launcher_support::IsAppLauncherPresent();
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
}
#endif #endif
}
} // namespace } // namespace
...@@ -83,31 +60,14 @@ void GetIsAppLauncherEnabled( ...@@ -83,31 +60,14 @@ void GetIsAppLauncherEnabled(
AppLauncherState state = SynchronousAppLauncherChecks(); AppLauncherState state = SynchronousAppLauncherChecks();
if (state != APP_LAUNCHER_UNKNOWN) { if (state != APP_LAUNCHER_UNKNOWN) {
bool is_enabled = state == APP_LAUNCHER_ENABLED; completion_callback.Run(state == APP_LAUNCHER_ENABLED);
PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled);
completion_callback.Run(is_enabled);
return; return;
} }
#if defined(OS_WIN)
content::BrowserThread::PostBlockingPoolTask(
FROM_HERE,
base::Bind(&IsAppLauncherInstalledOnBlockingPool,
completion_callback));
#else
// SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
// !defined(OS_WIN), so this path is never reached.
NOTREACHED(); NOTREACHED();
#endif
} }
bool WasAppLauncherEnabled() { bool WasAppLauncherEnabled() {
PrefService* prefs = g_browser_process->local_state(); return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
// In some tests, the prefs aren't initialised.
if (!prefs)
return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
} }
} // namespace apps } // namespace apps
...@@ -13,6 +13,11 @@ namespace apps { ...@@ -13,6 +13,11 @@ namespace apps {
// boolean flag is passed, which is true if the app launcher is enabled. // boolean flag is passed, which is true if the app launcher is enabled.
typedef base::Callback<void(bool)> OnAppLauncherEnabledCompleted; typedef base::Callback<void(bool)> OnAppLauncherEnabledCompleted;
// TODO(calamity): Remove all the "uncertain" apis because windows app launcher
// enabled is now just a single pref that we can check synchronously and with
// confidence. This includes changing GetIsAppLauncherEnabled to a synchronous
// API.
// A synchronous check to determine if the app launcher is enabled. If the // A synchronous check to determine if the app launcher is enabled. If the
// registry needs to be determined to find an accurate answer, this function // registry needs to be determined to find an accurate answer, this function
// will NOT do so; instead if will default to false (the app launcher is not // will NOT do so; instead if will default to false (the app launcher is not
......
...@@ -44,8 +44,6 @@ ...@@ -44,8 +44,6 @@
'shortcut_manager.h', 'shortcut_manager.h',
'shortcut_manager_factory.cc', 'shortcut_manager_factory.cc',
'shortcut_manager_factory.h', 'shortcut_manager_factory.h',
'switches.cc',
'switches.h',
], ],
'conditions': [ 'conditions': [
['enable_extensions==0', ['enable_extensions==0',
......
...@@ -8,10 +8,6 @@ namespace apps { ...@@ -8,10 +8,6 @@ namespace apps {
namespace prefs { namespace prefs {
// Local state caching knowledge of whether the app launcher is installed.
const char kAppLauncherIsEnabled[] =
"apps.app_launcher.should_show_apps_page";
// If set, the user requested to launch the app with this extension id while // If set, the user requested to launch the app with this extension id while
// in Metro mode, and then relaunched to Desktop mode to start it. // in Metro mode, and then relaunched to Desktop mode to start it.
const char kAppLaunchForMetroRestart[] = "apps.app_launch_for_metro_restart"; const char kAppLaunchForMetroRestart[] = "apps.app_launch_for_metro_restart";
...@@ -21,6 +17,16 @@ const char kAppLaunchForMetroRestart[] = "apps.app_launch_for_metro_restart"; ...@@ -21,6 +17,16 @@ const char kAppLaunchForMetroRestart[] = "apps.app_launch_for_metro_restart";
const char kAppLaunchForMetroRestartProfile[] = const char kAppLaunchForMetroRestartProfile[] =
"apps.app_launch_for_metro_restart_profile"; "apps.app_launch_for_metro_restart_profile";
// A boolean that tracks whether the user has ever enabled the app launcher.
const char kAppLauncherHasBeenEnabled[] =
"apps.app_launcher.has_been_enabled";
// TODO(calamity): remove this pref since app launcher will always be
// installed.
// Local state caching knowledge of whether the app launcher is installed.
const char kAppLauncherIsEnabled[] =
"apps.app_launcher.should_show_apps_page";
// A boolean identifying if we should show the app launcher promo or not. // A boolean identifying if we should show the app launcher promo or not.
const char kShowAppLauncherPromo[] = "app_launcher.show_promo"; const char kShowAppLauncherPromo[] = "app_launcher.show_promo";
......
...@@ -10,9 +10,10 @@ namespace prefs { ...@@ -10,9 +10,10 @@ namespace prefs {
// Alphabetical list of preference names specific to Apps component. // Alphabetical list of preference names specific to Apps component.
// Keep alphabetized and document each one in the source file. // Keep alphabetized and document each one in the source file.
extern const char kAppLauncherIsEnabled[];
extern const char kAppLaunchForMetroRestart[];
extern const char kAppLaunchForMetroRestartProfile[]; extern const char kAppLaunchForMetroRestartProfile[];
extern const char kAppLaunchForMetroRestart[];
extern const char kAppLauncherHasBeenEnabled[];
extern const char kAppLauncherIsEnabled[];
extern const char kShowAppLauncherPromo[]; extern const char kShowAppLauncherPromo[];
} // namespace prefs } // namespace prefs
......
...@@ -23,6 +23,7 @@ void RegisterPrefs(PrefRegistrySimple* registry) { ...@@ -23,6 +23,7 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
#if defined(OS_WIN) #if defined(OS_WIN)
registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, ""); registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, "");
registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, ""); registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, "");
registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false);
#endif #endif
// Identifies whether we should show the app launcher promo or not. // Identifies whether we should show the app launcher promo or not.
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "apps/switches.h"
namespace apps {
namespace switches {
// If true an app list shortcut will be shown in the taskbar.
const char kShowAppListShortcut[] = "show-app-list-shortcut";
} // namespace switches
} // namespace apps
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef APPS_SWITCHES_H_
#define APPS_SWITCHES_H_
namespace apps {
namespace switches {
// Alphabetical list of switches specific to Apps component.
// Keep alphabetized and document each one in the source file.
extern const char kShowAppListShortcut[];
} // namespace switches
} // namespace apps
#endif // APPS_SWITCHES_H_
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <set> #include <set>
#include <utility> #include <utility>
#include "apps/switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -1195,13 +1194,6 @@ const Experiment kExperiments[] = { ...@@ -1195,13 +1194,6 @@ const Experiment kExperiments[] = {
kOsDesktop, kOsDesktop,
SINGLE_VALUE_TYPE(switches::kDisableNativeAutofillUi) SINGLE_VALUE_TYPE(switches::kDisableNativeAutofillUi)
}, },
{
"show-app-list-shortcut",
IDS_FLAGS_SHOW_APP_LIST_SHORTCUT_NAME,
IDS_FLAGS_SHOW_APP_LIST_SHORTCUT_DESCRIPTION,
kOsWin,
SINGLE_VALUE_TYPE(apps::switches::kShowAppListShortcut)
},
{ {
"enable-experimental-form-filling", "enable-experimental-form-filling",
IDS_FLAGS_ENABLE_EXPERIMENTAL_FORM_FILLING_NAME, IDS_FLAGS_ENABLE_EXPERIMENTAL_FORM_FILLING_NAME,
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
#include "apps/app_launcher.h" #include "apps/app_launcher.h"
#include "apps/switches.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -127,18 +126,9 @@ WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; ...@@ -127,18 +126,9 @@ WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL;
void EnableAppLauncher(base::Callback<void(bool)> callback) { void EnableAppLauncher(base::Callback<void(bool)> callback) {
#if defined(OS_WIN) #if defined(OS_WIN)
if (BrowserDistribution::GetDistribution()->AppHostIsSupported()) { LOG(INFO) << "Enabling App Launcher via internal enable";
LOG(INFO) << "Enabling App Launcher via installation"; AppListService::Get()->EnableAppList();
extensions::AppHostInstaller::SetInstallWithLauncher(true); callback.Run(true);
extensions::AppHostInstaller::EnsureAppHostInstalled(callback);
} else {
LOG(INFO) << "Enabling App Launcher via flags";
about_flags::SetExperimentEnabled(g_browser_process->local_state(),
apps::switches::kShowAppListShortcut,
true);
AppListService::Get()->EnableAppList();
callback.Run(true);
}
#else #else
callback.Run(true); callback.Run(true);
#endif #endif
......
...@@ -111,6 +111,7 @@ class ShellIntegration { ...@@ -111,6 +111,7 @@ class ShellIntegration {
bool on_desktop; bool on_desktop;
bool in_applications_menu; bool in_applications_menu;
string16 applications_menu_subdir;
// For Windows, this refers to quick launch bar prior to Win7. In Win7, // For Windows, this refers to quick launch bar prior to Win7. In Win7,
// this means "pin to taskbar". For Mac/Linux, this could be used for // this means "pin to taskbar". For Mac/Linux, this could be used for
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <sstream> #include <sstream>
#include "apps/switches.h" #include "apps/pref_names.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h" #include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/views/browser_dialogs.h" #include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -130,6 +131,74 @@ void SetDidRunForNDayActiveStats() { ...@@ -130,6 +131,74 @@ void SetDidRunForNDayActiveStats() {
} }
} }
// The start menu shortcut is created on first run by users that are
// upgrading. The desktop and taskbar shortcuts are created the first time the
// user enables the app list. The taskbar shortcut is created in
// |user_data_dir| and will use a Windows Application Model Id of
// |app_model_id|. This runs on the FILE thread and not in the blocking IO
// thread pool as there are other tasks running (also on the FILE thread)
// which fiddle with shortcut icons
// (ShellIntegration::MigrateWin7ShortcutsOnPath). Having different threads
// fiddle with the same shortcuts could cause race issues.
void CreateAppListShortcuts(
const base::FilePath& user_data_dir,
const string16& app_model_id,
const ShellIntegration::ShortcutLocations& creation_locations) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
// Shortcut paths under which to create shortcuts.
std::vector<base::FilePath> shortcut_paths =
web_app::internals::GetShortcutPaths(creation_locations);
bool pin_to_taskbar = creation_locations.in_quick_launch_bar &&
(base::win::GetVersion() >= base::win::VERSION_WIN7);
// Create a shortcut in the |user_data_dir| for taskbar pinning.
if (pin_to_taskbar)
shortcut_paths.push_back(user_data_dir);
bool success = true;
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED();
return;
}
string16 wide_switches(GetAppListCommandLine().GetArgumentsString());
base::win::ShortcutProperties shortcut_properties;
shortcut_properties.set_target(chrome_exe);
shortcut_properties.set_working_dir(chrome_exe.DirName());
shortcut_properties.set_arguments(wide_switches);
shortcut_properties.set_description(
l10n_util::GetStringUTF16(IDS_APP_LIST_SHORTCUT_NAME));
shortcut_properties.set_icon(chrome_exe, kAppListIconIndex);
shortcut_properties.set_app_id(app_model_id);
const string16 file_name =
l10n_util::GetStringUTF16(IDS_APP_LIST_SHORTCUT_NAME);
for (size_t i = 0; i < shortcut_paths.size(); ++i) {
base::FilePath shortcut_file = shortcut_paths[i].Append(file_name).
AddExtension(installer::kLnkExt);
if (!file_util::PathExists(shortcut_file.DirName()) &&
!file_util::CreateDirectory(shortcut_file.DirName())) {
NOTREACHED();
return;
}
success = success && base::win::CreateOrUpdateShortcutLink(
shortcut_file, shortcut_properties,
base::win::SHORTCUT_CREATE_ALWAYS);
}
if (success && pin_to_taskbar) {
base::FilePath shortcut_to_pin = user_data_dir.Append(file_name).
AddExtension(installer::kLnkExt);
success = base::win::TaskbarPinShortcutLink(
shortcut_to_pin.value().c_str()) && success;
}
}
class AppListControllerDelegateWin : public AppListControllerDelegate { class AppListControllerDelegateWin : public AppListControllerDelegate {
public: public:
AppListControllerDelegateWin(); AppListControllerDelegateWin();
...@@ -839,78 +908,6 @@ void AppListController::FreeAnyKeepAliveForView() { ...@@ -839,78 +908,6 @@ void AppListController::FreeAnyKeepAliveForView() {
keep_alive_.reset(NULL); keep_alive_.reset(NULL);
} }
base::FilePath GetAppListTaskbarShortcutPath(
const base::FilePath& user_data_dir) {
const string16 shortcut_name = l10n_util::GetStringUTF16(
IDS_APP_LIST_SHORTCUT_NAME);
return user_data_dir.Append(shortcut_name).AddExtension(installer::kLnkExt);
}
void CreateAppListTaskbarShortcutOnFileThread(
const base::FilePath& user_data_dir,
const string16& app_model_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED();
return;
}
base::win::ShortcutProperties shortcut_properties;
shortcut_properties.set_target(chrome_exe);
shortcut_properties.set_working_dir(chrome_exe.DirName());
string16 wide_switches(GetAppListCommandLine().GetArgumentsString());
shortcut_properties.set_arguments(wide_switches);
shortcut_properties.set_description(l10n_util::GetStringUTF16(
IDS_APP_LIST_SHORTCUT_NAME));
shortcut_properties.set_icon(chrome_exe, kAppListIconIndex);
shortcut_properties.set_app_id(app_model_id);
const base::FilePath shortcut_path(
GetAppListTaskbarShortcutPath(user_data_dir));
base::win::CreateOrUpdateShortcutLink(shortcut_path, shortcut_properties,
base::win::SHORTCUT_CREATE_ALWAYS);
if (!base::win::TaskbarPinShortcutLink(shortcut_path.value().c_str()))
LOG(WARNING) << "Failed to pin AppList using " << shortcut_path.value();
}
// Check that a taskbar shortcut exists if it should, or does not exist if
// it should not. A taskbar shortcut should exist if the switch
// kShowAppListShortcut is set. The shortcut will be created or deleted in
// |user_data_dir| and will use a Windows Application Model Id of
// |app_model_id|.
// This runs on the FILE thread and not in the blocking IO thread pool as there
// are other tasks running (also on the FILE thread) which fiddle with shortcut
// icons (ShellIntegration::MigrateWin7ShortcutsOnPath). Having different
// threads fiddle with the same shortcuts could cause race issues.
void CheckAppListTaskbarShortcutOnFileThread(
const base::FilePath& user_data_dir,
const string16& app_model_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
const base::FilePath shortcut_path(
GetAppListTaskbarShortcutPath(user_data_dir));
const bool should_show =
CommandLine::ForCurrentProcess()->HasSwitch(
apps::switches::kShowAppListShortcut);
// This will not reshow a shortcut if it has been unpinned manually by the
// user, as that will not delete the shortcut file.
if (should_show && !file_util::PathExists(shortcut_path)) {
CreateAppListTaskbarShortcutOnFileThread(user_data_dir, app_model_id);
return;
}
if (!should_show && file_util::PathExists(shortcut_path)) {
base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str());
file_util::Delete(shortcut_path, false);
}
}
void InitView(Profile* profile) { void InitView(Profile* profile) {
if (!g_browser_process || g_browser_process->IsShuttingDown()) if (!g_browser_process || g_browser_process->IsShuttingDown())
return; return;
...@@ -931,22 +928,6 @@ void AppListController::Init(Profile* initial_profile) { ...@@ -931,22 +928,6 @@ void AppListController::Init(Profile* initial_profile) {
ShowAppListDuringModeSwitch(initial_profile); ShowAppListDuringModeSwitch(initial_profile);
} }
// Check that the app list shortcut matches the flag kShowAppListShortcut.
// This will either create or delete a shortcut file in the user data
// directory.
// TODO(benwells): Remove this and the flag once the app list installation
// is implemented.
static bool checked_shortcut = false;
if (!checked_shortcut) {
checked_shortcut = true;
base::FilePath user_data_dir(
g_browser_process->profile_manager()->user_data_dir());
content::BrowserThread::PostTask(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(&CheckAppListTaskbarShortcutOnFileThread, user_data_dir,
GetAppModelId()));
}
// Instantiate AppListController so it listens for profile deletions. // Instantiate AppListController so it listens for profile deletions.
AppListController::GetInstance(); AppListController::GetInstance();
...@@ -968,12 +949,31 @@ bool AppListController::IsAppListVisible() const { ...@@ -968,12 +949,31 @@ bool AppListController::IsAppListVisible() const {
} }
void AppListController::EnableAppList() { void AppListController::EnableAppList() {
base::FilePath user_data_dir( // Check if the app launcher shortcuts have ever been created before.
g_browser_process->profile_manager()->user_data_dir()); // Shortcuts should only be created once. If the user unpins the taskbar
content::BrowserThread::PostTask( // shortcut, they can restore it by pinning the start menu or desktop
content::BrowserThread::FILE, FROM_HERE, // shortcut.
base::Bind(&CreateAppListTaskbarShortcutOnFileThread, user_data_dir, PrefService* local_state = g_browser_process->local_state();
GetAppModelId())); bool has_been_enabled = local_state->GetBoolean(
apps::prefs::kAppLauncherHasBeenEnabled);
if (!has_been_enabled) {
local_state->SetBoolean(apps::prefs::kAppLauncherHasBeenEnabled,
true);
ShellIntegration::ShortcutLocations shortcut_locations;
shortcut_locations.on_desktop = true;
shortcut_locations.in_quick_launch_bar = true;
shortcut_locations.in_applications_menu = true;
shortcut_locations.applications_menu_subdir =
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
base::FilePath user_data_dir(
g_browser_process->profile_manager()->user_data_dir());
content::BrowserThread::PostTask(
content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&CreateAppListShortcuts,
user_data_dir, GetAppModelId(), shortcut_locations));
}
} }
} // namespace } // namespace
......
...@@ -96,6 +96,9 @@ namespace internals { ...@@ -96,6 +96,9 @@ namespace internals {
#if defined(OS_WIN) #if defined(OS_WIN)
bool CheckAndSaveIcon(const base::FilePath& icon_file, bool CheckAndSaveIcon(const base::FilePath& icon_file,
const gfx::ImageFamily& image); const gfx::ImageFamily& image);
std::vector<base::FilePath> GetShortcutPaths(
const ShellIntegration::ShortcutLocations& creation_locations);
#endif #endif
// Implemented for each platform, does the platform specific parts of creating // Implemented for each platform, does the platform specific parts of creating
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h" #include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/util_constants.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/gfx/icon_util.h" #include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -80,59 +81,6 @@ bool ShouldUpdateIcon(const base::FilePath& icon_file, const SkBitmap& image) { ...@@ -80,59 +81,6 @@ bool ShouldUpdateIcon(const base::FilePath& icon_file, const SkBitmap& image) {
sizeof(base::MD5Digest)) != 0; sizeof(base::MD5Digest)) != 0;
} }
std::vector<base::FilePath> GetShortcutPaths(
const ShellIntegration::ShortcutLocations& creation_locations) {
// Shortcut paths under which to create shortcuts.
std::vector<base::FilePath> shortcut_paths;
// Locations to add to shortcut_paths.
struct {
bool use_this_location;
int location_id;
const wchar_t* sub_dir;
} locations[] = {
{
creation_locations.on_desktop,
base::DIR_USER_DESKTOP,
NULL
}, {
creation_locations.in_applications_menu,
base::DIR_START_MENU,
NULL
}, {
creation_locations.in_quick_launch_bar,
// For Win7, create_in_quick_launch_bar means pinning to taskbar. Use
// base::PATH_START as a flag for this case.
(base::win::GetVersion() >= base::win::VERSION_WIN7) ?
base::PATH_START : base::DIR_APP_DATA,
(base::win::GetVersion() >= base::win::VERSION_WIN7) ?
NULL : L"Microsoft\\Internet Explorer\\Quick Launch"
}
};
// Populate shortcut_paths.
for (int i = 0; i < arraysize(locations); ++i) {
if (locations[i].use_this_location) {
base::FilePath path;
// Skip the Win7 case.
if (locations[i].location_id == base::PATH_START)
continue;
if (!PathService::Get(locations[i].location_id, &path)) {
continue;
}
if (locations[i].sub_dir != NULL)
path = path.Append(locations[i].sub_dir);
shortcut_paths.push_back(path);
}
}
return shortcut_paths;
}
bool ShortcutIsForProfile(const base::FilePath& shortcut_file_name, bool ShortcutIsForProfile(const base::FilePath& shortcut_file_name,
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
string16 cmd_line_string; string16 cmd_line_string;
...@@ -281,7 +229,7 @@ bool CreatePlatformShortcuts( ...@@ -281,7 +229,7 @@ bool CreatePlatformShortcuts(
bool success = true; bool success = true;
for (size_t i = 0; i < shortcut_paths.size(); ++i) { for (size_t i = 0; i < shortcut_paths.size(); ++i) {
base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). base::FilePath shortcut_file = shortcut_paths[i].Append(file_name).
AddExtension(FILE_PATH_LITERAL(".lnk")); AddExtension(installer::kLnkExt);
if (shortcut_paths[i] != web_app_path) { if (shortcut_paths[i] != web_app_path) {
int unique_number = int unique_number =
file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL(""));
...@@ -310,7 +258,7 @@ bool CreatePlatformShortcuts( ...@@ -310,7 +258,7 @@ bool CreatePlatformShortcuts(
// Use the web app path shortcut for pinning to avoid having unique numbers // Use the web app path shortcut for pinning to avoid having unique numbers
// in the application name. // in the application name.
base::FilePath shortcut_to_pin = web_app_path.Append(file_name). base::FilePath shortcut_to_pin = web_app_path.Append(file_name).
AddExtension(FILE_PATH_LITERAL(".lnk")); AddExtension(installer::kLnkExt);
success = base::win::TaskbarPinShortcutLink( success = base::win::TaskbarPinShortcutLink(
shortcut_to_pin.value().c_str()) && success; shortcut_to_pin.value().c_str()) && success;
} }
...@@ -364,6 +312,56 @@ void DeletePlatformShortcuts( ...@@ -364,6 +312,56 @@ void DeletePlatformShortcuts(
} }
} }
std::vector<base::FilePath> GetShortcutPaths(
const ShellIntegration::ShortcutLocations& creation_locations) {
// Shortcut paths under which to create shortcuts.
std::vector<base::FilePath> shortcut_paths;
// Locations to add to shortcut_paths.
struct {
bool use_this_location;
int location_id;
const wchar_t* subdir;
} locations[] = {
{
creation_locations.on_desktop,
base::DIR_USER_DESKTOP,
NULL
}, {
creation_locations.in_applications_menu,
base::DIR_START_MENU,
creation_locations.applications_menu_subdir.empty() ? NULL :
creation_locations.applications_menu_subdir.c_str()
}, {
creation_locations.in_quick_launch_bar,
// For Win7, in_quick_launch_bar means pinning to taskbar. Use
// base::PATH_START as a flag for this case.
(base::win::GetVersion() >= base::win::VERSION_WIN7) ?
base::PATH_START : base::DIR_APP_DATA,
(base::win::GetVersion() >= base::win::VERSION_WIN7) ?
NULL : L"Microsoft\\Internet Explorer\\Quick Launch"
}
};
// Populate shortcut_paths.
for (int i = 0; i < arraysize(locations); ++i) {
if (locations[i].use_this_location) {
base::FilePath path;
// Skip the Win7 case.
if (locations[i].location_id == base::PATH_START)
continue;
if (!PathService::Get(locations[i].location_id, &path)) {
continue;
}
if (locations[i].subdir != NULL)
path = path.Append(locations[i].subdir);
shortcut_paths.push_back(path);
}
}
return shortcut_paths;
}
} // namespace internals } // namespace internals
} // namespace web_app } // namespace web_app
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment