Add ICU message format support
[chromium-blink-merge.git] / content / browser / download / mhtml_generation_manager.h
blobbd178cb03d76d4667117affbca50c8dc09025cf1
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_
8 #include <map>
10 #include "base/files/file.h"
11 #include "base/memory/singleton.h"
12 #include "base/process/process.h"
13 #include "ipc/ipc_platform_file.h"
15 namespace base {
16 class FilePath;
19 namespace content {
21 class WebContents;
23 class MHTMLGenerationManager {
24 public:
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 base::File 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);
47 private:
48 friend struct DefaultSingletonTraits<MHTMLGenerationManager>;
49 class Job;
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 receives a handle to that file for the browser process
61 // and one for the renderer process.
62 void FileAvailable(int job_id,
63 base::File browser_file,
64 IPC::PlatformFileForTransit renderer_file);
66 // Called on the file thread to close the file the MHTML was saved to.
67 void CloseFile(base::File file);
69 // Called on the UI thread when a job has been processed (successfully or
70 // not). Closes the file and removes the job from the job map.
71 // |mhtml_data_size| is -1 if the MHTML generation failed.
72 void JobFinished(int job_id, int64 mhtml_data_size);
74 // Creates an register a new job.
75 int NewJob(WebContents* web_contents, const GenerateMHTMLCallback& callback);
77 // Called when the render process connected to a job exits.
78 void RenderProcessExited(Job* job);
80 typedef std::map<int, Job*> IDToJobMap;
81 IDToJobMap id_to_job_;
83 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager);
86 } // namespace content
88 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_