Commit d3711b44 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Switch MHTML generation to the new callbacks.

BUG=714018

Change-Id: I33cd6842055c959af25e286b1962c6f902b35971
Reviewed-on: https://chromium-review.googlesource.com/974284Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545087}
parent 7c1d03f5
......@@ -500,8 +500,8 @@ void AwContents::GenerateMHTML(JNIEnv* env,
base::FilePath target_path(ConvertJavaStringToUTF8(env, jpath));
web_contents_->GenerateMHTML(
content::MHTMLGenerationParams(target_path),
base::Bind(&GenerateMHTMLCallback,
ScopedJavaGlobalRef<jobject>(env, callback), target_path));
base::BindOnce(&GenerateMHTMLCallback,
ScopedJavaGlobalRef<jobject>(env, callback), target_path));
}
void AwContents::CreatePdfExporter(JNIEnv* env,
......
......@@ -210,7 +210,7 @@ void PageCaptureSaveAsMHTMLFunction::TemporaryFileCreatedOnUI(bool success) {
web_contents->GenerateMHTML(
content::MHTMLGenerationParams(mhtml_path_),
base::Bind(&PageCaptureSaveAsMHTMLFunction::MHTMLGenerated, this));
base::BindOnce(&PageCaptureSaveAsMHTMLFunction::MHTMLGenerated, this));
}
void PageCaptureSaveAsMHTMLFunction::MHTMLGenerated(int64_t mhtml_file_size) {
......
......@@ -128,8 +128,8 @@ void OfflinePageMHTMLArchiver::GenerateMHTML(
web_contents_->GenerateMHTML(
params,
base::Bind(&OfflinePageMHTMLArchiver::OnGenerateMHTMLDone,
weak_ptr_factory_.GetWeakPtr(), url, file_path, title));
base::BindOnce(&OfflinePageMHTMLArchiver::OnGenerateMHTMLDone,
weak_ptr_factory_.GetWeakPtr(), url, file_path, title));
}
void OfflinePageMHTMLArchiver::OnGenerateMHTMLDone(
......
......@@ -88,9 +88,9 @@ void TestMHTMLArchiver::GenerateMHTML(
base::FilePath archive_file_path =
archives_dir.AppendASCII(url_.ExtractFileName());
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&TestMHTMLArchiver::OnGenerateMHTMLDone,
base::Unretained(this), url_, archive_file_path,
kTestTitle, kTestFileSize));
FROM_HERE, base::BindOnce(&TestMHTMLArchiver::OnGenerateMHTMLDone,
base::Unretained(this), url_, archive_file_path,
kTestTitle, kTestFileSize));
}
bool TestMHTMLArchiver::HasConnectionSecurityError() {
......
......@@ -120,9 +120,8 @@ class MHTMLGenerationTest : public ContentBrowserTest {
histogram_tester_.reset(new base::HistogramTester());
shell()->web_contents()->GenerateMHTML(
params, base::Bind(&MHTMLGenerationTest::MHTMLGenerated,
base::Unretained(this),
run_loop.QuitClosure()));
params, base::BindOnce(&MHTMLGenerationTest::MHTMLGenerated,
base::Unretained(this), run_loop.QuitClosure()));
// Block until the MHTML is generated.
run_loop.Run();
......
......@@ -51,14 +51,14 @@ class MHTMLGenerationManager::Job : public RenderProcessHostObserver {
Job(int job_id,
WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback);
GenerateMHTMLCallback callback);
~Job() override;
int id() const { return job_id_; }
void set_browser_file(base::File file) { browser_file_ = std::move(file); }
base::TimeTicks creation_time() const { return creation_time_; }
const GenerateMHTMLCallback& callback() const { return callback_; }
GenerateMHTMLCallback callback() { return std::move(callback_); }
// Indicates whether we expect a message from the |sender| at this time.
// We expect only one message per frame - therefore calling this method
......@@ -88,7 +88,7 @@ class MHTMLGenerationManager::Job : public RenderProcessHostObserver {
// back on the UI thread with the updated status and file size (which will be
// negative in case of errors).
void CloseFile(
base::Callback<void(const std::tuple<MhtmlSaveStatus, int64_t>&)>
base::OnceCallback<void(const std::tuple<MhtmlSaveStatus, int64_t>&)>
callback,
MhtmlSaveStatus save_status);
......@@ -175,7 +175,7 @@ class MHTMLGenerationManager::Job : public RenderProcessHostObserver {
std::string salt_;
// The callback to call once generation is complete.
const GenerateMHTMLCallback callback_;
GenerateMHTMLCallback callback_;
// Whether the job is finished (set to true only for the short duration of
// time between MHTMLGenerationManager::JobFinished is called and the job is
......@@ -195,14 +195,14 @@ class MHTMLGenerationManager::Job : public RenderProcessHostObserver {
MHTMLGenerationManager::Job::Job(int job_id,
WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback)
GenerateMHTMLCallback callback)
: job_id_(job_id),
creation_time_(base::TimeTicks::Now()),
params_(params),
frame_tree_node_id_of_busy_frame_(FrameTreeNode::kFrameTreeNodeInvalidId),
mhtml_boundary_marker_(net::GenerateMimeMultipartBoundary()),
salt_(base::GenerateGUID()),
callback_(callback),
callback_(std::move(callback)),
is_finished_(false),
observed_renderer_process_host_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -371,7 +371,8 @@ void MHTMLGenerationManager::Job::RenderProcessHostDestroyed(
}
void MHTMLGenerationManager::Job::CloseFile(
base::Callback<void(const std::tuple<MhtmlSaveStatus, int64_t>&)> callback,
base::OnceCallback<void(const std::tuple<MhtmlSaveStatus, int64_t>&)>
callback,
MhtmlSaveStatus save_status) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!mhtml_boundary_marker_.empty());
......@@ -387,7 +388,7 @@ void MHTMLGenerationManager::Job::CloseFile(
// If no previous error occurred the boundary should be sent.
base::PostTaskAndReplyWithResult(
download::GetDownloadTaskRunner().get(), FROM_HERE,
base::Bind(
base::BindOnce(
&MHTMLGenerationManager::Job::FinalizeAndCloseFileOnFileThread,
save_status,
(save_status == MhtmlSaveStatus::SUCCESS ? mhtml_boundary_marker_
......@@ -542,10 +543,10 @@ MHTMLGenerationManager::~MHTMLGenerationManager() {
void MHTMLGenerationManager::SaveMHTML(WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback) {
GenerateMHTMLCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Job* job = NewJob(web_contents, params, callback);
Job* job = NewJob(web_contents, params, std::move(callback));
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
"page-serialization", "SavingMhtmlJob", job, "url",
web_contents->GetLastCommittedURL().possibly_invalid_spec(),
......@@ -644,9 +645,9 @@ void MHTMLGenerationManager::JobFinished(Job* job,
DCHECK(job);
job->MarkAsFinished();
job->CloseFile(
base::Bind(&MHTMLGenerationManager::OnFileClosed,
base::Unretained(this), // Safe b/c |this| is a singleton.
job->id()),
base::BindOnce(&MHTMLGenerationManager::OnFileClosed,
base::Unretained(this), // Safe b/c |this| is a singleton.
job->id()),
save_status);
}
......@@ -667,17 +668,18 @@ void MHTMLGenerationManager::OnFileClosed(
UMA_HISTOGRAM_ENUMERATION("PageSerialization.MhtmlGeneration.FinalSaveStatus",
static_cast<int>(save_status),
static_cast<int>(MhtmlSaveStatus::LAST));
job->callback().Run(save_status == MhtmlSaveStatus::SUCCESS ? file_size : -1);
std::move(job->callback())
.Run(save_status == MhtmlSaveStatus::SUCCESS ? file_size : -1);
id_to_job_.erase(job_id);
}
MHTMLGenerationManager::Job* MHTMLGenerationManager::NewJob(
WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback) {
GenerateMHTMLCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Job* job = new Job(++next_job_id_, web_contents, params, callback);
Job* job = new Job(++next_job_id_, web_contents, params, std::move(callback));
id_to_job_[job->id()] = base::WrapUnique(job);
return job;
}
......
......@@ -41,13 +41,13 @@ class MHTMLGenerationManager {
// GenerateMHTMLCallback is called to report completion and status of MHTML
// generation. On success |file_size| indicates the size of the
// generated file. On failure |file_size| is -1.
typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback;
using GenerateMHTMLCallback = base::OnceCallback<void(int64_t file_size)>;
// Instructs the RenderFrames in |web_contents| to generate a MHTML
// representation of the current page.
void SaveMHTML(WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback);
GenerateMHTMLCallback callback);
// Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the
// renderer that the MHTML generation finished for a single frame).
......@@ -83,7 +83,7 @@ class MHTMLGenerationManager {
// Creates and registers a new job.
Job* NewJob(WebContents* web_contents,
const MHTMLGenerationParams& params,
const GenerateMHTMLCallback& callback);
GenerateMHTMLCallback callback);
// Finds job by id. Returns nullptr if no job with a given id was found.
Job* FindJob(int job_id);
......
......@@ -314,7 +314,7 @@ void SavePackage::InitWithDownloadItem(
MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_);
web_contents()->GenerateMHTML(
mhtml_generation_params,
base::Bind(&SavePackage::OnMHTMLGenerated, this));
base::BindOnce(&SavePackage::OnMHTMLGenerated, this));
} else {
DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_);
wait_state_ = NET_FILES;
......
......@@ -3411,8 +3411,9 @@ void WebContentsImpl::SaveFrameWithHeaders(
void WebContentsImpl::GenerateMHTML(
const MHTMLGenerationParams& params,
const base::Callback<void(int64_t)>& callback) {
MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
base::OnceCallback<void(int64_t)> callback) {
MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
std::move(callback));
}
const std::string& WebContentsImpl::GetContentsMimeType() const {
......
......@@ -418,7 +418,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
const std::string& headers,
const base::string16& suggested_filename) override;
void GenerateMHTML(const MHTMLGenerationParams& params,
const base::Callback<void(int64_t)>& callback) override;
base::OnceCallback<void(int64_t)> callback) override;
const std::string& GetContentsMimeType() const override;
bool WillNotifyDisconnection() const override;
RendererPreferences* GetMutableRendererPrefs() override;
......
......@@ -628,7 +628,7 @@ class WebContents : public PageNavigator,
// not the recommended encoding for shareable content.
virtual void GenerateMHTML(
const MHTMLGenerationParams& params,
const base::Callback<void(int64_t /* size of the file */)>& callback) = 0;
base::OnceCallback<void(int64_t /* size of the file */)> callback) = 0;
// Returns the contents MIME type after a navigation.
virtual const std::string& GetContentsMimeType() const = 0;
......
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