Commit 6d28b0fe authored by Joey Scarr's avatar Joey Scarr Committed by Commit Bot

Convert DownloadItem::AcquireFileCallback to OnceCallback.

Bug: 1007685
Change-Id: If25ab8acb34bc501271d8a081a23aa0ea6e7211c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2060436
Commit-Queue: Joey Scarr <jsca@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742457}
parent 72dacdb5
......@@ -212,7 +212,10 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndDiscardDownload) {
EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(1000));
EXPECT_CALL(item,
StealDangerousDownload(true /*delete_file_after_feedback*/, _))
.WillOnce(SaveArg<1>(&download_discarded_callback));
.WillOnce([&download_discarded_callback](
bool _, download::DownloadItem::AcquireFileCallback arg) {
download_discarded_callback = std::move(arg);
});
DownloadFeedbackService service(nullptr, file_task_runner_.get());
service.MaybeStorePingsForDownload(DownloadCheckResult::UNCOMMON,
......@@ -223,7 +226,7 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndDiscardDownload) {
ASSERT_FALSE(download_discarded_callback.is_null());
EXPECT_EQ(0U, num_feedbacks());
download_discarded_callback.Run(file_path);
std::move(download_discarded_callback).Run(file_path);
ASSERT_EQ(1U, num_feedbacks());
ASSERT_TRUE(feedback(0));
EXPECT_TRUE(feedback(0)->start_called());
......@@ -251,7 +254,10 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndKeepDownload) {
EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(1000));
EXPECT_CALL(item,
StealDangerousDownload(false /*delete_file_after_feedback*/, _))
.WillOnce(SaveArg<1>(&download_discarded_callback));
.WillOnce([&download_discarded_callback](
bool _, download::DownloadItem::AcquireFileCallback arg) {
download_discarded_callback = std::move(arg);
});
EXPECT_CALL(item, ValidateDangerousDownload()).Times(1);
GURL empty_url;
EXPECT_CALL(item, GetURL()).WillOnce(ReturnRef(empty_url));
......@@ -265,7 +271,7 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndKeepDownload) {
ASSERT_FALSE(download_discarded_callback.is_null());
EXPECT_EQ(0U, num_feedbacks());
download_discarded_callback.Run(file_path);
std::move(download_discarded_callback).Run(file_path);
ASSERT_EQ(1U, num_feedbacks());
ASSERT_TRUE(feedback(0));
EXPECT_TRUE(feedback(0)->start_called());
......@@ -296,7 +302,10 @@ TEST_F(DownloadFeedbackServiceTest, MultiplePendingFeedbackComplete) {
Return(download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT));
EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000));
EXPECT_CALL(item[i], StealDangerousDownload(true, _))
.WillOnce(SaveArg<1>(&download_discarded_callback[i]));
.WillOnce([&download_discarded_callback, i](
bool _, download::DownloadItem::AcquireFileCallback arg) {
download_discarded_callback[i] = std::move(arg);
});
DownloadFeedbackService::MaybeStorePingsForDownload(
DownloadCheckResult::UNCOMMON, true /* upload_requested */, &item[i],
ping_request, ping_response);
......@@ -313,7 +322,7 @@ TEST_F(DownloadFeedbackServiceTest, MultiplePendingFeedbackComplete) {
EXPECT_EQ(0U, num_feedbacks());
for (size_t i = 0; i < kNumDownloads; ++i) {
download_discarded_callback[i].Run(file_path[i]);
std::move(download_discarded_callback[i]).Run(file_path[i]);
}
ASSERT_EQ(3U, num_feedbacks());
......@@ -365,7 +374,10 @@ TEST_F(DownloadFeedbackServiceTest, MultiFeedbackWithIncomplete) {
Return(download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT));
EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000));
EXPECT_CALL(item[i], StealDangerousDownload(true, _))
.WillOnce(SaveArg<1>(&download_discarded_callback[i]));
.WillOnce([&download_discarded_callback, i](
bool _, download::DownloadItem::AcquireFileCallback arg) {
download_discarded_callback[i] = std::move(arg);
});
DownloadFeedbackService::MaybeStorePingsForDownload(
DownloadCheckResult::UNCOMMON, true /* upload_requested */, &item[i],
ping_request, ping_response);
......@@ -381,12 +393,12 @@ TEST_F(DownloadFeedbackServiceTest, MultiFeedbackWithIncomplete) {
}
EXPECT_EQ(0U, num_feedbacks());
download_discarded_callback[0].Run(file_path[0]);
std::move(download_discarded_callback[0]).Run(file_path[0]);
ASSERT_EQ(1U, num_feedbacks());
ASSERT_TRUE(feedback(0));
EXPECT_TRUE(feedback(0)->start_called());
download_discarded_callback[1].Run(file_path[1]);
std::move(download_discarded_callback[1]).Run(file_path[1]);
ASSERT_EQ(2U, num_feedbacks());
ASSERT_TRUE(feedback(1));
EXPECT_FALSE(feedback(1)->start_called());
......@@ -404,7 +416,7 @@ TEST_F(DownloadFeedbackServiceTest, MultiFeedbackWithIncomplete) {
// Running a download acquired callback after the DownloadFeedbackService is
// destroyed should delete the file.
download_discarded_callback[2].Run(file_path[2]);
std::move(download_discarded_callback[2]).Run(file_path[2]);
EXPECT_EQ(2U, num_feedbacks());
// File should still exist since the file deletion task hasn't run yet.
......
......@@ -530,9 +530,8 @@ void DownloadItemImpl::ValidateMixedContentDownload() {
MaybeCompleteDownload();
}
void DownloadItemImpl::StealDangerousDownload(
bool delete_file_afterward,
const AcquireFileCallback& callback) {
void DownloadItemImpl::StealDangerousDownload(bool delete_file_afterward,
AcquireFileCallback callback) {
DVLOG(20) << __func__ << "() download = " << DebugString(true);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(IsDangerous());
......@@ -543,9 +542,9 @@ void DownloadItemImpl::StealDangerousDownload(
base::PostTaskAndReplyWithResult(
GetDownloadTaskRunner().get(), FROM_HERE,
base::BindOnce(&DownloadFileDetach, base::Passed(&download_file_)),
base::BindOnce(callback));
base::BindOnce(std::move(callback)));
} else {
callback.Run(GetFullPath());
std::move(callback).Run(GetFullPath());
}
destination_info_.current_path.clear();
Remove();
......@@ -554,9 +553,9 @@ void DownloadItemImpl::StealDangerousDownload(
base::PostTaskAndReplyWithResult(
GetDownloadTaskRunner().get(), FROM_HERE,
base::BindOnce(&MakeCopyOfDownloadFile, download_file_.get()),
base::BindOnce(callback));
base::BindOnce(std::move(callback)));
} else {
callback.Run(GetFullPath());
std::move(callback).Run(GetFullPath());
}
}
......
......@@ -118,7 +118,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData {
};
// Callback used with AcquireFileAndDeleteDownload().
typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback;
using AcquireFileCallback = base::OnceCallback<void(const base::FilePath&)>;
using RenameDownloadCallback = base::OnceCallback<void(DownloadRenameResult)>;
// Used to represent an invalid download ID.
static const uint32_t kInvalidId;
......@@ -186,7 +186,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData {
// Note: It is important for |callback| to be valid since the downloaded file
// will not be cleaned up if the callback fails.
virtual void StealDangerousDownload(bool delete_file_afterward,
const AcquireFileCallback& callback) = 0;
AcquireFileCallback callback) = 0;
// Pause a download. Will have no effect if the download is already
// paused.
......
......@@ -228,7 +228,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl
void ValidateDangerousDownload() override;
void ValidateMixedContentDownload() override;
void StealDangerousDownload(bool need_removal,
const AcquireFileCallback& callback) override;
AcquireFileCallback callback) override;
void Pause() override;
void Resume(bool user_resume) override;
void Cancel(bool user_cancel) override;
......
......@@ -45,7 +45,7 @@ class MockDownloadItem : public DownloadItem {
MOCK_METHOD0(UpdateObservers, void());
MOCK_METHOD0(ValidateDangerousDownload, void());
MOCK_METHOD0(ValidateMixedContentDownload, void());
MOCK_METHOD2(StealDangerousDownload, void(bool, const AcquireFileCallback&));
MOCK_METHOD2(StealDangerousDownload, void(bool, AcquireFileCallback));
MOCK_METHOD0(Pause, void());
MOCK_METHOD1(Resume, void(bool));
MOCK_METHOD1(Cancel, void(bool));
......
......@@ -43,7 +43,7 @@ class MockDownloadItemImpl : public DownloadItemImpl {
MOCK_METHOD0(OpenDownload, void());
MOCK_METHOD0(ShowDownloadInShell, void());
MOCK_METHOD0(ValidateDangerousDownload, void());
MOCK_METHOD2(StealDangerousDownload, void(bool, const AcquireFileCallback&));
MOCK_METHOD2(StealDangerousDownload, void(bool, AcquireFileCallback));
MOCK_METHOD3(UpdateProgress, void(int64_t, int64_t, const std::string&));
MOCK_METHOD1(Cancel, void(bool));
MOCK_METHOD0(MarkAsComplete, void());
......
......@@ -235,11 +235,10 @@ void FakeDownloadItem::ValidateMixedContentDownload() {
NOTREACHED();
}
void FakeDownloadItem::StealDangerousDownload(
bool delete_file_afterward,
const AcquireFileCallback& callback) {
void FakeDownloadItem::StealDangerousDownload(bool delete_file_afterward,
AcquireFileCallback callback) {
NOTREACHED();
callback.Run(base::FilePath());
std::move(callback).Run(base::FilePath());
}
void FakeDownloadItem::Pause() {
......
......@@ -118,7 +118,7 @@ class FakeDownloadItem : public download::DownloadItem {
void ValidateDangerousDownload() override;
void ValidateMixedContentDownload() override;
void StealDangerousDownload(bool delete_file_afterward,
const AcquireFileCallback& callback) override;
AcquireFileCallback callback) override;
void Rename(const base::FilePath& name,
RenameDownloadCallback callback) override;
void OnAsyncScanningCompleted(
......
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