| 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/process.h" | 12 #include "base/process/process.h" |
| 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" |
| 13 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 class FilePath; | 18 class FilePath; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 class WebContents; | 22 class WebContents; |
| 21 | 23 |
| 22 class MHTMLGenerationManager { | 24 class MHTMLGenerationManager : public NotificationObserver { |
| 23 public: | 25 public: |
| 24 static MHTMLGenerationManager* GetInstance(); | 26 static MHTMLGenerationManager* GetInstance(); |
| 25 | 27 |
| 26 typedef base::Callback<void(const base::FilePath& /* path to the MHTML file */
, | 28 typedef base::Callback<void(const base::FilePath& /* path to the MHTML file */
, |
| 27 int64 /* size of the file */)> GenerateMHTMLCallback; | 29 int64 /* size of the file */)> GenerateMHTMLCallback; |
| 28 | 30 |
| 29 // Instructs the render view to generate a MHTML representation of the current | 31 // Instructs the render view to generate a MHTML representation of the current |
| 30 // page for |web_contents|. | 32 // page for |web_contents|. |
| 31 void GenerateMHTML(WebContents* web_contents, | 33 void GenerateMHTML(WebContents* web_contents, |
| 32 const base::FilePath& file, | 34 const base::FilePath& file, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 | 55 |
| 54 // The IDs mapping to a specific contents. | 56 // The IDs mapping to a specific contents. |
| 55 int process_id; | 57 int process_id; |
| 56 int routing_id; | 58 int routing_id; |
| 57 | 59 |
| 58 // The callback to call once generation is complete. | 60 // The callback to call once generation is complete. |
| 59 GenerateMHTMLCallback callback; | 61 GenerateMHTMLCallback callback; |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 MHTMLGenerationManager(); | 64 MHTMLGenerationManager(); |
| 63 ~MHTMLGenerationManager(); | 65 virtual ~MHTMLGenerationManager(); |
| 64 | 66 |
| 65 // Called on the file thread to create |file|. | 67 // Called on the file thread to create |file|. |
| 66 void CreateFile(int job_id, | 68 void CreateFile(int job_id, |
| 67 const base::FilePath& file, | 69 const base::FilePath& file, |
| 68 base::ProcessHandle renderer_process); | 70 base::ProcessHandle renderer_process); |
| 69 | 71 |
| 70 // Called on the UI thread when the file that should hold the MHTML data has | 72 // Called on the UI thread when the file that should hold the MHTML data has |
| 71 // been created. This returns a handle to that file for the browser process | 73 // been created. This returns a handle to that file for the browser process |
| 72 // and one for the renderer process. These handles are | 74 // and one for the renderer process. These handles are |
| 73 // kInvalidPlatformFileValue if the file could not be opened. | 75 // kInvalidPlatformFileValue if the file could not be opened. |
| 74 void FileCreated(int job_id, | 76 void FileCreated(int job_id, |
| 75 base::PlatformFile browser_file, | 77 base::PlatformFile browser_file, |
| 76 IPC::PlatformFileForTransit renderer_file); | 78 IPC::PlatformFileForTransit renderer_file); |
| 77 | 79 |
| 78 // Called on the file thread to close the file the MHTML was saved to. | 80 // Called on the file thread to close the file the MHTML was saved to. |
| 79 void CloseFile(base::PlatformFile file); | 81 void CloseFile(base::PlatformFile file); |
| 80 | 82 |
| 81 // Called on the UI thread when a job has been processed (successfully or | 83 // Called on the UI thread when a job has been processed (successfully or |
| 82 // not). Closes the file and removes the job from the job map. | 84 // not). Closes the file and removes the job from the job map. |
| 83 // |mhtml_data_size| is -1 if the MHTML generation failed. | 85 // |mhtml_data_size| is -1 if the MHTML generation failed. |
| 84 void JobFinished(int job_id, int64 mhtml_data_size); | 86 void JobFinished(int job_id, int64 mhtml_data_size); |
| 85 | 87 |
| 88 // Implementation of NotificationObserver. |
| 89 virtual void Observe(int type, |
| 90 const NotificationSource& source, |
| 91 const NotificationDetails& details) OVERRIDE; |
| 92 |
| 86 typedef std::map<int, Job> IDToJobMap; | 93 typedef std::map<int, Job> IDToJobMap; |
| 87 IDToJobMap id_to_job_; | 94 IDToJobMap id_to_job_; |
| 95 NotificationRegistrar registrar_; |
| 88 | 96 |
| 89 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 97 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
| 90 }; | 98 }; |
| 91 | 99 |
| 92 } // namespace content | 100 } // namespace content |
| 93 | 101 |
| 94 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 102 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| OLD | NEW |