| 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" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | |
| 12 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 using content::WebContents; |
| 17 | 18 |
| 18 MHTMLGenerationManager::Job::Job() | 19 MHTMLGenerationManager::Job::Job() |
| 19 : browser_file(base::kInvalidPlatformFileValue), | 20 : browser_file(base::kInvalidPlatformFileValue), |
| 20 renderer_file(IPC::InvalidPlatformFileForTransit()), | 21 renderer_file(IPC::InvalidPlatformFileForTransit()), |
| 21 process_id(-1), | 22 process_id(-1), |
| 22 routing_id(-1) { | 23 routing_id(-1) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 MHTMLGenerationManager::Job::~Job() { | 26 MHTMLGenerationManager::Job::~Job() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 MHTMLGenerationManager::MHTMLGenerationManager() { | 29 MHTMLGenerationManager::MHTMLGenerationManager() { |
| 29 } | 30 } |
| 30 | 31 |
| 31 MHTMLGenerationManager::~MHTMLGenerationManager() { | 32 MHTMLGenerationManager::~MHTMLGenerationManager() { |
| 32 } | 33 } |
| 33 | 34 |
| 34 void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents, | 35 void MHTMLGenerationManager::GenerateMHTML(WebContents* web_contents, |
| 35 const FilePath& file, | 36 const FilePath& file, |
| 36 const GenerateMHTMLCallback& callback) { | 37 const GenerateMHTMLCallback& callback) { |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 static int id_counter = 0; | 39 static int id_counter = 0; |
| 39 | 40 |
| 40 int job_id = id_counter++; | 41 int job_id = id_counter++; |
| 41 Job job; | 42 Job job; |
| 42 job.file_path = file; | 43 job.file_path = file; |
| 43 job.process_id = tab_contents->GetRenderProcessHost()->GetID(); | 44 job.process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 44 job.routing_id = tab_contents->GetRenderViewHost()->routing_id(); | 45 job.routing_id = web_contents->GetRenderViewHost()->routing_id(); |
| 45 job.callback = callback; | 46 job.callback = callback; |
| 46 id_to_job_[job_id] = job; | 47 id_to_job_[job_id] = job; |
| 47 | 48 |
| 48 base::ProcessHandle renderer_process = | 49 base::ProcessHandle renderer_process = |
| 49 tab_contents->GetRenderProcessHost()->GetHandle(); | 50 web_contents->GetRenderProcessHost()->GetHandle(); |
| 50 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 51 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 51 base::Bind(&MHTMLGenerationManager::CreateFile, this, | 52 base::Bind(&MHTMLGenerationManager::CreateFile, this, |
| 52 job_id, file, renderer_process)); | 53 job_id, file, renderer_process)); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { | 56 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { |
| 56 JobFinished(job_id, mhtml_data_size); | 57 JobFinished(job_id, mhtml_data_size); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void MHTMLGenerationManager::CreateFile(int job_id, const FilePath& file_path, | 60 void MHTMLGenerationManager::CreateFile(int job_id, const FilePath& file_path, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 120 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 120 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); | 121 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); |
| 121 | 122 |
| 122 id_to_job_.erase(job_id); | 123 id_to_job_.erase(job_id); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 126 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 127 base::ClosePlatformFile(file); | 128 base::ClosePlatformFile(file); |
| 128 } | 129 } |
| OLD | NEW |