Commit 81790ebb authored by tby's avatar tby Committed by Commit Bot

[Files Ranking] Validate Drive files exist on-disk

There is a bug where a Drive file can be deleted via DriveFS, which
takes a few seconds to propagate back to the Drive QuickAccess results,
creating a window where we could surface a Drive file that can't be
launched.

We already deal with this for local files by checking they exist
on-disk before finalizing the results, so this CL does the same thing
for Drive files.

integration service right now.

Tested: manually, as we don't have a good way of mocking the drive
Bug: 1003588
Change-Id: I3ad839c18ad0dbb28fec13141e756993a4b65c74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1802775Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696691}
parent bc33a291
......@@ -7,7 +7,11 @@
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/ui/app_list/search/drive_quick_access_result.h"
......@@ -16,14 +20,31 @@ namespace {
constexpr int kMaxItems = 5;
// Given a vector of QuickAccessItems, return only those that exist on-disk.
std::vector<drive::QuickAccessItem> FilterResults(
const drive::DriveIntegrationService* drive_service,
const std::vector<drive::QuickAccessItem>& drive_results) {
std::vector<drive::QuickAccessItem> valid_results;
for (const auto& result : drive_results) {
if (base::PathExists(
drive_service->GetMountPointPath().Append(result.path))) {
valid_results.emplace_back(result);
}
}
return valid_results;
}
} // namespace
DriveQuickAccessProvider::DriveQuickAccessProvider(Profile* profile)
: profile_(profile),
drive_service_(
drive::DriveIntegrationServiceFactory::GetForProfile(profile)) {
DCHECK(profile_);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
task_runner_ = base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT, base::MayBlock(),
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
// Warm up the cache.
AppListShown();
......@@ -78,8 +99,18 @@ void DriveQuickAccessProvider::OnGetQuickAccessItems(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// An empty |drive_results| is likely caused by a failed call to ItemSuggest,
// so don't replace the cache.
if (!drive_results.empty())
results_cache_ = std::move(drive_results);
if (!drive_results.empty()) {
base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE,
base::BindOnce(&FilterResults, drive_service_, drive_results),
base::BindOnce(&DriveQuickAccessProvider::SetResultsCache,
weak_factory_.GetWeakPtr()));
}
}
void DriveQuickAccessProvider::SetResultsCache(
const std::vector<drive::QuickAccessItem>& drive_results) {
results_cache_ = std::move(drive_results);
}
} // namespace app_list
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
......@@ -34,6 +35,8 @@ class DriveQuickAccessProvider : public SearchProvider {
void GetQuickAccessItems();
void OnGetQuickAccessItems(drive::FileError error,
std::vector<drive::QuickAccessItem> drive_results);
void SetResultsCache(
const std::vector<drive::QuickAccessItem>& drive_results);
Profile* const profile_;
drive::DriveIntegrationService* const drive_service_;
......@@ -43,6 +46,7 @@ class DriveQuickAccessProvider : public SearchProvider {
SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<base::SequencedTaskRunner> task_runner_;
base::WeakPtrFactory<DriveQuickAccessProvider> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(DriveQuickAccessProvider);
......
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