summaryrefslogtreecommitdiff
path: root/content/browser/download/mhtml_generation_manager.h
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2012-11-14 11:43:16 +0000
committerTorne (Richard Coles) <torne@google.com>2012-11-14 11:43:16 +0000
commit5821806d5e7f356e8fa4b058a389a808ea183019 (patch)
treee19f4793aac92e2c0d9a01087019a60d6657d838 /content/browser/download/mhtml_generation_manager.h
parent8e79a8efe247f109aafd917a69e8a392961b3687 (diff)
downloadchromium_org-5821806d5e7f356e8fa4b058a389a808ea183019.tar.gz
Merge from Chromium at DEPS revision r167172
This commit was generated by merge_to_master.py. Change-Id: Ib8d56fd5ae39a2d7e8c91dcd76cc6d13f25f2aab
Diffstat (limited to 'content/browser/download/mhtml_generation_manager.h')
-rw-r--r--content/browser/download/mhtml_generation_manager.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/content/browser/download/mhtml_generation_manager.h b/content/browser/download/mhtml_generation_manager.h
new file mode 100644
index 0000000000..54b8733dd3
--- /dev/null
+++ b/content/browser/download/mhtml_generation_manager.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
+#define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
+
+#include <map>
+
+#include "base/memory/singleton.h"
+#include "base/platform_file.h"
+#include "base/process.h"
+#include "ipc/ipc_platform_file.h"
+
+class FilePath;
+
+namespace content {
+class WebContents;
+
+class MHTMLGenerationManager {
+ public:
+ static MHTMLGenerationManager* GetInstance();
+
+ typedef base::Callback<void(const FilePath& /* path to the MHTML file */,
+ 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 FilePath& 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,
+ // or -1 in case of failure.
+ void MHTMLGenerated(int job_id, int64 mhtml_data_size);
+
+ private:
+ friend struct DefaultSingletonTraits<MHTMLGenerationManager>;
+
+ struct Job{
+ Job();
+ ~Job();
+
+ FilePath file_path;
+
+ // The handles to file the MHTML is saved to, for the browser and renderer
+ // processes.
+ base::PlatformFile browser_file;
+ IPC::PlatformFileForTransit renderer_file;
+
+ // The IDs mapping to a specific contents.
+ int process_id;
+ int routing_id;
+
+ // The callback to call once generation is complete.
+ GenerateMHTMLCallback callback;
+ };
+
+ MHTMLGenerationManager();
+ ~MHTMLGenerationManager();
+
+ // Called on the file thread to create |file|.
+ void CreateFile(int job_id,
+ const FilePath& file,
+ base::ProcessHandle renderer_process);
+
+ // Called on the UI thread when the file that should hold the MHTML data has
+ // 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);
+
+ // Called on the file thread to close the file the MHTML was saved to.
+ void CloseFile(base::PlatformFile file);
+
+ // Called on the UI thread when a job has been processed (successfully or
+ // not). Closes the file and removes the job from the job map.
+ // |mhtml_data_size| is -1 if the MHTML generation failed.
+ void JobFinished(int job_id, int64 mhtml_data_size);
+
+ typedef std::map<int, Job> IDToJobMap;
+ IDToJobMap id_to_job_;
+
+ DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_