Chromium Code Reviews| 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, |
| 33 const GenerateMHTMLCallback& callback); | 35 const GenerateMHTMLCallback& callback); |
| 34 | 36 |
| 35 // Notification from the renderer that the MHTML generation finished. | 37 // Notification from the renderer that the MHTML generation finished. |
| 36 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, | 38 // |mhtml_data_size| contains the size in bytes of the generated MHTML data, |
| 37 // or -1 in case of failure. | 39 // or -1 in case of failure. |
| 38 void MHTMLGenerated(int job_id, int64 mhtml_data_size); | 40 void MHTMLGenerated(int job_id, int64 mhtml_data_size); |
| 39 | 41 |
| 42 // Implementation of NotificationObserver. | |
|
Jay Civelli
2013/08/01 17:57:00
Nit: could be moved to the private section.
qsr
2013/08/02 14:22:24
Done.
| |
| 43 virtual void Observe(int type, | |
| 44 const NotificationSource& source, | |
| 45 const NotificationDetails& details) OVERRIDE; | |
| 46 | |
| 40 private: | 47 private: |
| 41 friend struct DefaultSingletonTraits<MHTMLGenerationManager>; | 48 friend struct DefaultSingletonTraits<MHTMLGenerationManager>; |
| 42 | 49 |
| 43 struct Job{ | 50 struct Job{ |
| 44 Job(); | 51 Job(); |
| 45 ~Job(); | 52 ~Job(); |
| 46 | 53 |
| 47 base::FilePath file_path; | 54 base::FilePath file_path; |
| 48 | 55 |
| 49 // The handles to file the MHTML is saved to, for the browser and renderer | 56 // The handles to file the MHTML is saved to, for the browser and renderer |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 78 // Called on the file thread to close the file the MHTML was saved to. | 85 // Called on the file thread to close the file the MHTML was saved to. |
| 79 void CloseFile(base::PlatformFile file); | 86 void CloseFile(base::PlatformFile file); |
| 80 | 87 |
| 81 // Called on the UI thread when a job has been processed (successfully or | 88 // 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. | 89 // not). Closes the file and removes the job from the job map. |
| 83 // |mhtml_data_size| is -1 if the MHTML generation failed. | 90 // |mhtml_data_size| is -1 if the MHTML generation failed. |
| 84 void JobFinished(int job_id, int64 mhtml_data_size); | 91 void JobFinished(int job_id, int64 mhtml_data_size); |
| 85 | 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 |