| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> |
| 12 #include <string> |
| 11 | 13 |
| 12 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 15 #include "base/process/process.h" | 17 #include "base/process/process.h" |
| 16 #include "ipc/ipc_platform_file.h" | 18 #include "ipc/ipc_platform_file.h" |
| 19 #include "url/gurl.h" |
| 17 | 20 |
| 18 namespace base { | 21 namespace base { |
| 19 class FilePath; | 22 class FilePath; |
| 20 } | 23 } |
| 21 | 24 |
| 22 namespace content { | 25 namespace content { |
| 23 | 26 |
| 27 class RenderFrameHostImpl; |
| 24 class WebContents; | 28 class WebContents; |
| 25 | 29 |
| 26 // The class and all of its members live on the UI thread. Only static methods | 30 // The class and all of its members live on the UI thread. Only static methods |
| 27 // are executed on other threads. | 31 // are executed on other threads. |
| 28 class MHTMLGenerationManager { | 32 class MHTMLGenerationManager { |
| 29 public: | 33 public: |
| 30 static MHTMLGenerationManager* GetInstance(); | 34 static MHTMLGenerationManager* GetInstance(); |
| 31 | 35 |
| 32 // GenerateMHTMLCallback is called to report completion and status of MHTML | 36 // GenerateMHTMLCallback is called to report completion and status of MHTML |
| 33 // generation. On success |file_size| indicates the size of the | 37 // generation. On success |file_size| indicates the size of the |
| 34 // generated file. On failure |file_size| is -1. | 38 // generated file. On failure |file_size| is -1. |
| 35 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; | 39 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; |
| 36 | 40 |
| 37 // Instructs the render view to generate a MHTML representation of the current | 41 // Instructs the render view to generate a MHTML representation of the current |
| 38 // page for |web_contents|. | 42 // page for |web_contents|. |
| 39 void SaveMHTML(WebContents* web_contents, | 43 void SaveMHTML(WebContents* web_contents, |
| 40 const base::FilePath& file_path, | 44 const base::FilePath& file_path, |
| 41 const GenerateMHTMLCallback& callback); | 45 const GenerateMHTMLCallback& callback); |
| 42 | 46 |
| 43 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the | 47 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the |
| 44 // renderer that the MHTML generation finished for a single frame). | 48 // renderer that the MHTML generation finished for a single frame). |
| 45 void OnSavedFrameAsMHTML(int job_id, | 49 void OnSerializeAsMHTMLResponse( |
| 46 bool mhtml_generation_in_renderer_succeeded); | 50 RenderFrameHostImpl* sender, |
| 51 int job_id, |
| 52 bool mhtml_generation_in_renderer_succeeded, |
| 53 const std::set<std::string>& digests_of_uris_of_serialized_resources); |
| 47 | 54 |
| 48 private: | 55 private: |
| 49 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>; | 56 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>; |
| 50 class Job; | 57 class Job; |
| 51 enum class JobStatus { SUCCESS, FAILURE }; | 58 enum class JobStatus { SUCCESS, FAILURE }; |
| 52 | 59 |
| 53 MHTMLGenerationManager(); | 60 MHTMLGenerationManager(); |
| 54 virtual ~MHTMLGenerationManager(); | 61 virtual ~MHTMLGenerationManager(); |
| 55 | 62 |
| 56 // Called on the file thread to create |file|. | 63 // Called on the file thread to create |file|. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 79 IDToJobMap id_to_job_; | 86 IDToJobMap id_to_job_; |
| 80 | 87 |
| 81 int next_job_id_; | 88 int next_job_id_; |
| 82 | 89 |
| 83 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 90 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
| 84 }; | 91 }; |
| 85 | 92 |
| 86 } // namespace content | 93 } // namespace content |
| 87 | 94 |
| 88 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 95 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
| OLD | NEW |