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