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

Unified Diff: chrome/browser/ui/views/app_list/app_list_controller_win.cc

Issue 13940006: Remove --show-app-list-shortcut flag and implement new app launcher enable logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make start menu shortcut creation happen on enable Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/app_list/app_list_controller_win.cc
diff --git a/chrome/browser/ui/views/app_list/app_list_controller_win.cc b/chrome/browser/ui/views/app_list/app_list_controller_win.cc
index 91eb041e184110bcafb18c7ea379b33713e45f04..cfbf00cae92975fa342aafc7452626d3a67a7eec 100644
--- a/chrome/browser/ui/views/app_list/app_list_controller_win.cc
+++ b/chrome/browser/ui/views/app_list/app_list_controller_win.cc
@@ -4,7 +4,7 @@
#include <sstream>
-#include "apps/switches.h"
+#include "apps/pref_names.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
@@ -35,6 +35,7 @@
#include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h"
#include "chrome/browser/ui/extensions/application_launch.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_notification_types.h"
#include "chrome/common/chrome_switches.h"
@@ -125,6 +126,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 {
public:
AppListControllerDelegateWin();
@@ -834,78 +903,6 @@ void AppListController::FreeAnyKeepAliveForView() {
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) {
if (!g_browser_process || g_browser_process->IsShuttingDown())
return;
@@ -926,20 +923,20 @@ void AppListController::Init(Profile* 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()));
+ // Check if the start menu shortcut has been created before. It should only
koz (OOO until 15th September) 2013/04/19 01:39:35 I think all this new code needs to go.
calamity 2013/04/19 02:06:03 Done.
+ // be created once.
+ PrefService* local_state = g_browser_process->local_state();
+ bool start_menu_shortcut_created = local_state->GetBoolean(
+ apps::prefs::kAppLauncherStartMenuShortcutCreated);
+
+ if (!start_menu_shortcut_created) {
+ local_state->SetBoolean(apps::prefs::kAppLauncherStartMenuShortcutCreated,
+ true);
+
+ // This preserves the enable state of the app launcher across the migration.
+ local_state->SetBoolean(apps::prefs::kAppLauncherHasBeenEnabled,
+ local_state->GetBoolean(
+ apps::prefs::kAppLauncherIsEnabled));
}
// Instantiate AppListController so it listens for profile deletions.
@@ -963,12 +960,31 @@ bool AppListController::IsAppListVisible() const {
}
void AppListController::EnableAppList() {
- base::FilePath user_data_dir(
- g_browser_process->profile_manager()->user_data_dir());
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&CreateAppListTaskbarShortcutOnFileThread, user_data_dir,
- GetAppModelId()));
+ // Check if the app launcher shortcuts have ever been created before.
+ // Shortcuts should only be created once. If the user unpins the taskbar
+ // shortcut, they can restore it by pinning the start menu or desktop
+ // shortcut.
+ PrefService* local_state = g_browser_process->local_state();
+ 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

Powered by Google App Engine
This is Rietveld 408576698