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); |
63 } | 72 } |
64 | 73 |
74 void MHTMLGenerationManager::Observe(int type, | |
75 const NotificationSource& source, | |
76 const NotificationDetails& details) { | |
77 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); | |
78 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); | |
79 std::set<int> job_to_delete; | |
80 for (IDToJobMap::iterator it = id_to_job_.begin(); it != id_to_job_.end(); | |
81 ++it) { | |
82 if (it->second.process_id == host->GetID()) | |
83 job_to_delete.insert(it->first); | |
84 } | |
85 for (std::set<int>::iterator it = job_to_delete.begin(); | |
86 it != job_to_delete.end(); | |
87 ++it) { | |
88 JobFinished(*it, -1); | |
89 } | |
90 } | |
Jay Civelli
2013/08/01 17:57:00
Shouldn't we unregister for notifications for that
qsr
2013/08/02 14:22:24
Done.
| |
91 | |
65 void MHTMLGenerationManager::CreateFile( | 92 void MHTMLGenerationManager::CreateFile( |
66 int job_id, const base::FilePath& file_path, | 93 int job_id, const base::FilePath& file_path, |
67 base::ProcessHandle renderer_process) { | 94 base::ProcessHandle renderer_process) { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
69 base::PlatformFile browser_file = base::CreatePlatformFile(file_path, | 96 base::PlatformFile browser_file = base::CreatePlatformFile(file_path, |
70 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, | 97 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, |
71 NULL, NULL); | 98 NULL, NULL); |
72 if (browser_file == base::kInvalidPlatformFileValue) { | 99 if (browser_file == base::kInvalidPlatformFileValue) { |
73 LOG(ERROR) << "Failed to create file to save MHTML at: " << | 100 LOG(ERROR) << "Failed to create file to save MHTML at: " << |
74 file_path.value(); | 101 file_path.value(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 157 |
131 id_to_job_.erase(job_id); | 158 id_to_job_.erase(job_id); |
132 } | 159 } |
133 | 160 |
134 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 161 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
136 base::ClosePlatformFile(file); | 163 base::ClosePlatformFile(file); |
137 } | 164 } |
138 | 165 |
139 } // namespace content | 166 } // namespace content |
OLD | NEW |