Commit 53943c16 authored by fdoray's avatar fdoray Committed by Commit bot

Remove usage of SequencedWorkerPool::GetNamedSequenceToken from ChromeDownloadManagerDelegate.

SequencedWorkerPool is being deprecated in favor of TaskScheduler.

BUG=667892
TBR=hirono@chromium.org, kinuko@chromium.org,

Review-Url: https://codereview.chromium.org/2887933002
Cr-Commit-Position: refs/heads/master@{#473894}
parent 3abe1699
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <stddef.h> #include <stddef.h>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -104,10 +106,10 @@ void MoveDownloadedFile(const base::FilePath& downloaded_file, ...@@ -104,10 +106,10 @@ void MoveDownloadedFile(const base::FilePath& downloaded_file,
// Used to implement CheckForFileExistence(). // Used to implement CheckForFileExistence().
void ContinueCheckingForFileExistence( void ContinueCheckingForFileExistence(
const content::CheckForFileExistenceCallback& callback, content::CheckForFileExistenceCallback callback,
FileError error, FileError error,
std::unique_ptr<ResourceEntry> entry) { std::unique_ptr<ResourceEntry> entry) {
callback.Run(error == FILE_ERROR_OK); std::move(callback).Run(error == FILE_ERROR_OK);
} }
// Returns true if |download| is a Drive download created from data persisted // Returns true if |download| is a Drive download created from data persisted
...@@ -247,11 +249,11 @@ bool DownloadHandler::IsDriveDownload(const DownloadItem* download) { ...@@ -247,11 +249,11 @@ bool DownloadHandler::IsDriveDownload(const DownloadItem* download) {
void DownloadHandler::CheckForFileExistence( void DownloadHandler::CheckForFileExistence(
const DownloadItem* download, const DownloadItem* download,
const content::CheckForFileExistenceCallback& callback) { content::CheckForFileExistenceCallback callback) {
file_system_->GetResourceEntry( file_system_->GetResourceEntry(
util::ExtractDrivePath(GetTargetPath(download)), util::ExtractDrivePath(GetTargetPath(download)),
base::Bind(&ContinueCheckingForFileExistence, base::Bind(&ContinueCheckingForFileExistence,
callback)); base::Passed(std::move(callback))));
} }
void DownloadHandler::SetFreeDiskSpaceDelayForTesting( void DownloadHandler::SetFreeDiskSpaceDelayForTesting(
......
...@@ -71,9 +71,8 @@ class DownloadHandler : public AllDownloadItemNotifier::Observer { ...@@ -71,9 +71,8 @@ class DownloadHandler : public AllDownloadItemNotifier::Observer {
bool IsDriveDownload(const content::DownloadItem* download); bool IsDriveDownload(const content::DownloadItem* download);
// Checks a file corresponding to the download item exists in Drive. // Checks a file corresponding to the download item exists in Drive.
void CheckForFileExistence( void CheckForFileExistence(const content::DownloadItem* download,
const content::DownloadItem* download, content::CheckForFileExistenceCallback callback);
const content::CheckForFileExistenceCallback& callback);
// Calculates request space for |downloads|. // Calculates request space for |downloads|.
int64_t CalculateRequestSpace( int64_t CalculateRequestSpace(
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include <string> #include <string>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
...@@ -17,7 +18,6 @@ ...@@ -17,7 +18,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -212,8 +212,11 @@ ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) ...@@ -212,8 +212,11 @@ ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
: profile_(profile), : profile_(profile),
next_download_id_(content::DownloadItem::kInvalidId), next_download_id_(content::DownloadItem::kInvalidId),
download_prefs_(new DownloadPrefs(profile)), download_prefs_(new DownloadPrefs(profile)),
weak_ptr_factory_(this) { check_for_file_existence_task_runner_(
} base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})),
weak_ptr_factory_(this) {}
ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
// If a DownloadManager was set for this, Shutdown() must be called. // If a DownloadManager was set for this, Shutdown() must be called.
...@@ -533,29 +536,28 @@ void ChromeDownloadManagerDelegate::ShowDownloadInShell( ...@@ -533,29 +536,28 @@ void ChromeDownloadManagerDelegate::ShowDownloadInShell(
platform_util::ShowItemInFolder(profile_, platform_path); platform_util::ShowItemInFolder(profile_, platform_path);
} }
void ContinueCheckingForFileExistence(
content::CheckForFileExistenceCallback callback) {
std::move(callback).Run(false);
}
void ChromeDownloadManagerDelegate::CheckForFileExistence( void ChromeDownloadManagerDelegate::CheckForFileExistence(
DownloadItem* download, DownloadItem* download,
const content::CheckForFileExistenceCallback& callback) { content::CheckForFileExistenceCallback callback) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
drive::DownloadHandler* drive_download_handler = drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile_); drive::DownloadHandler::GetForProfile(profile_);
if (drive_download_handler && if (drive_download_handler &&
drive_download_handler->IsDriveDownload(download)) { drive_download_handler->IsDriveDownload(download)) {
drive_download_handler->CheckForFileExistence(download, callback); drive_download_handler->CheckForFileExistence(download,
std::move(callback));
return; return;
} }
#endif #endif
static const char kSequenceToken[] = "ChromeDMD-FileExistenceChecker";
base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool();
scoped_refptr<base::SequencedTaskRunner> task_runner =
worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
worker_pool->GetNamedSequenceToken(kSequenceToken),
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
task_runner.get(), check_for_file_existence_task_runner_.get(), FROM_HERE,
FROM_HERE, base::BindOnce(&base::PathExists, download->GetTargetFilePath()),
base::Bind(&base::PathExists, download->GetTargetFilePath()), std::move(callback));
callback);
} }
std::string std::string
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "chrome/browser/download/download_path_reservation_tracker.h" #include "chrome/browser/download/download_path_reservation_tracker.h"
#include "chrome/browser/download/download_target_determiner_delegate.h" #include "chrome/browser/download/download_target_determiner_delegate.h"
#include "chrome/browser/download/download_target_info.h" #include "chrome/browser/download/download_target_info.h"
...@@ -85,7 +86,7 @@ class ChromeDownloadManagerDelegate ...@@ -85,7 +86,7 @@ class ChromeDownloadManagerDelegate
void ShowDownloadInShell(content::DownloadItem* download) override; void ShowDownloadInShell(content::DownloadItem* download) override;
void CheckForFileExistence( void CheckForFileExistence(
content::DownloadItem* download, content::DownloadItem* download,
const content::CheckForFileExistenceCallback& callback) override; content::CheckForFileExistenceCallback callback) override;
std::string ApplicationClientIdForFileScanning() const override; std::string ApplicationClientIdForFileScanning() const override;
// Opens a download using the platform handler. DownloadItem::OpenDownload, // Opens a download using the platform handler. DownloadItem::OpenDownload,
...@@ -168,6 +169,12 @@ class ChromeDownloadManagerDelegate ...@@ -168,6 +169,12 @@ class ChromeDownloadManagerDelegate
IdCallbackVector id_callbacks_; IdCallbackVector id_callbacks_;
std::unique_ptr<DownloadPrefs> download_prefs_; std::unique_ptr<DownloadPrefs> download_prefs_;
// SequencedTaskRunner to check for file existence. A sequence is used so that
// a large download history doesn't cause a large number of concurrent disk
// operations.
const scoped_refptr<base::SequencedTaskRunner>
check_for_file_existence_task_runner_;
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
// Maps from pending extension installations to DownloadItem IDs. // Maps from pending extension installations to DownloadItem IDs.
typedef base::hash_map<extensions::CrxInstaller*, typedef base::hash_map<extensions::CrxInstaller*,
......
...@@ -64,7 +64,7 @@ using DownloadTargetCallback = ...@@ -64,7 +64,7 @@ using DownloadTargetCallback =
using DownloadOpenDelayedCallback = base::Callback<void(bool)>; using DownloadOpenDelayedCallback = base::Callback<void(bool)>;
// Called with the result of CheckForFileExistence(). // Called with the result of CheckForFileExistence().
using CheckForFileExistenceCallback = base::Callback<void(bool result)>; using CheckForFileExistenceCallback = base::OnceCallback<void(bool result)>;
using DownloadIdCallback = base::Callback<void(uint32_t)>; using DownloadIdCallback = base::Callback<void(uint32_t)>;
...@@ -152,9 +152,8 @@ class CONTENT_EXPORT DownloadManagerDelegate { ...@@ -152,9 +152,8 @@ class CONTENT_EXPORT DownloadManagerDelegate {
virtual void ShowDownloadInShell(DownloadItem* download) {} virtual void ShowDownloadInShell(DownloadItem* download) {}
// Checks whether a downloaded file still exists. // Checks whether a downloaded file still exists.
virtual void CheckForFileExistence( virtual void CheckForFileExistence(DownloadItem* download,
DownloadItem* download, CheckForFileExistenceCallback callback) {}
const CheckForFileExistenceCallback& callback) {}
// Return a GUID string used for identifying the application to the system AV // Return a GUID string used for identifying the application to the system AV
// function for scanning downloaded files. If no GUID is provided or if the // function for scanning downloaded files. If no GUID is provided or if the
......
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