OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "content/browser/download/mhtml_generation_manager.h" | 5 #include "content/browser/download/mhtml_generation_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "content/browser/renderer_host/render_process_host_impl.h" | 9 #include "content/browser/renderer_host/render_process_host_impl.h" |
10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 routing_id(-1) { | 22 routing_id(-1) { |
23 } | 23 } |
24 | 24 |
25 MHTMLGenerationManager::MHTMLGenerationManager() { | 25 MHTMLGenerationManager::MHTMLGenerationManager() { |
26 } | 26 } |
27 | 27 |
28 MHTMLGenerationManager::~MHTMLGenerationManager() { | 28 MHTMLGenerationManager::~MHTMLGenerationManager() { |
29 } | 29 } |
30 | 30 |
31 void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents, | 31 void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents, |
32 const FilePath& file) { | 32 const FilePath& file, |
| 33 const GenerateMHTMLCallback& callback) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 static int id_counter = 0; | 35 static int id_counter = 0; |
35 | 36 |
36 int job_id = id_counter++; | 37 int job_id = id_counter++; |
37 Job job; | 38 Job job; |
38 job.file_path = file; | 39 job.file_path = file; |
39 job.process_id = tab_contents->GetRenderProcessHost()->GetID(); | 40 job.process_id = tab_contents->GetRenderProcessHost()->GetID(); |
40 job.routing_id = tab_contents->render_view_host()->routing_id(); | 41 job.routing_id = tab_contents->render_view_host()->routing_id(); |
| 42 job.callback = callback; |
41 id_to_job_[job_id] = job; | 43 id_to_job_[job_id] = job; |
42 | 44 |
43 base::ProcessHandle renderer_process = | 45 base::ProcessHandle renderer_process = |
44 tab_contents->GetRenderProcessHost()->GetHandle(); | 46 tab_contents->GetRenderProcessHost()->GetHandle(); |
45 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 47 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
46 base::Bind(&MHTMLGenerationManager::CreateFile, this, | 48 base::Bind(&MHTMLGenerationManager::CreateFile, this, |
47 job_id, file, renderer_process)); | 49 job_id, file, renderer_process)); |
48 } | 50 } |
49 | 51 |
50 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { | 52 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 104 } |
103 | 105 |
104 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { | 106 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { |
105 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 107 IDToJobMap::iterator iter = id_to_job_.find(job_id); |
106 if (iter == id_to_job_.end()) { | 108 if (iter == id_to_job_.end()) { |
107 NOTREACHED(); | 109 NOTREACHED(); |
108 return; | 110 return; |
109 } | 111 } |
110 | 112 |
111 Job& job = iter->second; | 113 Job& job = iter->second; |
112 | 114 job.callback.Run(job.file_path, file_size); |
113 RenderViewHost* rvh = RenderViewHost::FromID(job.process_id, job.routing_id); | |
114 if (rvh) { | |
115 NotificationDetails details; | |
116 details.file_path = job.file_path; | |
117 details.file_size = file_size; | |
118 | |
119 content::NotificationService::current()->Notify( | |
120 content::NOTIFICATION_MHTML_GENERATED, | |
121 content::Source<RenderViewHost>(rvh), | |
122 content::Details<NotificationDetails>(&details)); | |
123 } | |
124 | 115 |
125 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 116 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
126 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); | 117 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); |
127 | 118 |
128 id_to_job_.erase(job_id); | 119 id_to_job_.erase(job_id); |
129 } | 120 } |
130 | 121 |
131 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 122 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
133 base::ClosePlatformFile(file); | 124 base::ClosePlatformFile(file); |
134 } | 125 } |
OLD | NEW |