Commit be3a1582 authored by Evan Stade's avatar Evan Stade Committed by Chromium LUCI CQ

Update remaining bind sites and callbacks in //c/b/downloads

Bug: 1152276
Change-Id: I44471424b6f6a106a029a87b54b30eca1e17229c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582818
Commit-Queue: David Trainor <dtrainor@chromium.org>
Auto-Submit: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836297}
parent 0a65fe33
......@@ -428,7 +428,7 @@ void DownloadController::StartContextMenuDownload(
int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
const content::WebContents::Getter& wc_getter(
base::Bind(&GetWebContents, process_id, routing_id));
base::BindRepeating(&GetWebContents, process_id, routing_id));
AcquireFileAccessPermission(
wc_getter, base::BindOnce(&CreateContextMenuDownloadInternal, wc_getter,
......
......@@ -522,8 +522,8 @@ void DownloadManagerService::ResumeDownloadInternal(
}
DownloadControllerBase::Get()->AboutToResumeDownload(item);
item->Resume(has_user_gesture);
if (!resume_callback_for_testing_.is_null())
resume_callback_for_testing_.Run(true);
if (resume_callback_for_testing_)
std::move(resume_callback_for_testing_).Run(true);
}
void DownloadManagerService::RetryDownloadInternal(
......@@ -665,8 +665,8 @@ void DownloadManagerService::OnResumptionFailedInternal(
Java_DownloadManagerService_onResumptionFailed(
env, java_ref_, ConvertUTF8ToJavaString(env, download_guid));
}
if (!resume_callback_for_testing_.is_null())
resume_callback_for_testing_.Run(false);
if (resume_callback_for_testing_)
std::move(resume_callback_for_testing_).Run(false);
}
download::DownloadItem* DownloadManagerService::GetDownload(
......
......@@ -239,9 +239,9 @@ class DownloadManagerService
// Called when all pending downloads are loaded.
void OnPendingDownloadsLoaded();
typedef base::Callback<void(bool)> ResumeCallback;
void set_resume_callback_for_testing(const ResumeCallback& resume_cb) {
resume_callback_for_testing_ = resume_cb;
using ResumeCallback = base::OnceCallback<void(bool)>;
void set_resume_callback_for_testing(ResumeCallback resume_cb) {
resume_callback_for_testing_ = std::move(resume_cb);
}
// Helper method to reset the SimpleDownloadManagerCoordinator if needed.
......
......@@ -30,7 +30,6 @@ class DownloadManagerServiceTest : public testing::Test {
DownloadManagerServiceTest()
: service_(new DownloadManagerService()),
coordinator_(base::NullCallback(), false),
finished_(false),
success_(false) {
ON_CALL(manager_, GetDownloadByGuid(_))
.WillByDefault(::testing::Invoke(
......@@ -40,13 +39,13 @@ class DownloadManagerServiceTest : public testing::Test {
}
void OnResumptionDone(bool success) {
finished_ = true;
success_ = success;
run_loop_.Quit();
}
void StartDownload(const std::string& download_guid) {
JNIEnv* env = base::android::AttachCurrentThread();
service_->set_resume_callback_for_testing(base::Bind(
service_->set_resume_callback_for_testing(base::BindOnce(
&DownloadManagerServiceTest::OnResumptionDone, base::Unretained(this)));
ProfileKeyAndroid profile_key_android(profile_.GetProfileKey());
......@@ -60,8 +59,7 @@ class DownloadManagerServiceTest : public testing::Test {
false);
EXPECT_FALSE(success_);
service_->OnDownloadsInitialized(&coordinator_, false);
while (!finished_)
base::RunLoop().RunUntilIdle();
run_loop_.Run();
}
void CreateDownloadItem(bool can_resume) {
......@@ -81,8 +79,8 @@ class DownloadManagerServiceTest : public testing::Test {
std::unique_ptr<download::MockDownloadItem> download_;
content::MockDownloadManager manager_;
TestingProfile profile_;
bool finished_;
bool success_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(DownloadManagerServiceTest);
};
......
......@@ -88,7 +88,7 @@ void InterceptOMADownloadNavigationThrottle::InterceptDownload() {
web_contents ? web_contents->GetRenderViewHost()->GetRoutingID() : 0;
DownloadControllerBase::Get()->CreateAndroidDownload(
base::Bind(&GetWebContents, process_id, routing_id),
base::BindRepeating(&GetWebContents, process_id, routing_id),
DownloadInfo(navigation_handle()->GetURL(), original_url,
content_disposition, mime_type, GetUserAgent(),
// TODO(qinmin): Get the cookie from cookie store.
......
......@@ -583,7 +583,7 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
DVLOG(2) << __func__ << "() Start SB download check for download = "
<< item->DebugString(false);
if (service->MaybeCheckClientDownload(
item, base::Bind(
item, base::BindRepeating(
&ChromeDownloadManagerDelegate::CheckClientDownloadDone,
weak_ptr_factory_.GetWeakPtr(), item->GetId()))) {
return false;
......
......@@ -396,7 +396,7 @@ base::FilePath ChromeDownloadManagerDelegateTest::GetPathInDownloadDir(
}
void StoreDownloadTargetInfo(
const base::Closure& closure,
const base::RepeatingClosure& quit_runloop,
DetermineDownloadTargetResult* result,
const base::FilePath& target_path,
DownloadItem::TargetDisposition target_disposition,
......@@ -412,7 +412,7 @@ void StoreDownloadTargetInfo(
result->intermediate_path = intermediate_path;
result->interrupt_reason = interrupt_reason;
result->download_schedule = std::move(download_schedule);
closure.Run();
quit_runloop.Run();
}
void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget(
......@@ -1658,8 +1658,8 @@ TEST_F(ChromeDownloadManagerDelegateTestWithSafeBrowsing,
CreateActiveDownloadItem(0);
EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(download_url));
EXPECT_CALL(*delegate(), GetDownloadProtectionService()).Times(0);
EXPECT_TRUE(
delegate()->ShouldCompleteDownload(download_item.get(), base::Closure()));
EXPECT_TRUE(delegate()->ShouldCompleteDownload(download_item.get(),
base::OnceClosure()));
}
#endif // OS_WIN
#endif // FULL_SAFE_BROWSING
......
......@@ -34,7 +34,7 @@ class DownloadDangerPrompt {
// The user dismissed the dialog without making an explicit choice.
DISMISS,
};
typedef base::Callback<void(Action)> OnDone;
typedef base::OnceCallback<void(Action)> OnDone;
// Return a new self-deleting DownloadDangerPrompt. The returned
// DownloadDangerPrompt* is only used for testing. The caller does not own the
......@@ -47,7 +47,7 @@ class DownloadDangerPrompt {
static DownloadDangerPrompt* Create(download::DownloadItem* item,
content::WebContents* web_contents,
bool show_context,
const OnDone& done);
OnDone done);
// Only to be used by tests. Subclasses must override to manually call the
// respective button click handler.
......
......@@ -156,11 +156,10 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
void CreatePrompt(bool from_download_api) {
prompt_ = DownloadDangerPrompt::Create(
&download_,
browser()->tab_strip_model()->GetActiveWebContents(),
&download_, browser()->tab_strip_model()->GetActiveWebContents(),
from_download_api,
base::Bind(&DownloadDangerPromptTest::PromptCallback,
base::Unretained(this)));
base::BindOnce(&DownloadDangerPromptTest::PromptCallback,
base::Unretained(this)));
content::RunAllPendingInMessageLoop();
}
......
......@@ -290,8 +290,6 @@ class DownloadHistoryTest : public testing::Test {
void CallOnDownloadCreatedInOrder() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Gmock doesn't appear to support something like InvokeWithTheseArgs. Maybe
// gmock needs to learn about base::Callback.
CallOnDownloadCreated(download_created_index_++);
}
......
......@@ -171,7 +171,7 @@ template <typename ValueType> DownloadQuery::FilterCallback BuildFilter(
// Returns true if |accessor.Run(item)| matches |pattern|.
bool FindRegex(
RE2* pattern,
const base::Callback<std::string(const DownloadItem&)>& accessor,
const base::RepeatingCallback<std::string(const DownloadItem&)>& accessor,
const DownloadItem& item) {
return RE2::PartialMatch(accessor.Run(item), *pattern);
}
......@@ -184,16 +184,17 @@ DownloadQuery::FilterCallback BuildRegexFilter(
if (!GetAs(regex_value, &regex_str)) return DownloadQuery::FilterCallback();
std::unique_ptr<RE2> pattern(new RE2(regex_str));
if (!pattern->ok()) return DownloadQuery::FilterCallback();
return base::Bind(&FindRegex, base::Owned(pattern.release()),
base::Bind(accessor));
return base::BindRepeating(&FindRegex, base::Owned(pattern.release()),
base::BindRepeating(accessor));
}
// Returns a ComparisonType to indicate whether a field in |left| is less than,
// greater than or equal to the same field in |right|.
template<typename ValueType>
template <typename ValueType>
ComparisonType Compare(
const base::Callback<ValueType(const DownloadItem&)>& accessor,
const DownloadItem& left, const DownloadItem& right) {
const base::RepeatingCallback<ValueType(const DownloadItem&)>& accessor,
const DownloadItem& left,
const DownloadItem& right) {
ValueType left_value = accessor.Run(left);
ValueType right_value = accessor.Run(right);
if (left_value > right_value) return GT;
......@@ -339,8 +340,8 @@ bool DownloadQuery::Matches(const DownloadItem& item) const {
// Sorters, but there is one DownloadComparator per call to Search().
struct DownloadQuery::Sorter {
typedef base::Callback<ComparisonType(
const DownloadItem&, const DownloadItem&)> SortType;
using SortType = base::RepeatingCallback<ComparisonType(const DownloadItem&,
const DownloadItem&)>;
template<typename ValueType>
static Sorter Build(DownloadQuery::SortDirection adirection,
......@@ -350,12 +351,9 @@ struct DownloadQuery::Sorter {
base::BindRepeating(accessor)));
}
Sorter(DownloadQuery::SortDirection adirection,
const SortType& asorter)
: direction(adirection),
sorter(asorter) {
}
~Sorter() {}
Sorter(DownloadQuery::SortDirection adirection, const SortType& asorter)
: direction(adirection), sorter(asorter) {}
~Sorter() = default;
DownloadQuery::SortDirection direction;
SortType sorter;
......
......@@ -35,7 +35,7 @@ class Value;
// bool FilterOutOddDownloads(const DownloadItem& item) {
// return 0 == (item.GetId() % 2);
// }
// CHECK(query.AddFilter(base::Bind(&FilterOutOddDownloads)));
// CHECK(query.AddFilter(base::BindRepeating(&FilterOutOddDownloads)));
// query.AddSorter(SORT_BYTES_RECEIVED, ASCENDING);
// query.AddSorter(SORT_URL, DESCENDING);
// query.Limit(20);
......@@ -47,7 +47,7 @@ class DownloadQuery {
// FilterCallback is a Callback that takes a DownloadItem and returns true if
// the item matches the filter and false otherwise.
// query.AddFilter(base::Bind(&YourFilterFunction));
// query.AddFilter(base::BindRepeating(&YourFilterFunction));
typedef base::RepeatingCallback<bool(const download::DownloadItem&)>
FilterCallback;
......@@ -151,7 +151,7 @@ class DownloadQuery {
bool FilterRegex(
const std::string& regex_str,
const base::Callback<std::string(const download::DownloadItem&)>&
const base::RepeatingCallback<std::string(const download::DownloadItem&)>&
accessor);
bool Matches(const download::DownloadItem& item) const;
void FinishSearch(DownloadVector* results) const;
......
......@@ -416,7 +416,7 @@ TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) {
TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) {
CreateMocks(2);
CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1)));
CHECK(query()->AddFilter(base::BindRepeating(&IdNotEqual, 1)));
ExpectStandardFilterResults();
}
......@@ -763,9 +763,9 @@ TEST_F(DownloadQueryTest, DownloadQueryFilterPerformance) {
static const int kNumFilters = 100;
CreateMocks(kNumItems);
for (size_t i = 0; i < (kNumFilters - 1); ++i) {
query()->AddFilter(base::Bind(&AlwaysReturn, true));
query()->AddFilter(base::BindRepeating(&AlwaysReturn, true));
}
query()->AddFilter(base::Bind(&AlwaysReturn, false));
query()->AddFilter(base::BindRepeating(&AlwaysReturn, false));
base::Time start = base::Time::Now();
Search();
base::Time end = base::Time::Now();
......
......@@ -335,8 +335,8 @@ DownloadTargetDeterminer::DoSetMixedContentStatus() {
delegate_->GetMixedContentStatus(
download_, virtual_path_,
base::Bind(&DownloadTargetDeterminer::GetMixedContentStatusDone,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&DownloadTargetDeterminer::GetMixedContentStatusDone,
weak_ptr_factory_.GetWeakPtr()));
return QUIT_DOLOOP;
}
......@@ -369,9 +369,10 @@ DownloadTargetDeterminer::Result
download_->GetState() != DownloadItem::IN_PROGRESS)
return CONTINUE;
delegate_->NotifyExtensions(download_, virtual_path_,
base::Bind(&DownloadTargetDeterminer::NotifyExtensionsDone,
weak_ptr_factory_.GetWeakPtr()));
delegate_->NotifyExtensions(
download_, virtual_path_,
base::BindOnce(&DownloadTargetDeterminer::NotifyExtensionsDone,
weak_ptr_factory_.GetWeakPtr()));
return QUIT_DOLOOP;
}
......@@ -572,10 +573,9 @@ DownloadTargetDeterminer::Result
next_state_ = STATE_DETERMINE_MIME_TYPE;
delegate_->DetermineLocalPath(
download_,
virtual_path_,
base::Bind(&DownloadTargetDeterminer::DetermineLocalPathDone,
weak_ptr_factory_.GetWeakPtr()));
download_, virtual_path_,
base::BindOnce(&DownloadTargetDeterminer::DetermineLocalPathDone,
weak_ptr_factory_.GetWeakPtr()));
return QUIT_DOLOOP;
}
......@@ -610,8 +610,8 @@ DownloadTargetDeterminer::Result
if (virtual_path_ == local_path_) {
delegate_->GetFileMimeType(
local_path_,
base::Bind(&DownloadTargetDeterminer::DetermineMimeTypeDone,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&DownloadTargetDeterminer::DetermineMimeTypeDone,
weak_ptr_factory_.GetWeakPtr()));
return QUIT_DOLOOP;
}
return CONTINUE;
......
......@@ -108,7 +108,7 @@ class NullWebContentsDelegate : public content::WebContentsDelegate {
// is bound as that parameter. Example:
// class FooClass {
// public:
// virtual void Foo(base::Callback<void(bool)> callback);
// virtual void Foo(base::OnceCallback<void(bool)> callback);
// };
// ...
// EXPECT_CALL(mock_fooclass_instance, Foo(callback))
......@@ -491,11 +491,11 @@ void DownloadTargetDeterminerTest::RunTestCase(
}
void CompletionCallbackWrapper(
const base::Closure& closure,
base::OnceClosure closure,
std::unique_ptr<DownloadTargetInfo>* target_info_receiver,
std::unique_ptr<DownloadTargetInfo> target_info) {
target_info_receiver->swap(target_info);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(closure));
}
std::unique_ptr<DownloadTargetInfo>
......@@ -2417,9 +2417,9 @@ TEST_F(DownloadTargetDeterminerTest, TransientDownloadResumption) {
#if BUILDFLAG(ENABLE_PLUGINS)
void DummyGetPluginsCallback(
const base::Closure& closure,
base::OnceClosure closure,
const std::vector<content::WebPluginInfo>& plugins) {
closure.Run();
std::move(closure).Run();
}
void ForceRefreshOfPlugins() {
......
......@@ -33,8 +33,8 @@ void DownloadTaskSchedulerImpl::ScheduleTask(
return;
scheduled_tasks_[task_type].Reset(
base::Bind(&DownloadTaskSchedulerImpl::RunScheduledTask,
weak_factory_.GetWeakPtr(), task_type));
base::BindOnce(&DownloadTaskSchedulerImpl::RunScheduledTask,
weak_factory_.GetWeakPtr(), task_type));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, scheduled_tasks_[task_type].callback(),
base::TimeDelta::FromSeconds(window_start_time_seconds));
......
......@@ -39,7 +39,7 @@ class DownloadTaskSchedulerImpl : public download::TaskScheduler {
SimpleFactoryKey* key_;
// Keeps track of scheduled tasks so that they can be cancelled.
std::map<download::DownloadTaskType, base::CancelableClosure>
std::map<download::DownloadTaskType, base::CancelableOnceClosure>
scheduled_tasks_;
base::WeakPtrFactory<DownloadTaskSchedulerImpl> weak_factory_{this};
......
......@@ -138,7 +138,7 @@ class DownloadPersistedObserver : public DownloadHistory::Observer {
void OnDownloadStored(DownloadItem* item,
const history::DownloadRow& info) override {
persisted_ = persisted_ || filter_.Run(item, info);
if (persisted_ && !quit_waiting_callback_.is_null())
if (persisted_ && quit_waiting_callback_)
std::move(quit_waiting_callback_).Run();
}
......@@ -174,7 +174,7 @@ class DownloadRemovedObserver : public DownloadPersistedObserver {
void OnDownloadsRemoved(const DownloadHistory::IdSet& ids) override {
removed_ = ids.find(download_id_) != ids.end();
if (removed_ && !quit_waiting_callback_.is_null())
if (removed_ && quit_waiting_callback_)
std::move(quit_waiting_callback_).Run();
}
......@@ -252,7 +252,6 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer {
base::RunLoop run_loop;
quit_waiting_callback_ = run_loop.QuitClosure();
run_loop.Run();
quit_waiting_callback_ = base::Closure();
}
*items_seen = items_seen_;
......@@ -266,18 +265,18 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer {
DCHECK_EQ(manager, manager_);
items_seen_.push_back(item);
if (!quit_waiting_callback_.is_null())
quit_waiting_callback_.Run();
if (quit_waiting_callback_)
std::move(quit_waiting_callback_).Run();
}
void ManagerGoingDown(DownloadManager* manager) override {
manager_->RemoveObserver(this);
manager_ = nullptr;
if (!quit_waiting_callback_.is_null())
quit_waiting_callback_.Run();
if (quit_waiting_callback_)
std::move(quit_waiting_callback_).Run();
}
base::Closure quit_waiting_callback_;
base::OnceClosure quit_waiting_callback_;
DownloadManager* manager_;
std::vector<DownloadItem*> items_seen_;
......
......@@ -1355,11 +1355,9 @@ void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) {
// DownloadDangerPrompt displays a modal dialog using native widgets that the
// user must either accept or cancel. It cannot be scripted.
DownloadDangerPrompt* prompt = DownloadDangerPrompt::Create(
download_item,
web_contents,
true,
base::Bind(&DownloadsAcceptDangerFunction::DangerPromptCallback,
this, download_id));
download_item, web_contents, true,
base::BindOnce(&DownloadsAcceptDangerFunction::DangerPromptCallback, this,
download_id));
// DownloadDangerPrompt deletes itself
if (on_prompt_created_ && !on_prompt_created_->is_null())
on_prompt_created_->Run(prompt);
......
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/compiler_specific.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/download/download_danger_prompt.h"
#include "base/compiler_specific.h"
#include "chrome/browser/download/download_stats.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
......@@ -45,7 +44,7 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
DownloadDangerPromptViews(download::DownloadItem* item,
Profile* profile,
bool show_context,
const OnDone& done);
OnDone done);
~DownloadDangerPromptViews() override;
// DownloadDangerPrompt:
......@@ -75,11 +74,11 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
download::DownloadItem* item,
Profile* profile,
bool show_context,
const OnDone& done)
OnDone done)
: download_(item),
profile_(profile),
show_context_(show_context),
done_(done) {
done_(std::move(done)) {
// Note that this prompt is asking whether to cancel a dangerous download, so
// the accept path is titled "Cancel".
SetButtonLabel(ui::DIALOG_BUTTON_OK, l10n_util::GetStringUTF16(IDS_CANCEL));
......@@ -263,8 +262,7 @@ base::string16 DownloadDangerPromptViews::GetMessageBody() const {
void DownloadDangerPromptViews::RunDone(Action action) {
// Invoking the callback can cause the download item state to change or cause
// the window to close, and |callback| refers to a member variable.
OnDone done = done_;
done_.Reset();
OnDone done = std::move(done_);
if (download_) {
// If this download is no longer dangerous, is already canceled or
// completed, don't send any report.
......@@ -284,8 +282,8 @@ void DownloadDangerPromptViews::RunDone(Action action) {
download_->RemoveObserver(this);
download_ = nullptr;
}
if (!done.is_null())
done.Run(action);
if (done)
std::move(done).Run(action);
}
} // namespace
......@@ -295,11 +293,12 @@ DownloadDangerPrompt* DownloadDangerPrompt::Create(
download::DownloadItem* item,
content::WebContents* web_contents,
bool show_context,
const OnDone& done) {
OnDone done) {
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
DownloadDangerPromptViews* download_danger_prompt =
new DownloadDangerPromptViews(item, profile, show_context, done);
new DownloadDangerPromptViews(item, profile, show_context,
std::move(done));
constrained_window::ShowWebModalDialogViews(download_danger_prompt,
web_contents);
return download_danger_prompt;
......
......@@ -399,8 +399,8 @@ void DownloadsDOMHandler::ShowDangerPrompt(
download::DownloadItem* dangerous_item) {
DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create(
dangerous_item, GetWebUIWebContents(), false,
base::Bind(&DownloadsDOMHandler::DangerPromptDone,
weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId()));
base::BindOnce(&DownloadsDOMHandler::DangerPromptDone,
weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId()));
// danger_prompt will delete itself.
DCHECK(danger_prompt);
}
......
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