| 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 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 MHTMLGenerationManager::MHTMLGenerationManager() { | 33 MHTMLGenerationManager::MHTMLGenerationManager() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 MHTMLGenerationManager::~MHTMLGenerationManager() { | 36 MHTMLGenerationManager::~MHTMLGenerationManager() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 void MHTMLGenerationManager::GenerateMHTML( | 39 void MHTMLGenerationManager::GenerateMHTML( |
| 40 WebContents* web_contents, | 40 WebContents* web_contents, |
| 41 const FilePath& file, | 41 const base::FilePath& file, |
| 42 const GenerateMHTMLCallback& callback) { | 42 const GenerateMHTMLCallback& callback) { |
| 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 | 53 |
| 54 base::ProcessHandle renderer_process = | 54 base::ProcessHandle renderer_process = |
| 55 web_contents->GetRenderProcessHost()->GetHandle(); | 55 web_contents->GetRenderProcessHost()->GetHandle(); |
| 56 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 56 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 57 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), | 57 base::Bind(&MHTMLGenerationManager::CreateFile, base::Unretained(this), |
| 58 job_id, file, renderer_process)); | 58 job_id, file, renderer_process)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { | 61 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { |
| 62 JobFinished(job_id, mhtml_data_size); | 62 JobFinished(job_id, mhtml_data_size); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void MHTMLGenerationManager::CreateFile( | 65 void MHTMLGenerationManager::CreateFile( |
| 66 int job_id, const FilePath& file_path, | 66 int job_id, const base::FilePath& file_path, |
| 67 base::ProcessHandle renderer_process) { | 67 base::ProcessHandle renderer_process) { |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 69 base::PlatformFile browser_file = base::CreatePlatformFile(file_path, | 69 base::PlatformFile browser_file = base::CreatePlatformFile(file_path, |
| 70 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, | 70 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, |
| 71 NULL, NULL); | 71 NULL, NULL); |
| 72 if (browser_file == base::kInvalidPlatformFileValue) { | 72 if (browser_file == base::kInvalidPlatformFileValue) { |
| 73 LOG(ERROR) << "Failed to create file to save MHTML at: " << | 73 LOG(ERROR) << "Failed to create file to save MHTML at: " << |
| 74 file_path.value(); | 74 file_path.value(); |
| 75 } | 75 } |
| 76 | 76 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 id_to_job_.erase(job_id); | 131 id_to_job_.erase(job_id); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { | 134 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 136 base::ClosePlatformFile(file); | 136 base::ClosePlatformFile(file); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace content | 139 } // namespace content |
| OLD | NEW |