summaryrefslogtreecommitdiffstats
path: root/content/browser/download
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 18:19:48 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 18:19:48 +0000
commit18516cf967b0fe2c50c1f51a882a3343289e8d63 (patch)
tree248c4961056fa4960c9d55778e12e0e26a9f7b61 /content/browser/download
parent9664576f7f52aad46352556e6dc07fd0f6653af6 (diff)
downloadchromium_src-18516cf967b0fe2c50c1f51a882a3343289e8d63.zip
chromium_src-18516cf967b0fe2c50c1f51a882a3343289e8d63.tar.gz
chromium_src-18516cf967b0fe2c50c1f51a882a3343289e8d63.tar.bz2
Refactor MHTMLGenerator to allow getting sending the data to a file descriptor.
TBR=darin@chromium.org Review URL: https://chromiumcodereview.appspot.com/22920005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download')
-rw-r--r--content/browser/download/mhtml_generation_browsertest.cc2
-rw-r--r--content/browser/download/mhtml_generation_manager.cc77
-rw-r--r--content/browser/download/mhtml_generation_manager.h27
-rw-r--r--content/browser/download/save_package.cc2
-rw-r--r--content/browser/download/save_package.h2
5 files changed, 71 insertions, 39 deletions
diff --git a/content/browser/download/mhtml_generation_browsertest.cc b/content/browser/download/mhtml_generation_browsertest.cc
index 7e99fb26..6e79013 100644
--- a/content/browser/download/mhtml_generation_browsertest.cc
+++ b/content/browser/download/mhtml_generation_browsertest.cc
@@ -21,7 +21,7 @@ class MHTMLGenerationTest : public ContentBrowserTest {
public:
MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {}
- void MHTMLGenerated(const base::FilePath& path, int64 size) {
+ void MHTMLGenerated(int64 size) {
mhtml_generated_ = true;
file_size_ = size;
base::MessageLoopForUI::current()->Quit();
diff --git a/content/browser/download/mhtml_generation_manager.cc b/content/browser/download/mhtml_generation_manager.cc
index c4bc378..7d7d4bb 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) {
diff --git a/content/browser/download/mhtml_generation_manager.h b/content/browser/download/mhtml_generation_manager.h
index 0c9ec61..5525d99 100644
--- a/content/browser/download/mhtml_generation_manager.h
+++ b/content/browser/download/mhtml_generation_manager.h
@@ -25,14 +25,20 @@ class MHTMLGenerationManager : public NotificationObserver {
public:
static MHTMLGenerationManager* GetInstance();
- typedef base::Callback<void(const base::FilePath& /* path to the MHTML file */,
- int64 /* size of the file */)> GenerateMHTMLCallback;
+ typedef base::Callback<void(int64 /* size of the file */)>
+ GenerateMHTMLCallback;
// Instructs the render view to generate a MHTML representation of the current
// page for |web_contents|.
- void GenerateMHTML(WebContents* web_contents,
- const base::FilePath& file,
- const GenerateMHTMLCallback& callback);
+ void SaveMHTML(WebContents* web_contents,
+ const base::FilePath& file,
+ const GenerateMHTMLCallback& callback);
+
+ // Instructs the render view to generate a MHTML representation of the current
+ // page for |web_contents|.
+ void StreamMHTML(WebContents* web_contents,
+ const base::PlatformFile file,
+ const GenerateMHTMLCallback& callback);
// Notification from the renderer that the MHTML generation finished.
// |mhtml_data_size| contains the size in bytes of the generated MHTML data,
@@ -46,8 +52,6 @@ class MHTMLGenerationManager : public NotificationObserver {
Job();
~Job();
- base::FilePath file_path;
-
// The handles to file the MHTML is saved to, for the browser and renderer
// processes.
base::PlatformFile browser_file;
@@ -73,9 +77,9 @@ class MHTMLGenerationManager : public NotificationObserver {
// been created. This returns a handle to that file for the browser process
// and one for the renderer process. These handles are
// kInvalidPlatformFileValue if the file could not be opened.
- void FileCreated(int job_id,
- base::PlatformFile browser_file,
- IPC::PlatformFileForTransit renderer_file);
+ void FileHandleAvailable(int job_id,
+ base::PlatformFile browser_file,
+ IPC::PlatformFileForTransit renderer_file);
// Called on the file thread to close the file the MHTML was saved to.
void CloseFile(base::PlatformFile file);
@@ -85,6 +89,9 @@ class MHTMLGenerationManager : public NotificationObserver {
// |mhtml_data_size| is -1 if the MHTML generation failed.
void JobFinished(int job_id, int64 mhtml_data_size);
+ // Creates an register a new job.
+ int NewJob(WebContents* web_contents, const GenerateMHTMLCallback& callback);
+
// Implementation of NotificationObserver.
virtual void Observe(int type,
const NotificationSource& source,
diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc
index 29d8912..f38f9cd 100644
--- a/content/browser/download/save_package.cc
+++ b/content/browser/download/save_package.cc
@@ -363,7 +363,7 @@ void SavePackage::InitWithDownloadItem(
}
}
-void SavePackage::OnMHTMLGenerated(const base::FilePath& path, int64 size) {
+void SavePackage::OnMHTMLGenerated(int64 size) {
if (size <= 0) {
Cancel(false);
return;
diff --git a/content/browser/download/save_package.h b/content/browser/download/save_package.h
index b53280d..939002e 100644
--- a/content/browser/download/save_package.h
+++ b/content/browser/download/save_package.h
@@ -129,7 +129,7 @@ class CONTENT_EXPORT SavePackage
DownloadItemImpl* item);
// Callback for WebContents::GenerateMHTML().
- void OnMHTMLGenerated(const base::FilePath& path, int64 size);
+ void OnMHTMLGenerated(int64 size);
// For testing only.
SavePackage(WebContents* web_contents,