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