Commit 62b01f85 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Check for existence of taskbar pins dir in path provider.

This directory may not exist for a user. PathService's contract is that
it either returns an empty path or it returns the path to a dir that
exists, so it must enforce that.

BUG=1053446

Change-Id: I56a187039363f1b76306a3914e7dc73ad3c2737d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096681Reviewed-by: default avatarPatrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749181}
parent 4ad92fae
......@@ -9,9 +9,12 @@
#include "base/base_paths.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/win/current_module.h"
#include "base/win/scoped_co_mem.h"
#include "base/win/windows_version.h"
......@@ -172,12 +175,19 @@ bool PathProviderWin(int key, FilePath* result) {
.Append(FILE_PATH_LITERAL("Internet Explorer"))
.Append(FILE_PATH_LITERAL("Quick Launch"));
break;
case base::DIR_TASKBAR_PINS:
case base::DIR_TASKBAR_PINS: {
if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("User Pinned"))
.Append(FILE_PATH_LITERAL("TaskBar"));
// Allow a blocking call here to check for existence of the directory. In
// practice, all uses of SHGetFolderPath in this function make a similar
// check, so this does not add new I/O that wasn't already happening.
ScopedAllowBlocking allow_blocking(FROM_HERE);
if (!DirectoryExists(cur))
return false;
break;
}
case base::DIR_IMPLICIT_APP_SHORTCUTS:
if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur))
return false;
......
......@@ -303,12 +303,15 @@ class TaskTracker;
class AdjustOOMScoreHelper;
class FileDescriptorWatcher;
class FilePath;
class GetAppOutputScopedAllowBaseSyncPrimitives;
class ScopedAllowThreadRecallForStackSamplingProfiler;
class SimpleThread;
class StackSamplingProfiler;
class Thread;
bool PathProviderWin(int, FilePath*);
#if DCHECK_IS_ON()
#define INLINE_IF_DCHECK_IS_OFF BASE_EXPORT
#define EMPTY_BODY_IF_DCHECK_IS_OFF
......@@ -376,6 +379,8 @@ class BASE_EXPORT ScopedAllowBlocking {
friend class content::RenderProcessHostImpl;
friend class weblayer::WebLayerPathProvider;
friend bool PathProviderWin(int, FilePath*);
ScopedAllowBlocking(const Location& from_here = Location::Current());
~ScopedAllowBlocking();
......
......@@ -735,20 +735,6 @@ void MigrateTaskbarPins(base::OnceClosure completion_callback) {
// This needs to happen (e.g. so that the appid is fixed and the
// run-time Chrome icon is merged with the taskbar shortcut), but it is not an
// urgent task.
base::FilePath taskbar_path;
if (!base::PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_path)) {
NOTREACHED();
return;
}
// Migrate any pinned shortcuts in ImplicitApps sub-directories.
base::FilePath implicit_apps_path;
if (!base::PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS,
&implicit_apps_path)) {
NOTREACHED();
return;
}
// MigrateTaskbarPinsCallback just calls MigrateShortcutsInPathInternal
// several times with different parameters. Each call may or may not load
// DLL's. Since the callback may take the loader lock several times, and this
......@@ -761,10 +747,16 @@ void MigrateTaskbarPins(base::OnceClosure completion_callback) {
base::ThreadPool::CreateCOMSTATaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::ThreadPolicy::MUST_USE_FOREGROUND})
->PostTaskAndReply(FROM_HERE,
base::BindOnce(&MigrateTaskbarPinsCallback,
taskbar_path, implicit_apps_path),
std::move(completion_callback));
->PostTaskAndReply(
FROM_HERE, base::BindOnce([]() {
base::FilePath taskbar_path;
base::FilePath implicit_apps_path;
base::PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_path);
base::PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS,
&implicit_apps_path);
MigrateTaskbarPinsCallback(taskbar_path, implicit_apps_path);
}),
std::move(completion_callback));
}
void MigrateTaskbarPinsCallback(const base::FilePath& taskbar_path,
......@@ -775,8 +767,12 @@ void MigrateTaskbarPinsCallback(const base::FilePath& taskbar_path,
return;
base::FilePath chrome_proxy_path(web_app::GetChromeProxyPath());
MigrateChromeAndChromeProxyShortcuts(chrome_exe, chrome_proxy_path,
taskbar_path);
if (!taskbar_path.empty()) {
MigrateChromeAndChromeProxyShortcuts(chrome_exe, chrome_proxy_path,
taskbar_path);
}
if (implicit_apps_path.empty())
return;
base::FileEnumerator directory_enum(implicit_apps_path, /*recursive=*/false,
base::FileEnumerator::DIRECTORIES);
for (base::FilePath implicit_app_sub_directory = directory_enum.Next();
......
......@@ -1603,8 +1603,8 @@ bool ShellUtil::GetShortcutPath(ShortcutLocation location,
folder_to_append = InstallUtil::GetChromeAppsShortcutDirName();
break;
case SHORTCUT_LOCATION_TASKBAR_PINS:
dir_key = base::DIR_TASKBAR_PINS;
break;
// This directory isn't guaranteed to exist.
return base::PathService::Get(base::DIR_TASKBAR_PINS, path);
case SHORTCUT_LOCATION_APP_SHORTCUTS:
// TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win.
return GetAppShortcutsFolder(level, path);
......
......@@ -188,21 +188,24 @@ bool IsPinnedToTaskbarHelper::DirectoryContainsPinnedShortcutForProgram(
bool IsPinnedToTaskbarHelper::GetResult() {
base::FilePath current_exe;
base::PathService::Get(base::FILE_EXE, &current_exe);
if (!base::PathService::Get(base::FILE_EXE, &current_exe))
return false;
InstallUtil::ProgramCompare current_exe_compare(current_exe);
// Look into the "Quick Launch\User Pinned\TaskBar" folder.
base::FilePath taskbar_pins_dir;
base::PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_dir);
if (DirectoryContainsPinnedShortcutForProgram(taskbar_pins_dir,
if (base::PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_dir) &&
DirectoryContainsPinnedShortcutForProgram(taskbar_pins_dir,
current_exe_compare)) {
return true;
}
// Check all folders in ImplicitAppShortcuts.
base::FilePath implicit_app_shortcuts_dir;
base::PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS,
&implicit_app_shortcuts_dir);
if (!base::PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS,
&implicit_app_shortcuts_dir)) {
return false;
}
base::FileEnumerator directory_enum(implicit_app_shortcuts_dir, false,
base::FileEnumerator::DIRECTORIES);
for (base::FilePath directory = directory_enum.Next(); !directory.empty();
......
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