Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: content/browser/download/mhtml_generation_manager.h

Issue 9566001: Hide MHTMLGenerationManager from chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 "content/common/content_export.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "ipc/ipc_platform_file.h" 13 #include "ipc/ipc_platform_file.h"
16 14
17 class FilePath; 15 class FilePath;
18 16
19 namespace content { 17 namespace content {
20 class WebContents; 18 class WebContents;
21 } 19 }
22 20
23 class CONTENT_EXPORT MHTMLGenerationManager 21 class MHTMLGenerationManager {
24 : public base::RefCountedThreadSafe<
25 MHTMLGenerationManager, content::BrowserThread::DeleteOnUIThread> {
26 public: 22 public:
27 MHTMLGenerationManager(); 23 static MHTMLGenerationManager* GetInstance();
28 ~MHTMLGenerationManager();
29 24
30 typedef base::Callback<void(const FilePath& /* path to the MHTML file */, 25 typedef base::Callback<void(const FilePath& /* path to the MHTML file */,
31 int64 /* size of the file */)> GenerateMHTMLCallback; 26 int64 /* size of the file */)> GenerateMHTMLCallback;
32 27
33 // Instructs the render view to generate a MHTML representation of the current 28 // Instructs the render view to generate a MHTML representation of the current
34 // page for |web_contents|. 29 // page for |web_contents|.
35 void GenerateMHTML(content::WebContents* web_contents, 30 void GenerateMHTML(content::WebContents* web_contents,
36 const FilePath& file, 31 const FilePath& file,
37 const GenerateMHTMLCallback& callback); 32 const GenerateMHTMLCallback& callback);
38 33
39 // Notification from the renderer that the MHTML generation finished. 34 // Notification from the renderer that the MHTML generation finished.
40 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, 35 // |mhtml_data_size| contains the size in bytes of the generated MHTML data,
41 // or -1 in case of failure. 36 // or -1 in case of failure.
42 void MHTMLGenerated(int job_id, int64 mhtml_data_size); 37 void MHTMLGenerated(int job_id, int64 mhtml_data_size);
43 38
44 private: 39 private:
40 friend struct DefaultSingletonTraits<MHTMLGenerationManager>;
41
45 struct Job{ 42 struct Job{
46 Job(); 43 Job();
47 ~Job(); 44 ~Job();
48 45
49 FilePath file_path; 46 FilePath file_path;
50 47
51 // 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
52 // processes. 49 // processes.
53 base::PlatformFile browser_file; 50 base::PlatformFile browser_file;
54 IPC::PlatformFileForTransit renderer_file; 51 IPC::PlatformFileForTransit renderer_file;
55 52
56 // The IDs mapping to a specific tab. 53 // The IDs mapping to a specific tab.
57 int process_id; 54 int process_id;
58 int routing_id; 55 int routing_id;
59 56
60 // The callback to call once generation is complete. 57 // The callback to call once generation is complete.
61 GenerateMHTMLCallback callback; 58 GenerateMHTMLCallback callback;
62 }; 59 };
63 60
61 MHTMLGenerationManager();
62 ~MHTMLGenerationManager();
63
64 // Called on the file thread to create |file|. 64 // Called on the file thread to create |file|.
65 void CreateFile(int job_id, 65 void CreateFile(int job_id,
66 const FilePath& file, 66 const FilePath& file,
67 base::ProcessHandle renderer_process); 67 base::ProcessHandle renderer_process);
68 68
69 // Called on the UI thread when the file that should hold the MHTML data has 69 // Called on the UI thread when the file that should hold the MHTML data has
70 // been created. This returns a handle to that file for the browser process 70 // been created. This returns a handle to that file for the browser process
71 // and one for the renderer process. These handles are 71 // and one for the renderer process. These handles are
72 // kInvalidPlatformFileValue if the file could not be opened. 72 // kInvalidPlatformFileValue if the file could not be opened.
73 void FileCreated(int job_id, 73 void FileCreated(int job_id,
74 base::PlatformFile browser_file, 74 base::PlatformFile browser_file,
75 IPC::PlatformFileForTransit renderer_file); 75 IPC::PlatformFileForTransit renderer_file);
76 76
77 // Called on the file thread to close the file the MHTML was saved to. 77 // Called on the file thread to close the file the MHTML was saved to.
78 void CloseFile(base::PlatformFile file); 78 void CloseFile(base::PlatformFile file);
79 79
80 // Called on the UI thread when a job has been processed (successfully or 80 // Called on the UI thread when a job has been processed (successfully or
81 // not). Closes the file and removes the job from the job map. 81 // not). Closes the file and removes the job from the job map.
82 // |mhtml_data_size| is -1 if the MHTML generation failed. 82 // |mhtml_data_size| is -1 if the MHTML generation failed.
83 void JobFinished(int job_id, int64 mhtml_data_size); 83 void JobFinished(int job_id, int64 mhtml_data_size);
84 84
85 typedef std::map<int, Job> IDToJobMap; 85 typedef std::map<int, Job> IDToJobMap;
86 IDToJobMap id_to_job_; 86 IDToJobMap id_to_job_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); 88 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager);
89 }; 89 };
90 90
91 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 91 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698