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 */, | |
jam
2011/11/22 23:06:00
nit: can you make these two parameters line up?
| |
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(); |
45 | 44 |
46 FilePath file_path; | 45 FilePath file_path; |
47 | 46 |
48 // The handles to file the MHTML is saved to, for the browser and renderer | 47 // The handles to file the MHTML is saved to, for the browser and renderer |
49 // processes. | 48 // processes. |
50 base::PlatformFile browser_file; | 49 base::PlatformFile browser_file; |
51 IPC::PlatformFileForTransit renderer_file; | 50 IPC::PlatformFileForTransit renderer_file; |
52 | 51 |
53 // The IDs mapping to a specific tab. | 52 // The IDs mapping to a specific tab. |
54 int process_id; | 53 int process_id; |
55 int routing_id; | 54 int routing_id; |
55 | |
56 // The callback to call once generation is complete. | |
57 GenerateMHTMLCallback callback; | |
56 }; | 58 }; |
57 | 59 |
58 // Called on the file thread to create |file|. | 60 // Called on the file thread to create |file|. |
59 void CreateFile(int job_id, | 61 void CreateFile(int job_id, |
60 const FilePath& file, | 62 const FilePath& file, |
61 base::ProcessHandle renderer_process); | 63 base::ProcessHandle renderer_process); |
62 | 64 |
63 // Called on the UI thread when the file that should hold the MHTML data has | 65 // 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 | 66 // been created. This returns a handle to that file for the browser process |
65 // and one for the renderer process. These handles are | 67 // 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. | 78 // |mhtml_data_size| is -1 if the MHTML generation failed. |
77 void JobFinished(int job_id, int64 mhtml_data_size); | 79 void JobFinished(int job_id, int64 mhtml_data_size); |
78 | 80 |
79 typedef std::map<int, Job> IDToJobMap; | 81 typedef std::map<int, Job> IDToJobMap; |
80 IDToJobMap id_to_job_; | 82 IDToJobMap id_to_job_; |
81 | 83 |
82 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 84 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
83 }; | 85 }; |
84 | 86 |
85 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 87 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
OLD | NEW |