| 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 "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" | 5 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 OnAnalyzeZipFileFinished(zip_analyzer::Results()); | 105 OnAnalyzeZipFileFinished(zip_analyzer::Results()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void SandboxedZipAnalyzer::OnProcessLaunchFailed() { | 108 void SandboxedZipAnalyzer::OnProcessLaunchFailed() { |
| 109 OnAnalyzeZipFileFinished(zip_analyzer::Results()); | 109 OnAnalyzeZipFileFinished(zip_analyzer::Results()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool SandboxedZipAnalyzer::OnMessageReceived(const IPC::Message& message) { | 112 bool SandboxedZipAnalyzer::OnMessageReceived(const IPC::Message& message) { |
| 113 bool handled = true; | 113 bool handled = true; |
| 114 IPC_BEGIN_MESSAGE_MAP(SandboxedZipAnalyzer, message) | 114 IPC_BEGIN_MESSAGE_MAP(SandboxedZipAnalyzer, message) |
| 115 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | |
| 116 OnUtilityProcessStarted) | |
| 117 IPC_MESSAGE_HANDLER( | 115 IPC_MESSAGE_HANDLER( |
| 118 ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished, | 116 ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished, |
| 119 OnAnalyzeZipFileFinished) | 117 OnAnalyzeZipFileFinished) |
| 120 IPC_MESSAGE_UNHANDLED(handled = false) | 118 IPC_MESSAGE_UNHANDLED(handled = false) |
| 121 IPC_END_MESSAGE_MAP() | 119 IPC_END_MESSAGE_MAP() |
| 122 return handled; | 120 return handled; |
| 123 } | 121 } |
| 124 | 122 |
| 125 void SandboxedZipAnalyzer::StartProcessOnIOThread() { | 123 void SandboxedZipAnalyzer::StartProcessOnIOThread() { |
| 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 127 utility_process_host_ = content::UtilityProcessHost::Create( | 125 utility_process_host_ = content::UtilityProcessHost::Create( |
| 128 this, | 126 this, |
| 129 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get()) | 127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get()) |
| 130 ->AsWeakPtr(); | 128 ->AsWeakPtr(); |
| 131 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 129 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
| 132 IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME)); | 130 IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME)); |
| 133 utility_process_host_->Send(new ChromeUtilityMsg_StartupPing); | |
| 134 // Wait for the startup notification before sending the main IPC to the | |
| 135 // utility process, so that we can dup the file handle. | |
| 136 } | |
| 137 | |
| 138 void SandboxedZipAnalyzer::OnUtilityProcessStarted() { | |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 140 utility_process_host_->Send( | 131 utility_process_host_->Send( |
| 141 new ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection( | 132 new ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection( |
| 142 IPC::TakePlatformFileForTransit(std::move(zip_file_)), | 133 IPC::TakePlatformFileForTransit(std::move(zip_file_)), |
| 143 IPC::GetPlatformFileForTransit(temp_file_.GetPlatformFile(), | 134 IPC::GetPlatformFileForTransit(temp_file_.GetPlatformFile(), |
| 144 false /* !close_source_handle */))); | 135 false /* !close_source_handle */))); |
| 145 } | 136 } |
| 146 | 137 |
| 147 void SandboxedZipAnalyzer::OnAnalyzeZipFileFinished( | 138 void SandboxedZipAnalyzer::OnAnalyzeZipFileFinished( |
| 148 const zip_analyzer::Results& results) { | 139 const zip_analyzer::Results& results) { |
| 149 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 150 if (callback_called_) | 141 if (callback_called_) |
| 151 return; | 142 return; |
| 152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 153 base::Bind(callback_, results)); | 144 base::Bind(callback_, results)); |
| 154 callback_called_ = true; | 145 callback_called_ = true; |
| 155 CloseTemporaryFile(); | 146 CloseTemporaryFile(); |
| 156 } | 147 } |
| 157 | 148 |
| 158 } // namespace safe_browsing | 149 } // namespace safe_browsing |
| OLD | NEW |