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 24 matching lines...) Expand all Loading... |
35 void MHTMLGenerationManager::GenerateMHTML(WebContents* web_contents, | 35 void MHTMLGenerationManager::GenerateMHTML(WebContents* web_contents, |
36 const FilePath& file, | 36 const FilePath& file, |
37 const GenerateMHTMLCallback& callback) { | 37 const GenerateMHTMLCallback& callback) { |
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
39 static int id_counter = 0; | 39 static int id_counter = 0; |
40 | 40 |
41 int job_id = id_counter++; | 41 int job_id = id_counter++; |
42 Job job; | 42 Job job; |
43 job.file_path = file; | 43 job.file_path = file; |
44 job.process_id = web_contents->GetRenderProcessHost()->GetID(); | 44 job.process_id = web_contents->GetRenderProcessHost()->GetID(); |
45 job.routing_id = web_contents->GetRenderViewHost()->routing_id(); | 45 job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
46 job.callback = callback; | 46 job.callback = callback; |
47 id_to_job_[job_id] = job; | 47 id_to_job_[job_id] = job; |
48 | 48 |
49 base::ProcessHandle renderer_process = | 49 base::ProcessHandle renderer_process = |
50 web_contents->GetRenderProcessHost()->GetHandle(); | 50 web_contents->GetRenderProcessHost()->GetHandle(); |
51 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 51 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
52 base::Bind(&MHTMLGenerationManager::CreateFile, this, | 52 base::Bind(&MHTMLGenerationManager::CreateFile, this, |
53 job_id, file, renderer_process)); | 53 job_id, file, renderer_process)); |
54 } | 54 } |
55 | 55 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 89 IDToJobMap::iterator iter = id_to_job_.find(job_id); |
90 if (iter == id_to_job_.end()) { | 90 if (iter == id_to_job_.end()) { |
91 NOTREACHED(); | 91 NOTREACHED(); |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 Job& job = iter->second; | 95 Job& job = iter->second; |
96 job.browser_file = browser_file; | 96 job.browser_file = browser_file; |
97 job.renderer_file = renderer_file; | 97 job.renderer_file = renderer_file; |
98 | 98 |
99 RenderViewHost* rvh = RenderViewHost::FromID(job.process_id, job.routing_id); | 99 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( |
| 100 job.process_id, job.routing_id); |
100 if (!rvh) { | 101 if (!rvh) { |
101 // The tab went away. | 102 // The tab went away. |
102 JobFinished(job_id, -1); | 103 JobFinished(job_id, -1); |
103 return; | 104 return; |
104 } | 105 } |
105 | 106 |
106 rvh->Send(new ViewMsg_SavePageAsMHTML(rvh->routing_id(), job_id, | 107 rvh->Send(new ViewMsg_SavePageAsMHTML(rvh->GetRoutingID(), job_id, |
107 renderer_file)); | 108 renderer_file)); |
108 } | 109 } |
109 | 110 |
110 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { | 111 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { |
111 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 112 IDToJobMap::iterator iter = id_to_job_.find(job_id); |
112 if (iter == id_to_job_.end()) { | 113 if (iter == id_to_job_.end()) { |
113 NOTREACHED(); | 114 NOTREACHED(); |
114 return; | 115 return; |
115 } | 116 } |
116 | 117 |
117 Job& job = iter->second; | 118 Job& job = iter->second; |
118 job.callback.Run(job.file_path, file_size); | 119 job.callback.Run(job.file_path, file_size); |
119 | 120 |
120 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 121 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
121 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); | 122 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); |
122 | 123 |
123 id_to_job_.erase(job_id); | 124 id_to_job_.erase(job_id); |
124 } | 125 } |
125 | 126 |
126 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 127 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
128 base::ClosePlatformFile(file); | 129 base::ClosePlatformFile(file); |
129 } | 130 } |
OLD | NEW |