OLD | NEW |
1 // Copyright (c) 2011 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 #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" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
(...skipping 29 matching lines...) Expand all Loading... |
41 WebContents* web_contents, | 41 WebContents* web_contents, |
42 const FilePath& file, | 42 const FilePath& file, |
43 const GenerateMHTMLCallback& callback) { | 43 const GenerateMHTMLCallback& callback) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 static int id_counter = 0; | 45 static int id_counter = 0; |
46 | 46 |
47 int job_id = id_counter++; | 47 int job_id = id_counter++; |
48 Job job; | 48 Job job; |
49 job.file_path = file; | 49 job.file_path = file; |
50 job.process_id = web_contents->GetRenderProcessHost()->GetID(); | 50 job.process_id = web_contents->GetRenderProcessHost()->GetID(); |
51 job.routing_id = web_contents->GetRenderViewHost()->routing_id(); | 51 job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
52 job.callback = callback; | 52 job.callback = callback; |
53 id_to_job_[job_id] = job; | 53 id_to_job_[job_id] = job; |
54 | 54 |
55 base::ProcessHandle renderer_process = | 55 base::ProcessHandle renderer_process = |
56 web_contents->GetRenderProcessHost()->GetHandle(); | 56 web_contents->GetRenderProcessHost()->GetHandle(); |
57 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 57 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
58 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), | 58 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), |
59 job_id, file, renderer_process)); | 59 job_id, file, renderer_process)); |
60 } | 60 } |
61 | 61 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 96 IDToJobMap::iterator iter = id_to_job_.find(job_id); |
97 if (iter == id_to_job_.end()) { | 97 if (iter == id_to_job_.end()) { |
98 NOTREACHED(); | 98 NOTREACHED(); |
99 return; | 99 return; |
100 } | 100 } |
101 | 101 |
102 Job& job = iter->second; | 102 Job& job = iter->second; |
103 job.browser_file = browser_file; | 103 job.browser_file = browser_file; |
104 job.renderer_file = renderer_file; | 104 job.renderer_file = renderer_file; |
105 | 105 |
106 RenderViewHost* rvh = RenderViewHost::FromID(job.process_id, job.routing_id); | 106 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( |
| 107 job.process_id, job.routing_id); |
107 if (!rvh) { | 108 if (!rvh) { |
108 // The tab went away. | 109 // The tab went away. |
109 JobFinished(job_id, -1); | 110 JobFinished(job_id, -1); |
110 return; | 111 return; |
111 } | 112 } |
112 | 113 |
113 rvh->Send(new ViewMsg_SavePageAsMHTML(rvh->routing_id(), job_id, | 114 rvh->Send(new ViewMsg_SavePageAsMHTML(rvh->GetRoutingID(), job_id, |
114 renderer_file)); | 115 renderer_file)); |
115 } | 116 } |
116 | 117 |
117 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { | 118 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { |
118 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 119 IDToJobMap::iterator iter = id_to_job_.find(job_id); |
119 if (iter == id_to_job_.end()) { | 120 if (iter == id_to_job_.end()) { |
120 NOTREACHED(); | 121 NOTREACHED(); |
121 return; | 122 return; |
122 } | 123 } |
123 | 124 |
124 Job& job = iter->second; | 125 Job& job = iter->second; |
125 job.callback.Run(job.file_path, file_size); | 126 job.callback.Run(job.file_path, file_size); |
126 | 127 |
127 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 128 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
128 base::Bind(&MHTMLGenerationManager::CloseFile, base::Unretained(this), | 129 base::Bind(&MHTMLGenerationManager::CloseFile, base::Unretained(this), |
129 job.browser_file)); | 130 job.browser_file)); |
130 | 131 |
131 id_to_job_.erase(job_id); | 132 id_to_job_.erase(job_id); |
132 } | 133 } |
133 | 134 |
134 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 135 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
136 base::ClosePlatformFile(file); | 137 base::ClosePlatformFile(file); |
137 } | 138 } |
OLD | NEW |