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> |
| 9 |
8 #include <map> | 10 #include <map> |
9 | 11 |
10 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/macros.h" |
11 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
12 #include "base/process/process.h" | 15 #include "base/process/process.h" |
13 #include "ipc/ipc_platform_file.h" | 16 #include "ipc/ipc_platform_file.h" |
14 | 17 |
15 namespace base { | 18 namespace base { |
16 class FilePath; | 19 class FilePath; |
17 } | 20 } |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 | 23 |
21 class WebContents; | 24 class WebContents; |
22 | 25 |
23 // The class and all of its members live on the UI thread. Only static methods | 26 // The class and all of its members live on the UI thread. Only static methods |
24 // are executed on other threads. | 27 // are executed on other threads. |
25 class MHTMLGenerationManager { | 28 class MHTMLGenerationManager { |
26 public: | 29 public: |
27 static MHTMLGenerationManager* GetInstance(); | 30 static MHTMLGenerationManager* GetInstance(); |
28 | 31 |
29 // GenerateMHTMLCallback is called to report completion and status of MHTML | 32 // GenerateMHTMLCallback is called to report completion and status of MHTML |
30 // generation. On success |file_size| indicates the size of the | 33 // generation. On success |file_size| indicates the size of the |
31 // generated file. On failure |file_size| is -1. | 34 // generated file. On failure |file_size| is -1. |
32 typedef base::Callback<void(int64 file_size)> GenerateMHTMLCallback; | 35 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; |
33 | 36 |
34 // Instructs the render view to generate a MHTML representation of the current | 37 // Instructs the render view to generate a MHTML representation of the current |
35 // page for |web_contents|. | 38 // page for |web_contents|. |
36 void SaveMHTML(WebContents* web_contents, | 39 void SaveMHTML(WebContents* web_contents, |
37 const base::FilePath& file_path, | 40 const base::FilePath& file_path, |
38 const GenerateMHTMLCallback& callback); | 41 const GenerateMHTMLCallback& callback); |
39 | 42 |
40 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the | 43 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the |
41 // renderer that the MHTML generation finished for a single frame). | 44 // renderer that the MHTML generation finished for a single frame). |
42 void OnSavedFrameAsMHTML(int job_id, | 45 void OnSavedFrameAsMHTML(int job_id, |
(...skipping 11 matching lines...) Expand all Loading... |
54 static base::File CreateFile(const base::FilePath& file_path); | 57 static base::File CreateFile(const base::FilePath& file_path); |
55 | 58 |
56 // Called on the UI thread when the file that should hold the MHTML data has | 59 // Called on the UI thread when the file that should hold the MHTML data has |
57 // been created. | 60 // been created. |
58 void OnFileAvailable(int job_id, base::File browser_file); | 61 void OnFileAvailable(int job_id, base::File browser_file); |
59 | 62 |
60 // Called on the UI thread when a job has been finished. | 63 // Called on the UI thread when a job has been finished. |
61 void JobFinished(int job_id, JobStatus job_status); | 64 void JobFinished(int job_id, JobStatus job_status); |
62 | 65 |
63 // Called on the UI thread after the file got finalized and we have its size. | 66 // Called on the UI thread after the file got finalized and we have its size. |
64 void OnFileClosed(int job_id, JobStatus job_status, int64 file_size); | 67 void OnFileClosed(int job_id, JobStatus job_status, int64_t file_size); |
65 | 68 |
66 // Creates and registers a new job. | 69 // Creates and registers a new job. |
67 int NewJob(WebContents* web_contents, const GenerateMHTMLCallback& callback); | 70 int NewJob(WebContents* web_contents, const GenerateMHTMLCallback& callback); |
68 | 71 |
69 // Finds job by id. Returns nullptr if no job with a given id was found. | 72 // Finds job by id. Returns nullptr if no job with a given id was found. |
70 Job* FindJob(int job_id); | 73 Job* FindJob(int job_id); |
71 | 74 |
72 // Called when the render process connected to a job exits. | 75 // Called when the render process connected to a job exits. |
73 void RenderProcessExited(Job* job); | 76 void RenderProcessExited(Job* job); |
74 | 77 |
75 typedef std::map<int, Job*> IDToJobMap; | 78 typedef std::map<int, Job*> IDToJobMap; |
76 IDToJobMap id_to_job_; | 79 IDToJobMap id_to_job_; |
77 | 80 |
78 int next_job_id_; | 81 int next_job_id_; |
79 | 82 |
80 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); | 83 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); |
81 }; | 84 }; |
82 | 85 |
83 } // namespace content | 86 } // namespace content |
84 | 87 |
85 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ | 88 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ |
OLD | NEW |