Commit 8362598c authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

Convert base::Bind to Once/Repeating in //chrome/browser/offline_pages/

This CL converts base::Bind to Once/Repeating
in //chrome/browser/offline_pages/. After this CL, there should be no
base::Callback, base::Closure and base::Bind in this directory.

Bug: 1007635
Change-Id: I3e8eedc2b921e7dac46f155ae72be1b312887eae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2345285Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#800904}
parent 88e648f7
......@@ -243,8 +243,8 @@ void DuplicateCheckDone(const GURL& url,
bool duplicate_request_exists =
result == OfflinePageUtils::DuplicateCheckResult::DUPLICATE_REQUEST_FOUND;
OfflinePageInfoBarDelegate::Create(
base::Bind(&SavePageIfNotNavigatedAway, url, original_url, j_tab_ref,
origin),
base::BindOnce(&SavePageIfNotNavigatedAway, url, original_url, j_tab_ref,
origin),
url, duplicate_request_exists, web_contents);
}
......@@ -263,15 +263,16 @@ content::WebContents::Getter GetWebContentsGetter(
// The FrameTreeNode ID should be used to access the WebContents.
int frame_tree_node_id = web_contents->GetMainFrame()->GetFrameTreeNodeId();
if (frame_tree_node_id != -1) {
return base::Bind(content::WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
return base::BindRepeating(content::WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
}
// In other cases, use the RenderProcessHost ID + RenderFrameHost ID to get
// the WebContents.
return base::Bind(&GetWebContentsByFrameID,
web_contents->GetMainFrame()->GetProcess()->GetID(),
web_contents->GetMainFrame()->GetRoutingID());
return base::BindRepeating(
&GetWebContentsByFrameID,
web_contents->GetMainFrame()->GetProcess()->GetID(),
web_contents->GetMainFrame()->GetRoutingID());
}
void DownloadAsFile(content::WebContents* web_contents, const GURL& url) {
......@@ -328,7 +329,8 @@ void OnOfflinePageAcquireFileAccessPermissionDone(
chrome::GetBrowserContextRedirectedInIncognito(
web_contents->GetBrowserContext()),
url,
base::Bind(&DuplicateCheckDone, url, original_url, j_tab_ref, origin));
base::BindOnce(&DuplicateCheckDone, url, original_url, j_tab_ref,
origin));
}
void InitializeBackendOnProfileCreated(Profile* profile) {
......
......@@ -14,11 +14,10 @@
namespace offline_pages {
// static
void OfflinePageInfoBarDelegate::Create(
const base::Closure& confirm_continuation,
const GURL& page_to_download,
bool exists_duplicate_request,
content::WebContents* web_contents) {
void OfflinePageInfoBarDelegate::Create(base::OnceClosure confirm_continuation,
const GURL& page_to_download,
bool exists_duplicate_request,
content::WebContents* web_contents) {
// The URL could be very long, especially since we are including query
// parameters, path, etc. Elide the URL to a shorter length because the
// infobar cannot handle scrolling and completely obscures Chrome if the text
......@@ -40,18 +39,18 @@ void OfflinePageInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents)
->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar(
base::WrapUnique(new OfflinePageInfoBarDelegate(
confirm_continuation, base::UTF16ToUTF8(elided_url),
std::move(confirm_continuation), base::UTF16ToUTF8(elided_url),
page_to_download, exists_duplicate_request))));
}
OfflinePageInfoBarDelegate::~OfflinePageInfoBarDelegate() {}
OfflinePageInfoBarDelegate::OfflinePageInfoBarDelegate(
const base::Closure& confirm_continuation,
base::OnceClosure confirm_continuation,
const std::string& page_name,
const GURL& page_to_download,
bool duplicate_request_exists)
: confirm_continuation_(confirm_continuation),
: confirm_continuation_(std::move(confirm_continuation)),
page_name_(page_name),
page_to_download_(page_to_download),
duplicate_request_exists_(duplicate_request_exists) {}
......@@ -73,7 +72,7 @@ bool OfflinePageInfoBarDelegate::Cancel() {
}
bool OfflinePageInfoBarDelegate::Accept() {
confirm_continuation_.Run();
std::move(confirm_continuation_).Run();
return true;
}
......
......@@ -28,14 +28,14 @@ class OfflinePageInfoBarDelegate
// Creates an offline page infobar and a delegate and adds the infobar to the
// InfoBarService associated with |web_contents|. |page_name| is the name
// shown for this file in the infobar text.
static void Create(const base::Closure& confirm_continuation,
static void Create(base::OnceClosure confirm_continuation,
const GURL& page_to_download,
bool exists_duplicate_request,
content::WebContents* web_contents);
~OfflinePageInfoBarDelegate() override;
private:
OfflinePageInfoBarDelegate(const base::Closure& confirm_continuation,
OfflinePageInfoBarDelegate(base::OnceClosure confirm_continuation,
const std::string& page_name,
const GURL& page_to_download,
bool duplicate_request_exists);
......@@ -53,7 +53,7 @@ class OfflinePageInfoBarDelegate
OfflinePageInfoBarDelegate* AsOfflinePageInfoBarDelegate() override;
// Continuation called when the user chooses to create a new file.
base::Closure confirm_continuation_;
base::OnceClosure confirm_continuation_;
std::string page_name_;
GURL page_to_download_;
......
......@@ -41,7 +41,8 @@ void GetAllRequestsDone(
Profile* profile = ProfileManager::GetLastUsedProfile();
RequestCoordinator* coordinator =
RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
coordinator->StartImmediateProcessing(base::Bind(&ProcessingDoneCallback));
coordinator->StartImmediateProcessing(
base::BindRepeating(&ProcessingDoneCallback));
}
}
......@@ -57,7 +58,7 @@ void StartProcessing() {
Profile* profile = ProfileManager::GetLastUsedProfile();
RequestCoordinator* coordinator =
RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
coordinator->GetAllRequests(base::Bind(&GetAllRequestsDone));
coordinator->GetAllRequests(base::BindOnce(&GetAllRequestsDone));
}
} // namespace
......
......@@ -157,8 +157,9 @@ std::unique_ptr<KeyedService> GetTestingRequestCoordinator(
std::move(policy), std::move(offliner), std::move(queue),
std::move(scheduler), network_quality_tracker);
request_coordinator->SetInternalStartProcessingCallbackForTest(
base::Bind(&android::EvaluationTestScheduler::ImmediateScheduleCallback,
base::Unretained(scheduler.get())));
base::BindRepeating(
&android::EvaluationTestScheduler::ImmediateScheduleCallback,
base::Unretained(scheduler.get())));
return std::move(request_coordinator);
}
......@@ -311,7 +312,7 @@ void OfflinePageEvaluationBridge::GetAllPages(
ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj);
offline_page_model_->GetAllPages(
base::Bind(&GetAllPagesCallback, j_result_ref, j_callback_ref));
base::BindOnce(&GetAllPagesCallback, j_result_ref, j_callback_ref));
}
bool OfflinePageEvaluationBridge::PushRequestProcessing(
......@@ -350,7 +351,7 @@ void OfflinePageEvaluationBridge::GetRequestsInQueue(
const JavaParamRef<jobject>& j_callback_obj) {
ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj);
request_coordinator_->GetAllRequests(
base::Bind(&OnGetAllRequestsDone, j_callback_ref));
base::BindOnce(&OnGetAllRequestsDone, j_callback_ref));
}
void OfflinePageEvaluationBridge::RemoveRequestsFromQueue(
......@@ -362,7 +363,7 @@ void OfflinePageEvaluationBridge::RemoveRequestsFromQueue(
base::android::JavaLongArrayToInt64Vector(env, j_request_ids, &request_ids);
ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj);
request_coordinator_->RemoveRequests(
request_ids, base::Bind(&OnRemoveRequestsDone, j_callback_ref));
request_ids, base::BindOnce(&OnRemoveRequestsDone, j_callback_ref));
}
void OfflinePageEvaluationBridge::NotifyIfDoneLoading() const {
......
......@@ -35,12 +35,12 @@ bool OfflinePageUtils::CurrentlyShownInCustomTab(
// static
void OfflinePageUtils::ShowDuplicatePrompt(
const base::Closure& confirm_continuation,
base::OnceClosure confirm_continuation,
const GURL& url,
bool exists_duplicate_request,
content::WebContents* web_contents) {
OfflinePageInfoBarDelegate::Create(
confirm_continuation, url, exists_duplicate_request, web_contents);
OfflinePageInfoBarDelegate::Create(std::move(confirm_continuation), url,
exists_duplicate_request, web_contents);
}
// static
......
......@@ -30,10 +30,11 @@
namespace offline_pages {
namespace {
void DeleteFileOnFileThread(const base::FilePath& file_path,
const base::Closure& callback) {
base::OnceClosure callback) {
base::ThreadPool::PostTaskAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(base::GetDeleteFileCallback(), file_path), callback);
base::BindOnce(base::GetDeleteFileCallback(), file_path),
std::move(callback));
}
// Compute a SHA256 digest using a background thread. The computed digest will
......@@ -170,9 +171,9 @@ void OfflinePageMHTMLArchiver::OnComputeDigestDone(
void OfflinePageMHTMLArchiver::DeleteFileAndReportFailure(
const base::FilePath& file_path,
ArchiverResult result) {
DeleteFileOnFileThread(file_path,
base::Bind(&OfflinePageMHTMLArchiver::ReportFailure,
weak_ptr_factory_.GetWeakPtr(), result));
DeleteFileOnFileThread(
file_path, base::BindOnce(&OfflinePageMHTMLArchiver::ReportFailure,
weak_ptr_factory_.GetWeakPtr(), result));
}
void OfflinePageMHTMLArchiver::ReportFailure(ArchiverResult result) {
......
......@@ -171,7 +171,7 @@ class OfflinePageMHTMLArchiverTest : public testing::Test {
int64_t last_file_size_;
std::string last_digest_;
bool async_operation_completed_ = false;
base::Closure async_operation_completed_callback_;
base::OnceClosure async_operation_completed_callback_;
TestScopedOfflineClock clock_;
......@@ -222,7 +222,7 @@ void OfflinePageMHTMLArchiverTest::OnCreateArchiveDone(
last_file_size_ = file_size;
last_digest_ = digest;
if (!async_operation_completed_callback_.is_null())
async_operation_completed_callback_.Run();
std::move(async_operation_completed_callback_).Run();
}
void OfflinePageMHTMLArchiverTest::PumpLoop() {
......
......@@ -605,8 +605,9 @@ void OfflinePageRequestHandler::OnTrustedOfflinePageFound() {
} else {
file_path = GetCurrentOfflinePage().file_path;
}
OpenFile(file_path, base::Bind(&OfflinePageRequestHandler::DidOpenForServing,
weak_ptr_factory_.GetWeakPtr()));
OpenFile(file_path,
base::BindRepeating(&OfflinePageRequestHandler::DidOpenForServing,
weak_ptr_factory_.GetWeakPtr()));
}
void OfflinePageRequestHandler::VisitTrustedOfflinePage() {
......@@ -712,7 +713,7 @@ bool OfflinePageRequestHandler::IsProcessingFileOrContentUrlIntent() const {
void OfflinePageRequestHandler::OpenFile(
const base::FilePath& file_path,
const base::Callback<void(int)>& callback) {
const base::RepeatingCallback<void(int)>& callback) {
if (!stream_)
stream_ = std::make_unique<net::FileStream>(file_task_runner_);
......@@ -814,8 +815,8 @@ void OfflinePageRequestHandler::DidGetFileSizeForValidation(
// Open file to compute the digest.
OpenFile(GetCurrentOfflinePage().file_path,
base::Bind(&OfflinePageRequestHandler::DidOpenForValidation,
weak_ptr_factory_.GetWeakPtr()));
base::BindRepeating(&OfflinePageRequestHandler::DidOpenForValidation,
weak_ptr_factory_.GetWeakPtr()));
}
void OfflinePageRequestHandler::DidOpenForValidation(int result) {
......
......@@ -253,7 +253,7 @@ class OfflinePageRequestHandler {
void Redirect(const GURL& redirected_url);
void OpenFile(const base::FilePath& file_path,
const base::Callback<void(int)>& callback);
const base::RepeatingCallback<void(int)>& callback);
void UpdateDigestOnBackground(
scoped_refptr<net::IOBuffer> buffer,
size_t len,
......
......@@ -419,7 +419,7 @@ class OfflinePageRequestHandlerTest : public testing::Test {
// Runs on IO thread.
void CreateFileWithContentOnIO(const std::string& content,
const base::Closure& callback);
base::OnceClosure callback);
content::BrowserTaskEnvironment task_environment_;
TestingProfileManager profile_manager_;
......@@ -454,7 +454,7 @@ class OfflinePageRequestHandlerTest : public testing::Test {
int file_name_sequence_num_ = 0;
bool async_operation_completed_ = false;
base::Closure async_operation_completed_callback_;
base::OnceClosure async_operation_completed_callback_;
OfflinePageURLLoaderBuilder interceptor_factory_;
......@@ -572,7 +572,7 @@ void OfflinePageRequestHandlerTest::WaitForAsyncOperation() {
void OfflinePageRequestHandlerTest::CreateFileWithContentOnIO(
const std::string& content,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (!temp_dir_.IsValid()) {
......@@ -584,7 +584,7 @@ void OfflinePageRequestHandlerTest::CreateFileWithContentOnIO(
temp_file_path_ = temp_dir_.GetPath().AppendASCII(file_name);
ASSERT_NE(base::WriteFile(temp_file_path_, content.c_str(), content.length()),
-1);
callback.Run();
std::move(callback).Run();
}
base::FilePath OfflinePageRequestHandlerTest::CreateFileWithContent(
......@@ -888,7 +888,7 @@ void OfflinePageRequestHandlerTest::OnSavePageDone(SavePageResult result,
async_operation_completed_ = true;
if (!async_operation_completed_callback_.is_null())
async_operation_completed_callback_.Run();
std::move(async_operation_completed_callback_).Run();
}
OfflinePageItem OfflinePageRequestHandlerTest::GetPage(int64_t offline_id) {
......
......@@ -418,9 +418,10 @@ void OfflinePageTabHelper::ScheduleDownloadHelper(
const std::string& request_origin) {
OfflinePageUtils::CheckDuplicateDownloads(
web_contents->GetBrowserContext(), url,
base::Bind(&OfflinePageTabHelper::DuplicateCheckDoneForScheduleDownload,
weak_ptr_factory_.GetWeakPtr(), web_contents, name_space, url,
ui_action, request_origin));
base::BindOnce(
&OfflinePageTabHelper::DuplicateCheckDoneForScheduleDownload,
weak_ptr_factory_.GetWeakPtr(), web_contents, name_space, url,
ui_action, request_origin));
}
void OfflinePageTabHelper::DuplicateCheckDoneForScheduleDownload(
......@@ -435,9 +436,9 @@ void OfflinePageTabHelper::DuplicateCheckDoneForScheduleDownload(
static_cast<int>(
OfflinePageUtils::DownloadUIActionFlags::PROMPT_DUPLICATE)) {
OfflinePageUtils::ShowDuplicatePrompt(
base::Bind(&OfflinePageTabHelper::DoDownloadPageLater,
weak_ptr_factory_.GetWeakPtr(), web_contents, name_space,
url, ui_action, request_origin),
base::BindOnce(&OfflinePageTabHelper::DoDownloadPageLater,
weak_ptr_factory_.GetWeakPtr(), web_contents,
name_space, url, ui_action, request_origin),
url,
result ==
OfflinePageUtils::DuplicateCheckResult::DUPLICATE_REQUEST_FOUND,
......
......@@ -217,14 +217,14 @@ int OfflinePageURLLoader::GetPageTransition() const {
OfflinePageRequestHandler::Delegate::WebContentsGetter
OfflinePageURLLoader::GetWebContentsGetter() const {
return base::Bind(&GetWebContents, frame_tree_node_id_);
return base::BindRepeating(&GetWebContents, frame_tree_node_id_);
}
OfflinePageRequestHandler::Delegate::TabIdGetter
OfflinePageURLLoader::GetTabIdGetter() const {
if (!tab_id_getter_.is_null())
return tab_id_getter_;
return base::Bind(&GetTabId);
return base::BindRepeating(&GetTabId);
}
void OfflinePageURLLoader::ReadRawData() {
......
......@@ -66,7 +66,7 @@ bool IsSupportedByDownload(content::BrowserContext* browser_context,
void CheckDuplicateOngoingDownloads(
content::BrowserContext* browser_context,
const GURL& url,
const OfflinePageUtils::DuplicateCheckCallback& callback) {
OfflinePageUtils::DuplicateCheckCallback callback) {
RequestCoordinator* request_coordinator =
RequestCoordinatorFactory::GetForBrowserContext(browser_context);
if (!request_coordinator)
......@@ -74,7 +74,7 @@ void CheckDuplicateOngoingDownloads(
auto request_coordinator_continuation =
[](content::BrowserContext* browser_context, const GURL& url,
const OfflinePageUtils::DuplicateCheckCallback& callback,
OfflinePageUtils::DuplicateCheckCallback callback,
std::vector<std::unique_ptr<SavePageRequest>> requests) {
base::Time latest_request_time;
for (auto& request : requests) {
......@@ -87,7 +87,8 @@ void CheckDuplicateOngoingDownloads(
}
if (latest_request_time.is_null()) {
callback.Run(OfflinePageUtils::DuplicateCheckResult::NOT_FOUND);
std::move(callback).Run(
OfflinePageUtils::DuplicateCheckResult::NOT_FOUND);
} else {
// Using CUSTOM_COUNTS instead of time-oriented histogram to record
// samples in seconds rather than milliseconds.
......@@ -97,13 +98,14 @@ void CheckDuplicateOngoingDownloads(
base::TimeDelta::FromSeconds(1).InSeconds(),
base::TimeDelta::FromDays(7).InSeconds(), 50);
callback.Run(
std::move(callback).Run(
OfflinePageUtils::DuplicateCheckResult::DUPLICATE_REQUEST_FOUND);
}
};
request_coordinator->GetAllRequests(base::BindOnce(
request_coordinator_continuation, browser_context, url, callback));
request_coordinator->GetAllRequests(
base::BindOnce(request_coordinator_continuation, browser_context, url,
std::move(callback)));
}
void DoCalculateSizeBetween(
......@@ -133,15 +135,16 @@ content::WebContents::Getter GetWebContentsGetter(
// The FrameTreeNode ID should be used to access the WebContents.
int frame_tree_node_id = web_contents->GetMainFrame()->GetFrameTreeNodeId();
if (frame_tree_node_id != -1) {
return base::Bind(content::WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
return base::BindRepeating(content::WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
}
// In other cases, use the RenderProcessHost ID + RenderFrameHost ID to get
// the WebContents.
return base::Bind(&GetWebContentsByFrameID,
web_contents->GetMainFrame()->GetProcess()->GetID(),
web_contents->GetMainFrame()->GetRoutingID());
return base::BindRepeating(
&GetWebContentsByFrameID,
web_contents->GetMainFrame()->GetProcess()->GetID(),
web_contents->GetMainFrame()->GetRoutingID());
}
void AcquireFileAccessPermissionDoneForScheduleDownload(
......@@ -256,7 +259,7 @@ GURL OfflinePageUtils::GetOriginalURLFromWebContents(
void OfflinePageUtils::CheckDuplicateDownloads(
content::BrowserContext* browser_context,
const GURL& url,
const DuplicateCheckCallback& callback) {
DuplicateCheckCallback callback) {
// First check for finished downloads, that is, saved pages.
OfflinePageModel* offline_page_model =
OfflinePageModelFactory::GetForBrowserContext(browser_context);
......@@ -264,8 +267,7 @@ void OfflinePageUtils::CheckDuplicateDownloads(
return;
auto continuation = [](content::BrowserContext* browser_context,
const GURL& url,
const DuplicateCheckCallback& callback,
const GURL& url, DuplicateCheckCallback callback,
const std::vector<OfflinePageItem>& pages) {
base::Time latest_saved_time;
for (const auto& offline_page_item : pages) {
......@@ -277,7 +279,7 @@ void OfflinePageUtils::CheckDuplicateDownloads(
}
if (latest_saved_time.is_null()) {
// Then check for ongoing downloads, that is, requests.
CheckDuplicateOngoingDownloads(browser_context, url, callback);
CheckDuplicateOngoingDownloads(browser_context, url, std::move(callback));
} else {
// Using CUSTOM_COUNTS instead of time-oriented histogram to record
// samples in seconds rather than milliseconds.
......@@ -287,13 +289,14 @@ void OfflinePageUtils::CheckDuplicateDownloads(
base::TimeDelta::FromSeconds(1).InSeconds(),
base::TimeDelta::FromDays(7).InSeconds(), 50);
callback.Run(DuplicateCheckResult::DUPLICATE_PAGE_FOUND);
std::move(callback).Run(DuplicateCheckResult::DUPLICATE_PAGE_FOUND);
}
};
PageCriteria criteria;
criteria.url = url;
offline_page_model->GetPagesWithCriteria(
criteria, base::BindOnce(continuation, browser_context, url, callback));
criteria,
base::BindOnce(continuation, browser_context, url, std::move(callback)));
}
// static
......
......@@ -61,7 +61,7 @@ class OfflinePageUtils {
static const base::FilePath::CharType kMHTMLExtension[];
// Callback to inform the duplicate checking result.
using DuplicateCheckCallback = base::Callback<void(DuplicateCheckResult)>;
using DuplicateCheckCallback = base::OnceCallback<void(DuplicateCheckResult)>;
// Returns via callback all offline pages related to |url|. The provided URL
// is matched both against the original and the actual URL fields (they
......@@ -117,7 +117,7 @@ class OfflinePageUtils {
// for more details.
static void CheckDuplicateDownloads(content::BrowserContext* browser_context,
const GURL& url,
const DuplicateCheckCallback& callback);
DuplicateCheckCallback callback);
// Shows appropriate UI to indicate to the user that the |url| is either
// already downloaded or is already scheduled to be downloaded soon (as
......@@ -125,7 +125,7 @@ class OfflinePageUtils {
// continue with creating a duplicate - which is indicated by invoking the
// |confirm_continuation|, or cancels the whole operation which does not
// invoke continuation then.
static void ShowDuplicatePrompt(const base::Closure& confirm_continuation,
static void ShowDuplicatePrompt(base::OnceClosure confirm_continuation,
const GURL& url,
bool exists_duplicate_request,
content::WebContents* web_contents);
......
......@@ -60,7 +60,7 @@ class PrefetchInstanceIDProxyTest : public testing::Test {
InstanceID::Result result_ = InstanceID::UNKNOWN_ERROR;
bool async_operation_completed_ = false;
base::Closure async_operation_completed_callback_;
base::OnceClosure async_operation_completed_callback_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(PrefetchInstanceIDProxyTest);
......@@ -105,7 +105,7 @@ void PrefetchInstanceIDProxyTest::GetTokenCompleted(const std::string& token,
token_ = token;
result_ = result;
if (!async_operation_completed_callback_.is_null())
async_operation_completed_callback_.Run();
std::move(async_operation_completed_callback_).Run();
}
TEST_F(PrefetchInstanceIDProxyTest, GetToken) {
......
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