| Index: chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.cc
|
| diff --git a/chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.cc b/chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.cc
|
| index 23af395e75e44be4b2bf55b3022694a2163f56b2..5668db7b795dddee285feb3be28048de2255548e 100644
|
| --- a/chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.cc
|
| +++ b/chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.cc
|
| @@ -8,96 +8,79 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/task_scheduler/post_task.h"
|
| -#include "chrome/common/chrome_utility_messages.h"
|
| #include "chrome/common/safe_browsing/zip_analyzer_results.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/child_process_data.h"
|
| -#include "content/public/browser/render_process_host.h"
|
| -#include "ipc/ipc_message_macros.h"
|
| -#include "ipc/ipc_platform_file.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| -using content::BrowserThread;
|
| -
|
| namespace safe_browsing {
|
|
|
| SandboxedDMGAnalyzer::SandboxedDMGAnalyzer(const base::FilePath& dmg_file,
|
| - const ResultsCallback& callback)
|
| - : file_path_(dmg_file), callback_(callback), callback_called_(false) {
|
| + const ResultCallback& callback)
|
| + : file_path_(dmg_file), callback_(callback) {
|
| + DCHECK(callback);
|
| }
|
|
|
| -SandboxedDMGAnalyzer::~SandboxedDMGAnalyzer() {}
|
| -
|
| void SandboxedDMGAnalyzer::Start() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| +
|
| base::PostTaskWithTraits(
|
| - FROM_HERE, base::TaskTraits()
|
| - .MayBlock()
|
| - .WithPriority(base::TaskPriority::BACKGROUND)
|
| - .WithShutdownBehavior(
|
| - base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
|
| - base::Bind(&SandboxedDMGAnalyzer::OpenDMGFile, this));
|
| + FROM_HERE,
|
| + base::TaskTraits()
|
| + .MayBlock()
|
| + .WithPriority(base::TaskPriority::BACKGROUND)
|
| + .WithShutdownBehavior(
|
| + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
|
| + base::Bind(&SandboxedDMGAnalyzer::PrepareFileToAnalyze, this));
|
| }
|
|
|
| -void SandboxedDMGAnalyzer::OpenDMGFile() {
|
| - file_.Initialize(file_path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
| - if (!file_.IsValid()) {
|
| - DLOG(ERROR) << "Could not open DMG file at path " << file_path_.value();
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&SandboxedDMGAnalyzer::OnAnalysisFinished, this,
|
| - zip_analyzer::Results()));
|
| +SandboxedDMGAnalyzer::~SandboxedDMGAnalyzer() = default;
|
| +
|
| +void SandboxedDMGAnalyzer::PrepareFileToAnalyze() {
|
| + base::File file(file_path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
| +
|
| + if (!file.IsValid()) {
|
| + DLOG(ERROR) << "Could not open file: " << file_path_.value();
|
| + ReportFileFailure();
|
| return;
|
| }
|
|
|
| - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&SandboxedDMGAnalyzer::StartAnalysis,
|
| - this));
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&SandboxedDMGAnalyzer::AnalyzeFile, this,
|
| + base::Passed(&file)));
|
| }
|
|
|
| -void SandboxedDMGAnalyzer::StartAnalysis() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +void SandboxedDMGAnalyzer::ReportFileFailure() {
|
| + DCHECK(!utility_process_mojo_client_);
|
|
|
| - content::UtilityProcessHost* utility_process_host =
|
| - content::UtilityProcessHost::Create(
|
| - this, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
|
| -
|
| - utility_process_host->SetName(l10n_util::GetStringUTF16(
|
| - IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME));
|
| - utility_process_host->Send(
|
| - new ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection(
|
| - IPC::TakePlatformFileForTransit(std::move(file_))));
|
| + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(callback_, Results()));
|
| }
|
|
|
| -void SandboxedDMGAnalyzer::OnProcessCrashed(int exit_code) {
|
| - OnAnalysisFinished(zip_analyzer::Results());
|
| -}
|
| +void SandboxedDMGAnalyzer::AnalyzeFile(base::File file) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(!utility_process_mojo_client_);
|
|
|
| -void SandboxedDMGAnalyzer::OnProcessLaunchFailed(int error_code) {
|
| - OnAnalysisFinished(zip_analyzer::Results());
|
| -}
|
| + utility_process_mojo_client_ = base::MakeUnique<
|
| + content::UtilityProcessMojoClient<chrome::mojom::SafeArchiveAnalyzer>>(
|
| + l10n_util::GetStringUTF16(
|
| + IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME));
|
| + utility_process_mojo_client_->set_error_callback(
|
| + base::Bind(&SandboxedDMGAnalyzer::AnalyzeFileDone, this, Results()));
|
|
|
| -bool SandboxedDMGAnalyzer::OnMessageReceived(const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(SandboxedDMGAnalyzer, message)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished,
|
| - OnAnalysisFinished)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| + utility_process_mojo_client_->Start();
|
| +
|
| + utility_process_mojo_client_->service()->AnalyzeDmgFile(
|
| + std::move(file),
|
| + base::Bind(&SandboxedDMGAnalyzer::AnalyzeFileDone, this));
|
| }
|
|
|
| -void SandboxedDMGAnalyzer::OnAnalysisFinished(
|
| - const zip_analyzer::Results& results) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| - if (callback_called_)
|
| - return;
|
| +void SandboxedDMGAnalyzer::AnalyzeFileDone(const Results& results) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - callback_called_ = true;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback_, results));
|
| + utility_process_mojo_client_.reset();
|
| + callback_.Run(results);
|
| }
|
|
|
| } // namespace safe_browsing
|
|
|