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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
10 #include "base/memory/singleton.h"
11 #include "base/platform_file.h"
12 #include "base/process/process.h"
13 #include "ipc/ipc_platform_file.h"
23 class MHTMLGenerationManager
{
25 static MHTMLGenerationManager
* GetInstance();
27 typedef base::Callback
<void(int64
/* size of the file */)>
28 GenerateMHTMLCallback
;
30 // Instructs the render view to generate a MHTML representation of the current
31 // page for |web_contents|.
32 void SaveMHTML(WebContents
* web_contents
,
33 const base::FilePath
& file
,
34 const GenerateMHTMLCallback
& callback
);
36 // Instructs the render view to generate a MHTML representation of the current
37 // page for |web_contents|.
38 void StreamMHTML(WebContents
* web_contents
,
39 const base::PlatformFile file
,
40 const GenerateMHTMLCallback
& callback
);
42 // Notification from the renderer that the MHTML generation finished.
43 // |mhtml_data_size| contains the size in bytes of the generated MHTML data,
44 // or -1 in case of failure.
45 void MHTMLGenerated(int job_id
, int64 mhtml_data_size
);
48 friend struct DefaultSingletonTraits
<MHTMLGenerationManager
>;
51 MHTMLGenerationManager();
52 virtual ~MHTMLGenerationManager();
54 // Called on the file thread to create |file|.
55 void CreateFile(int job_id
,
56 const base::FilePath
& file
,
57 base::ProcessHandle renderer_process
);
59 // Called on the UI thread when the file that should hold the MHTML data has
60 // been created. This returns a handle to that file for the browser process
61 // and one for the renderer process. These handles are
62 // kInvalidPlatformFileValue if the file could not be opened.
63 void FileHandleAvailable(int job_id
,
64 base::PlatformFile browser_file
,
65 IPC::PlatformFileForTransit renderer_file
);
67 // Called on the file thread to close the file the MHTML was saved to.
68 void CloseFile(base::PlatformFile file
);
70 // Called on the UI thread when a job has been processed (successfully or
71 // not). Closes the file and removes the job from the job map.
72 // |mhtml_data_size| is -1 if the MHTML generation failed.
73 void JobFinished(int job_id
, int64 mhtml_data_size
);
75 // Creates an register a new job.
76 int NewJob(WebContents
* web_contents
, const GenerateMHTMLCallback
& callback
);
78 // Called when the render process connected to a job exits.
79 void RenderProcessExited(Job
* job
);
81 typedef std::map
<int, Job
> IDToJobMap
;
82 IDToJobMap id_to_job_
;
84 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_