Commit afa58d45 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

Convert to OnceCallback for downloads in content/public.

Bug: 1007763
Change-Id: I5d7de99da99b88f59cd56832b0f87c32e8d0be27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942901Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720674}
parent bb647ef9
......@@ -624,15 +624,11 @@ void ChromeDownloadManagerDelegate::ChooseSavePath(
const base::FilePath& suggested_path,
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
const content::SavePackagePathPickedCallback& callback) {
content::SavePackagePathPickedCallback callback) {
// Deletes itself.
new SavePackageFilePicker(
web_contents,
suggested_path,
default_extension,
can_save_as_complete,
download_prefs_.get(),
callback);
new SavePackageFilePicker(web_contents, suggested_path, default_extension,
can_save_as_complete, download_prefs_.get(),
std::move(callback));
}
void ChromeDownloadManagerDelegate::SanitizeSavePackageResourceName(
......
......@@ -103,12 +103,11 @@ class ChromeDownloadManagerDelegate
void GetSaveDir(content::BrowserContext* browser_context,
base::FilePath* website_save_dir,
base::FilePath* download_save_dir) override;
void ChooseSavePath(
content::WebContents* web_contents,
void ChooseSavePath(content::WebContents* web_contents,
const base::FilePath& suggested_path,
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
const content::SavePackagePathPickedCallback& callback) override;
content::SavePackagePathPickedCallback callback) override;
void SanitizeSavePackageResourceName(base::FilePath* filename) override;
void SanitizeDownloadParameters(
download::DownloadUrlParameters* params) override;
......
......@@ -134,11 +134,11 @@ SavePackageFilePicker::SavePackageFilePicker(
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
DownloadPrefs* download_prefs,
const content::SavePackagePathPickedCallback& callback)
content::SavePackagePathPickedCallback callback)
: render_process_id_(web_contents->GetMainFrame()->GetProcess()->GetID()),
can_save_as_complete_(can_save_as_complete),
download_prefs_(download_prefs),
callback_(callback) {
callback_(std::move(callback)) {
base::FilePath suggested_path_copy = suggested_path;
base::FilePath::StringType default_extension_copy = default_extension;
int file_type_index = 0;
......@@ -263,8 +263,8 @@ void SavePackageFilePicker::FileSelected(
download_prefs_->SetSaveFilePath(path_copy.DirName());
callback_.Run(path_copy, save_type,
base::Bind(&OnSavePackageDownloadCreated));
std::move(callback_).Run(path_copy, save_type,
base::BindOnce(&OnSavePackageDownloadCreated));
}
void SavePackageFilePicker::FileSelectionCanceled(void* unused_params) {
......
......@@ -18,13 +18,12 @@ class DownloadPrefs;
// Handles showing a dialog to the user to ask for the filename to save a page.
class SavePackageFilePicker : public ui::SelectFileDialog::Listener {
public:
SavePackageFilePicker(
content::WebContents* web_contents,
SavePackageFilePicker(content::WebContents* web_contents,
const base::FilePath& suggested_path,
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
DownloadPrefs* download_prefs,
const content::SavePackagePathPickedCallback& callback);
content::SavePackagePathPickedCallback callback);
~SavePackageFilePicker() override;
// Used to disable prompting the user for a directory/filename of the saved
......
......@@ -710,13 +710,13 @@ void DownloadManagerImpl::CreateSavePackageDownloadItem(
int render_process_id,
int render_frame_id,
download::DownloadJob::CancelRequestCallback cancel_request_callback,
const DownloadItemImplCreated& item_created) {
DownloadItemImplCreated item_created) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
GetNextId(
base::BindOnce(&DownloadManagerImpl::CreateSavePackageDownloadItemWithId,
weak_factory_.GetWeakPtr(), main_file_path, page_url,
mime_type, render_process_id, render_frame_id,
std::move(cancel_request_callback), item_created));
GetNextId(base::BindOnce(
&DownloadManagerImpl::CreateSavePackageDownloadItemWithId,
weak_factory_.GetWeakPtr(), main_file_path, page_url, mime_type,
render_process_id, render_frame_id, std::move(cancel_request_callback),
std::move(item_created)));
}
void DownloadManagerImpl::CreateSavePackageDownloadItemWithId(
......@@ -726,7 +726,7 @@ void DownloadManagerImpl::CreateSavePackageDownloadItemWithId(
int render_process_id,
int render_frame_id,
download::DownloadJob::CancelRequestCallback cancel_request_callback,
const DownloadItemImplCreated& item_created,
DownloadItemImplCreated item_created,
uint32_t id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_NE(download::DownloadItem::kInvalidId, id);
......@@ -739,7 +739,7 @@ void DownloadManagerImpl::CreateSavePackageDownloadItemWithId(
render_process_id, render_frame_id));
OnDownloadCreated(base::WrapUnique(download_item));
if (!item_created.is_null())
item_created.Run(download_item);
std::move(item_created).Run(download_item);
}
// Resume a download of a specific URL. We send the request to the
......
......@@ -51,7 +51,7 @@ class CONTENT_EXPORT DownloadManagerImpl
private download::DownloadItemImplDelegate {
public:
using DownloadItemImplCreated =
base::Callback<void(download::DownloadItemImpl*)>;
base::OnceCallback<void(download::DownloadItemImpl*)>;
// Caller guarantees that |net_log| will remain valid
// for the lifetime of DownloadManagerImpl (until Shutdown() is called).
......@@ -63,14 +63,14 @@ class CONTENT_EXPORT DownloadManagerImpl
// Creates a download item for the SavePackage system.
// Must be called on the UI thread. Note that the DownloadManager
// retains ownership.
virtual void CreateSavePackageDownloadItem(
void CreateSavePackageDownloadItem(
const base::FilePath& main_file_path,
const GURL& page_url,
const std::string& mime_type,
int render_process_id,
int render_frame_id,
download::DownloadJob::CancelRequestCallback cancel_request_callback,
const DownloadItemImplCreated& item_created);
DownloadItemImplCreated item_created);
// DownloadManager functions.
void SetDelegate(DownloadManagerDelegate* delegate) override;
......@@ -172,7 +172,7 @@ class CONTENT_EXPORT DownloadManagerImpl
int render_process_id,
int render_frame_id,
download::DownloadJob::CancelRequestCallback cancel_request_callback,
const DownloadItemImplCreated& on_started,
DownloadItemImplCreated on_started,
uint32_t id);
// InProgressDownloadManager::Delegate implementations.
......
......@@ -92,9 +92,12 @@ class MockDownloadManagerDelegate : public DownloadManagerDelegate {
const DownloadOpenDelayedCallback&));
MOCK_METHOD3(GetSaveDir,
void(BrowserContext*, base::FilePath*, base::FilePath*));
MOCK_METHOD5(ChooseSavePath, void(
WebContents*, const base::FilePath&, const base::FilePath::StringType&,
bool, const SavePackagePathPickedCallback&));
MOCK_METHOD5(ChooseSavePath,
void(WebContents*,
const base::FilePath&,
const base::FilePath::StringType&,
bool,
SavePackagePathPickedCallback));
MOCK_METHOD0(ApplicationClientIdForFileScanning, std::string());
};
......
......@@ -255,7 +255,7 @@ void SavePackage::InternalInit() {
}
bool SavePackage::Init(
const SavePackageDownloadCreatedCallback& download_created_callback) {
SavePackageDownloadCreatedCallback download_created_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(page_url_.is_valid());
// Set proper running state.
......@@ -278,20 +278,20 @@ bool SavePackage::Init(
: "text/html"),
frame_host->GetProcess()->GetID(), frame_host->GetRoutingID(),
base::BindOnce(&CancelSavePackage, AsWeakPtr()),
base::Bind(&SavePackage::InitWithDownloadItem, AsWeakPtr(),
download_created_callback));
base::BindOnce(&SavePackage::InitWithDownloadItem, AsWeakPtr(),
std::move(download_created_callback)));
return true;
}
void SavePackage::InitWithDownloadItem(
const SavePackageDownloadCreatedCallback& download_created_callback,
SavePackageDownloadCreatedCallback download_created_callback,
download::DownloadItemImpl* item) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(item);
download_ = item;
// Confirm above didn't delete the tab out from under us.
if (!download_created_callback.is_null())
download_created_callback.Run(download_);
std::move(download_created_callback).Run(download_);
// Check save type and process the save page job.
if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) {
......@@ -1316,17 +1316,14 @@ void SavePackage::ContinueGetSaveInfo(bool can_save_as_complete,
default_extension = kDefaultHtmlExtension;
download_manager_->GetDelegate()->ChooseSavePath(
web_contents(),
suggested_path,
default_extension,
can_save_as_complete,
base::Bind(&SavePackage::OnPathPicked, AsWeakPtr()));
web_contents(), suggested_path, default_extension, can_save_as_complete,
base::BindOnce(&SavePackage::OnPathPicked, AsWeakPtr()));
}
void SavePackage::OnPathPicked(
const base::FilePath& final_name,
SavePageType type,
const SavePackageDownloadCreatedCallback& download_created_callback) {
SavePackageDownloadCreatedCallback download_created_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK((type == SAVE_PAGE_TYPE_AS_ONLY_HTML) ||
(type == SAVE_PAGE_TYPE_AS_MHTML) ||
......@@ -1347,7 +1344,7 @@ void SavePackage::OnPathPicked(
FILE_PATH_LITERAL("_files"));
}
Init(download_created_callback);
Init(std::move(download_created_callback));
}
void SavePackage::FinalizeDownloadEntry() {
......
......@@ -97,7 +97,7 @@ class CONTENT_EXPORT SavePackage
// g_browser_process on a non-UI thread can cause crashes during shutdown.
// |cb| will be called when the download::DownloadItem is created, before data
// is written to disk.
bool Init(const SavePackageDownloadCreatedCallback& cb);
bool Init(SavePackageDownloadCreatedCallback cb);
// Cancel all in progress request, might be called by user or internal error.
void Cancel(bool user_action, bool cancel_download_item = true);
......@@ -159,7 +159,7 @@ class CONTENT_EXPORT SavePackage
~SavePackage() override;
void InitWithDownloadItem(
const SavePackageDownloadCreatedCallback& download_created_callback,
SavePackageDownloadCreatedCallback download_created_callback,
download::DownloadItemImpl* item);
// Callback for WebContents::GenerateMHTML().
......@@ -308,10 +308,9 @@ class CONTENT_EXPORT SavePackage
const base::FilePath& download_save_dir);
void ContinueGetSaveInfo(bool can_save_as_complete,
const base::FilePath& suggested_path);
void OnPathPicked(
const base::FilePath& final_name,
void OnPathPicked(const base::FilePath& final_name,
SavePageType type,
const SavePackageDownloadCreatedCallback& cb);
SavePackageDownloadCreatedCallback cb);
// The number of in process SaveItems.
int in_process_count() const {
......
......@@ -31,8 +31,8 @@ class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate {
const base::FilePath& suggested_path,
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
const SavePackagePathPickedCallback& callback) override {
callback.Run(suggested_path, save_page_type_,
SavePackagePathPickedCallback callback) override {
std::move(callback).Run(suggested_path, save_page_type_,
SavePackageDownloadCreatedCallback());
}
......
......@@ -28,16 +28,16 @@ class WebContents;
// Called by SavePackage when it creates a download::DownloadItem.
using SavePackageDownloadCreatedCallback =
base::Callback<void(download::DownloadItem*)>;
base::OnceCallback<void(download::DownloadItem*)>;
// Will be called asynchronously with the results of the ChooseSavePath
// operation. If the delegate wants notification of the download item created
// in response to this operation, the SavePackageDownloadCreatedCallback will be
// non-null.
using SavePackagePathPickedCallback =
base::Callback<void(const base::FilePath&,
base::OnceCallback<void(const base::FilePath&,
SavePageType,
const SavePackageDownloadCreatedCallback&)>;
SavePackageDownloadCreatedCallback)>;
// Called with the results of DetermineDownloadTarget().
//
......@@ -145,8 +145,7 @@ class CONTENT_EXPORT DownloadManagerDelegate {
const base::FilePath& suggested_path,
const base::FilePath::StringType& default_extension,
bool can_save_as_complete,
const SavePackagePathPickedCallback& callback) {
}
SavePackagePathPickedCallback callback) {}
// Sanitize a filename that's going to be used for saving a subresource of a
// SavePackage.
......
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