| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/process.h" | 12 #include "base/process.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
| 16 | 16 |
| 17 class FilePath; | 17 class FilePath; |
| 18 class TabContents; | 18 class TabContents; |
| 19 | 19 |
| 20 class CONTENT_EXPORT MHTMLGenerationManager | 20 class CONTENT_EXPORT MHTMLGenerationManager |
| 21 : public base::RefCountedThreadSafe< | 21 : public base::RefCountedThreadSafe< |
| 22 MHTMLGenerationManager, content::BrowserThread::DeleteOnUIThread> { | 22 MHTMLGenerationManager, content::BrowserThread::DeleteOnUIThread> { |
| 23 public: | 23 public: |
| 24 MHTMLGenerationManager(); | 24 MHTMLGenerationManager(); |
| 25 ~MHTMLGenerationManager(); | 25 ~MHTMLGenerationManager(); |
| 26 | 26 |
| 27 typedef base::Callback<void(const FilePath& /* path to the MHTML file */, |
| 28 int64 /* size of the file */)> GenerateMHTMLCallback; |
| 29 |
| 27 // Instructs the render view to generate a MHTML representation of the current | 30 // Instructs the render view to generate a MHTML representation of the current |
| 28 // page for |tab_contents|. | 31 // page for |tab_contents|. |
| 29 void GenerateMHTML(TabContents* tab_contents, const FilePath& file); | 32 void GenerateMHTML(TabContents* tab_contents, |
| 33 const FilePath& file, |
| 34 const GenerateMHTMLCallback& callback); |
| 30 | 35 |
| 31 // Notification from the renderer that the MHTML generation finished. | 36 // Notification from the renderer that the MHTML generation finished. |
| 32 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, | 37 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, |
| 33 // or -1 in case of failure. | 38 // or -1 in case of failure. |
| 34 void MHTMLGenerated(int job_id, int64 mhtml_data_size); | 39 void MHTMLGenerated(int job_id, int64 mhtml_data_size); |
| 35 | 40 |
| 36 // The details sent along with the MHTML_GENERATED notification. | |
| 37 struct NotificationDetails { | |
| 38 FilePath file_path; | |
| 39 int64 file_size; | |
| 40 }; | |
| 41 | |
| 42 private: | 41 private: |
| 43 struct Job{ | 42 struct Job{ |
| 44 Job(); | 43 Job(); |
| 44 ~Job(); |
| 45 | 45 |
| 46 FilePath file_path; | 46 FilePath file_path; |
| 47 | 47 |
| 48 // The handles to file the MHTML is saved to, for the browser and renderer | 48 // The handles to file the MHTML is saved to, for the browser and renderer |
| 49 // processes. | 49 // processes. |
| 50 base::PlatformFile browser_file; | 50 base::PlatformFile browser_file; |
| 51 IPC::PlatformFileForTransit renderer_file; | 51 IPC::PlatformFileForTransit renderer_file; |
| 52 | 52 |
| 53 // The IDs mapping to a specific tab. | 53 // The IDs mapping to a specific tab. |
| 54 int process_id; | 54 int process_id; |
| 55 int routing_id; | 55 int routing_id; |
| 56 |
| 57 // The callback to call once generation is complete. |
| 58 GenerateMHTMLCallback callback; |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 // Called on the file thread to create |file|. | 61 // Called on the file thread to create |file|. |
| 59 void CreateFile(int job_id, | 62 void CreateFile(int job_id, |
| 60 const FilePath& file, | 63 const FilePath& file, |
| 61 base::ProcessHandle renderer_process); | 64 base::ProcessHandle renderer_process); |
| 62 | 65 |
| 63 // Called on the UI thread when the file that should hold the MHTML data has | 66 // Called on the UI thread when the file that should hold the MHTML data has |
| 64 // been created. This returns a handle to that file for the browser process | 67 // been created. This returns a handle to that file for the browser process |
| 65 // and one for the renderer process. These handles are | 68 // and one for the renderer process. These handles are |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 // |mhtml_data_size| is -1 if the MHTML generation failed. | 79 // |mhtml_data_size| is -1 if the MHTML generation failed. |
| 77 void JobFinished(int job_id, int64 mhtml_data_size); | 80 void JobFinished(int job_id, int64 mhtml_data_size); |
| 78 | 81 |
| 79 typedef std::map<int, Job> IDToJobMap; | 82 typedef std::map<int, Job> IDToJobMap; |
| 80 IDToJobMap id_to_job_; | 83 IDToJobMap id_to_job_; |
| 81 | 84 |
| 82 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 85 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 88 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| OLD | NEW |