Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/platform_file.h" | |
| 12 #include "base/process.h" | |
| 13 #include "content/browser/browser_thread.h" | |
| 14 | |
| 15 class FilePath; | |
| 16 class TabContents; | |
| 17 | |
| 18 class MHTMLGenerationManager | |
| 19 : public base::RefCountedThreadSafe<MHTMLGenerationManager, | |
| 20 BrowserThread::DeleteOnUIThread> { | |
|
Randy Smith (Not in Mondays)
2011/06/10 19:49:58
This seems like it's a leak in waiting. If the ge
jam
2011/06/10 20:25:06
this is totally acceptable, and happens in lots of
| |
| 21 public: | |
| 22 MHTMLGenerationManager(); | |
| 23 ~MHTMLGenerationManager(); | |
| 24 | |
| 25 // Instructs the render view to generate a MHTML representation of the current | |
| 26 // page for |tab_contents|. | |
| 27 void GenerateMHTML(TabContents* tab_contents, const FilePath& file); | |
| 28 | |
| 29 // Notification from the renderer that the MHTML generation succeeded/failed. | |
| 30 void MHTMLGenerated(int job_id, bool success); | |
| 31 | |
| 32 // The details sent along with the MHTML_GENERATED notification. | |
| 33 struct NotificationDetails { | |
| 34 FilePath file_path; | |
| 35 bool success; | |
| 36 }; | |
| 37 | |
| 38 private: | |
| 39 struct Job{ | |
| 40 Job(); | |
| 41 | |
| 42 FilePath file_path; | |
| 43 | |
| 44 // The handles to file the MHTML is saved to, for the browser and renderer | |
| 45 // processes. | |
| 46 base::PlatformFile browser_file; | |
| 47 base::PlatformFile renderer_file; | |
| 48 | |
| 49 // The IDs mapping to a specific tab. | |
| 50 int process_id; | |
| 51 int routing_id; | |
| 52 }; | |
| 53 | |
| 54 // Called on the file thread to create |file|. | |
| 55 void CreateFile(int job_id, | |
| 56 const FilePath& file, | |
| 57 base::ProcessHandle renderer_process); | |
| 58 | |
| 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 FileCreated(int job_id, | |
| 64 base::PlatformFile browser_file, | |
| 65 base::PlatformFile renderer_file); | |
| 66 | |
| 67 // Called on the file thread to close the file the MHTML was saved to. | |
| 68 void CloseFile(base::PlatformFile file); | |
| 69 | |
| 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 void JobFinished(int job_id, bool success); | |
| 73 | |
| 74 typedef std::map<int, Job> IDToJobMap; | |
| 75 IDToJobMap id_to_job_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | |
| 78 }; | |
| 79 | |
| 80 #endif // CHROME_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | |
| OLD | NEW |