| 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 | |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 4 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 5 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| 7 | 6 |
| 8 #include <stdint.h> | 7 #include <stdint.h> |
| 9 | 8 |
| 10 #include <map> | 9 #include <map> |
| 11 #include <set> | 10 #include <set> |
| 12 #include <string> | 11 #include <string> |
| 13 | 12 |
| 14 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 17 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "content/public/common/mhtml_generation_params.h" |
| 18 #include "ipc/ipc_platform_file.h" | 18 #include "ipc/ipc_platform_file.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class FilePath; | 21 class FilePath; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 | 25 |
| 26 class RenderFrameHostImpl; | 26 class RenderFrameHostImpl; |
| 27 class WebContents; | 27 class WebContents; |
| 28 | 28 |
| 29 // The class and all of its members live on the UI thread. Only static methods | 29 // The class and all of its members live on the UI thread. Only static methods |
| 30 // are executed on other threads. | 30 // are executed on other threads. |
| 31 class MHTMLGenerationManager { | 31 class MHTMLGenerationManager { |
| 32 public: | 32 public: |
| 33 static MHTMLGenerationManager* GetInstance(); | 33 static MHTMLGenerationManager* GetInstance(); |
| 34 | 34 |
| 35 // GenerateMHTMLCallback is called to report completion and status of MHTML | 35 // GenerateMHTMLCallback is called to report completion and status of MHTML |
| 36 // generation. On success |file_size| indicates the size of the | 36 // generation. On success |file_size| indicates the size of the |
| 37 // generated file. On failure |file_size| is -1. | 37 // generated file. On failure |file_size| is -1. |
| 38 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; | 38 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; |
| 39 | 39 |
| 40 // Instructs the render view to generate a MHTML representation of the current | 40 // Instructs the render view to generate a MHTML representation of the current |
| 41 // page for |web_contents|. | 41 // page for |web_contents|. |
| 42 void SaveMHTML(WebContents* web_contents, | 42 void SaveMHTML(WebContents* web_contents, |
| 43 bool use_binary_encoding, | 43 const MHTMLGenerationParams& params, |
| 44 const base::FilePath& file_path, | |
| 45 const GenerateMHTMLCallback& callback); | 44 const GenerateMHTMLCallback& callback); |
| 46 | 45 |
| 47 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the | 46 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the |
| 48 // renderer that the MHTML generation finished for a single frame). | 47 // renderer that the MHTML generation finished for a single frame). |
| 49 void OnSerializeAsMHTMLResponse( | 48 void OnSerializeAsMHTMLResponse( |
| 50 RenderFrameHostImpl* sender, | 49 RenderFrameHostImpl* sender, |
| 51 int job_id, | 50 int job_id, |
| 52 bool mhtml_generation_in_renderer_succeeded, | 51 bool mhtml_generation_in_renderer_succeeded, |
| 53 const std::set<std::string>& digests_of_uris_of_serialized_resources); | 52 const std::set<std::string>& digests_of_uris_of_serialized_resources); |
| 54 | 53 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 void OnFileAvailable(int job_id, base::File browser_file); | 67 void OnFileAvailable(int job_id, base::File browser_file); |
| 69 | 68 |
| 70 // Called on the UI thread when a job has been finished. | 69 // Called on the UI thread when a job has been finished. |
| 71 void JobFinished(Job* job, JobStatus job_status); | 70 void JobFinished(Job* job, JobStatus job_status); |
| 72 | 71 |
| 73 // Called on the UI thread after the file got finalized and we have its size. | 72 // Called on the UI thread after the file got finalized and we have its size. |
| 74 void OnFileClosed(int job_id, JobStatus job_status, int64_t file_size); | 73 void OnFileClosed(int job_id, JobStatus job_status, int64_t file_size); |
| 75 | 74 |
| 76 // Creates and registers a new job. | 75 // Creates and registers a new job. |
| 77 int NewJob(WebContents* web_contents, | 76 int NewJob(WebContents* web_contents, |
| 78 bool use_binary_encoding, | 77 const MHTMLGenerationParams& params, |
| 79 const GenerateMHTMLCallback& callback); | 78 const GenerateMHTMLCallback& callback); |
| 80 | 79 |
| 81 // Finds job by id. Returns nullptr if no job with a given id was found. | 80 // Finds job by id. Returns nullptr if no job with a given id was found. |
| 82 Job* FindJob(int job_id); | 81 Job* FindJob(int job_id); |
| 83 | 82 |
| 84 // Called when the render process connected to a job exits. | 83 // Called when the render process connected to a job exits. |
| 85 void RenderProcessExited(Job* job); | 84 void RenderProcessExited(Job* job); |
| 86 | 85 |
| 87 typedef std::map<int, Job*> IDToJobMap; | 86 typedef std::map<int, Job*> IDToJobMap; |
| 88 IDToJobMap id_to_job_; | 87 IDToJobMap id_to_job_; |
| 89 | 88 |
| 90 int next_job_id_; | 89 int next_job_id_; |
| 91 | 90 |
| 92 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 91 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 } // namespace content | 94 } // namespace content |
| 96 | 95 |
| 97 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 96 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| OLD | NEW |