| 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 #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_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 static int id_counter = 0; | 44 static int id_counter = 0; |
| 45 | 45 |
| 46 int job_id = id_counter++; | 46 int job_id = id_counter++; |
| 47 Job job; | 47 Job job; |
| 48 job.file_path = file; | 48 job.file_path = file; |
| 49 job.process_id = web_contents->GetRenderProcessHost()->GetID(); | 49 job.process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 50 job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 50 job.routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 51 job.callback = callback; | 51 job.callback = callback; |
| 52 id_to_job_[job_id] = job; | 52 id_to_job_[job_id] = job; |
| 53 if (!registrar_.IsRegistered( |
| 54 this, |
| 55 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 56 Source<RenderProcessHost>(web_contents->GetRenderProcessHost()))) { |
| 57 registrar_.Add( |
| 58 this, |
| 59 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 60 Source<RenderProcessHost>(web_contents->GetRenderProcessHost())); |
| 61 } |
| 53 | 62 |
| 54 base::ProcessHandle renderer_process = | 63 base::ProcessHandle renderer_process = |
| 55 web_contents->GetRenderProcessHost()->GetHandle(); | 64 web_contents->GetRenderProcessHost()->GetHandle(); |
| 56 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 65 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 57 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), | 66 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), |
| 58 job_id, file, renderer_process)); | 67 job_id, file, renderer_process)); |
| 59 } | 68 } |
| 60 | 69 |
| 61 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { | 70 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { |
| 62 JobFinished(job_id, mhtml_data_size); | 71 JobFinished(job_id, mhtml_data_size); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 job.browser_file)); | 138 job.browser_file)); |
| 130 | 139 |
| 131 id_to_job_.erase(job_id); | 140 id_to_job_.erase(job_id); |
| 132 } | 141 } |
| 133 | 142 |
| 134 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 143 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 136 base::ClosePlatformFile(file); | 145 base::ClosePlatformFile(file); |
| 137 } | 146 } |
| 138 | 147 |
| 148 void MHTMLGenerationManager::Observe(int type, |
| 149 const NotificationSource& source, |
| 150 const NotificationDetails& details) { |
| 151 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
| 152 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); |
| 153 registrar_.Remove( |
| 154 this, |
| 155 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 156 source); |
| 157 std::set<int> job_to_delete; |
| 158 for (IDToJobMap::iterator it = id_to_job_.begin(); it != id_to_job_.end(); |
| 159 ++it) { |
| 160 if (it->second.process_id == host->GetID()) |
| 161 job_to_delete.insert(it->first); |
| 162 } |
| 163 for (std::set<int>::iterator it = job_to_delete.begin(); |
| 164 it != job_to_delete.end(); |
| 165 ++it) { |
| 166 JobFinished(*it, -1); |
| 167 } |
| 168 } |
| 169 |
| 139 } // namespace content | 170 } // namespace content |
| OLD | NEW |