Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: content/browser/download/mhtml_generation_manager.cc

Issue 22920005: Refactor MHTMLGenerator to allow getting sending the data to a file descriptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/mhtml_generation_manager.cc
diff --git a/content/browser/download/mhtml_generation_manager.cc b/content/browser/download/mhtml_generation_manager.cc
index c4bc378c1480907cb61800114c0b788e3d376077..7d7d4bb2645cfa9ce4359574e4158b26a2316bea 100644
--- a/content/browser/download/mhtml_generation_manager.cc
+++ b/content/browser/download/mhtml_generation_manager.cc
@@ -36,29 +36,12 @@ MHTMLGenerationManager::MHTMLGenerationManager() {
MHTMLGenerationManager::~MHTMLGenerationManager() {
}
-void MHTMLGenerationManager::GenerateMHTML(
- WebContents* web_contents,
- const base::FilePath& file,
- const GenerateMHTMLCallback& callback) {
+void MHTMLGenerationManager::SaveMHTML(WebContents* web_contents,
+ const base::FilePath& file,
+ const GenerateMHTMLCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- static int id_counter = 0;
- int job_id = id_counter++;
- Job job;
- job.file_path = file;
- job.process_id = web_contents->GetRenderProcessHost()->GetID();
- job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
- job.callback = callback;
- id_to_job_[job_id] = job;
- if (!registrar_.IsRegistered(
- this,
- NOTIFICATION_RENDERER_PROCESS_TERMINATED,
- Source<RenderProcessHost>(web_contents->GetRenderProcessHost()))) {
- registrar_.Add(
- this,
- NOTIFICATION_RENDERER_PROCESS_TERMINATED,
- Source<RenderProcessHost>(web_contents->GetRenderProcessHost()));
- }
+ int job_id = NewJob(web_contents, callback);
base::ProcessHandle renderer_process =
web_contents->GetRenderProcessHost()->GetHandle();
@@ -67,6 +50,23 @@ void MHTMLGenerationManager::GenerateMHTML(
job_id, file, renderer_process));
}
+void MHTMLGenerationManager::StreamMHTML(
+ WebContents* web_contents,
+ const base::PlatformFile browser_file,
+ const GenerateMHTMLCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ int job_id = NewJob(web_contents, callback);
+
+ base::ProcessHandle renderer_process =
+ web_contents->GetRenderProcessHost()->GetHandle();
+ IPC::PlatformFileForTransit renderer_file =
+ IPC::GetFileHandleForProcess(browser_file, renderer_process, false);
+
+ FileHandleAvailable(job_id, browser_file, renderer_file);
+}
+
+
void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) {
JobFinished(job_id, mhtml_data_size);
}
@@ -86,12 +86,17 @@ void MHTMLGenerationManager::CreateFile(
IPC::PlatformFileForTransit renderer_file =
IPC::GetFileHandleForProcess(browser_file, renderer_process, false);
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&MHTMLGenerationManager::FileCreated, base::Unretained(this),
- job_id, browser_file, renderer_file));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&MHTMLGenerationManager::FileHandleAvailable,
+ base::Unretained(this),
+ job_id,
+ browser_file,
+ renderer_file));
}
-void MHTMLGenerationManager::FileCreated(int job_id,
+void MHTMLGenerationManager::FileHandleAvailable(int job_id,
base::PlatformFile browser_file,
IPC::PlatformFileForTransit renderer_file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -131,7 +136,7 @@ void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) {
}
Job& job = iter->second;
- job.callback.Run(job.file_path, file_size);
+ job.callback.Run(file_size);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&MHTMLGenerationManager::CloseFile, base::Unretained(this),
@@ -145,6 +150,26 @@ void MHTMLGenerationManager::CloseFile(base::PlatformFile file) {
base::ClosePlatformFile(file);
}
+int MHTMLGenerationManager::NewJob(WebContents* web_contents,
+ const GenerateMHTMLCallback& callback) {
+ static int id_counter = 0;
+ int job_id = id_counter++;
+ Job& job = id_to_job_[job_id];
+ job.process_id = web_contents->GetRenderProcessHost()->GetID();
+ job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
+ job.callback = callback;
+ if (!registrar_.IsRegistered(
+ this,
+ NOTIFICATION_RENDERER_PROCESS_TERMINATED,
+ Source<RenderProcessHost>(web_contents->GetRenderProcessHost()))) {
+ registrar_.Add(
+ this,
+ NOTIFICATION_RENDERER_PROCESS_TERMINATED,
+ Source<RenderProcessHost>(web_contents->GetRenderProcessHost()));
+ }
+ return job_id;
+}
+
void MHTMLGenerationManager::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {

Powered by Google App Engine
This is Rietveld 408576698