OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/singleton.h" | 10 #include "base/memory/singleton.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 "ipc/ipc_platform_file.h" | 13 #include "ipc/ipc_platform_file.h" |
14 | 14 |
| 15 namespace base { |
15 class FilePath; | 16 class FilePath; |
| 17 } |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 class WebContents; | 20 class WebContents; |
19 | 21 |
20 class MHTMLGenerationManager { | 22 class MHTMLGenerationManager { |
21 public: | 23 public: |
22 static MHTMLGenerationManager* GetInstance(); | 24 static MHTMLGenerationManager* GetInstance(); |
23 | 25 |
24 typedef base::Callback<void(const FilePath& /* path to the MHTML file */, | 26 typedef base::Callback<void(const base::FilePath& /* path to the MHTML file */
, |
25 int64 /* size of the file */)> GenerateMHTMLCallback; | 27 int64 /* size of the file */)> GenerateMHTMLCallback; |
26 | 28 |
27 // Instructs the render view to generate a MHTML representation of the current | 29 // Instructs the render view to generate a MHTML representation of the current |
28 // page for |web_contents|. | 30 // page for |web_contents|. |
29 void GenerateMHTML(WebContents* web_contents, | 31 void GenerateMHTML(WebContents* web_contents, |
30 const FilePath& file, | 32 const base::FilePath& file, |
31 const GenerateMHTMLCallback& callback); | 33 const GenerateMHTMLCallback& callback); |
32 | 34 |
33 // Notification from the renderer that the MHTML generation finished. | 35 // Notification from the renderer that the MHTML generation finished. |
34 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, | 36 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, |
35 // or -1 in case of failure. | 37 // or -1 in case of failure. |
36 void MHTMLGenerated(int job_id, int64 mhtml_data_size); | 38 void MHTMLGenerated(int job_id, int64 mhtml_data_size); |
37 | 39 |
38 private: | 40 private: |
39 friend struct DefaultSingletonTraits<MHTMLGenerationManager>; | 41 friend struct DefaultSingletonTraits<MHTMLGenerationManager>; |
40 | 42 |
41 struct Job{ | 43 struct Job{ |
42 Job(); | 44 Job(); |
43 ~Job(); | 45 ~Job(); |
44 | 46 |
45 FilePath file_path; | 47 base::FilePath file_path; |
46 | 48 |
47 // The handles to file the MHTML is saved to, for the browser and renderer | 49 // The handles to file the MHTML is saved to, for the browser and renderer |
48 // processes. | 50 // processes. |
49 base::PlatformFile browser_file; | 51 base::PlatformFile browser_file; |
50 IPC::PlatformFileForTransit renderer_file; | 52 IPC::PlatformFileForTransit renderer_file; |
51 | 53 |
52 // The IDs mapping to a specific contents. | 54 // The IDs mapping to a specific contents. |
53 int process_id; | 55 int process_id; |
54 int routing_id; | 56 int routing_id; |
55 | 57 |
56 // The callback to call once generation is complete. | 58 // The callback to call once generation is complete. |
57 GenerateMHTMLCallback callback; | 59 GenerateMHTMLCallback callback; |
58 }; | 60 }; |
59 | 61 |
60 MHTMLGenerationManager(); | 62 MHTMLGenerationManager(); |
61 ~MHTMLGenerationManager(); | 63 ~MHTMLGenerationManager(); |
62 | 64 |
63 // Called on the file thread to create |file|. | 65 // Called on the file thread to create |file|. |
64 void CreateFile(int job_id, | 66 void CreateFile(int job_id, |
65 const FilePath& file, | 67 const base::FilePath& file, |
66 base::ProcessHandle renderer_process); | 68 base::ProcessHandle renderer_process); |
67 | 69 |
68 // Called on the UI thread when the file that should hold the MHTML data has | 70 // Called on the UI thread when the file that should hold the MHTML data has |
69 // been created. This returns a handle to that file for the browser process | 71 // been created. This returns a handle to that file for the browser process |
70 // and one for the renderer process. These handles are | 72 // and one for the renderer process. These handles are |
71 // kInvalidPlatformFileValue if the file could not be opened. | 73 // kInvalidPlatformFileValue if the file could not be opened. |
72 void FileCreated(int job_id, | 74 void FileCreated(int job_id, |
73 base::PlatformFile browser_file, | 75 base::PlatformFile browser_file, |
74 IPC::PlatformFileForTransit renderer_file); | 76 IPC::PlatformFileForTransit renderer_file); |
75 | 77 |
76 // Called on the file thread to close the file the MHTML was saved to. | 78 // Called on the file thread to close the file the MHTML was saved to. |
77 void CloseFile(base::PlatformFile file); | 79 void CloseFile(base::PlatformFile file); |
78 | 80 |
79 // Called on the UI thread when a job has been processed (successfully or | 81 // Called on the UI thread when a job has been processed (successfully or |
80 // not). Closes the file and removes the job from the job map. | 82 // not). Closes the file and removes the job from the job map. |
81 // |mhtml_data_size| is -1 if the MHTML generation failed. | 83 // |mhtml_data_size| is -1 if the MHTML generation failed. |
82 void JobFinished(int job_id, int64 mhtml_data_size); | 84 void JobFinished(int job_id, int64 mhtml_data_size); |
83 | 85 |
84 typedef std::map<int, Job> IDToJobMap; | 86 typedef std::map<int, Job> IDToJobMap; |
85 IDToJobMap id_to_job_; | 87 IDToJobMap id_to_job_; |
86 | 88 |
87 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 89 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
88 }; | 90 }; |
89 | 91 |
90 } // namespace content | 92 } // namespace content |
91 | 93 |
92 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 94 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
OLD | NEW |