| Index: content/browser/android/download_process_host.cc
|
| diff --git a/content/browser/android/download_process_host.cc b/content/browser/android/download_process_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..06dfb6c720013d6fbb91b87043183dd1002126c7
|
| --- /dev/null
|
| +++ b/content/browser/android/download_process_host.cc
|
| @@ -0,0 +1,92 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/android/download_process_host.h"
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "content/public/common/child_process_host.h"
|
| +#include "content/public/common/content_switches.h"
|
| +#include "content/public/common/process_type.h"
|
| +#include "content/public/common/sandbox_type.h"
|
| +#include "content/public/common/sandboxed_process_launcher_delegate.h"
|
| +#include "ipc/ipc_switches.h"
|
| +
|
| +namespace content {
|
| +
|
| +// Delegate to launch the download child process.
|
| +class DownloadSandboxedProcessLauncherDelegate
|
| + : public content::SandboxedProcessLauncherDelegate {
|
| + public:
|
| + DownloadSandboxedProcessLauncherDelegate(content::ChildProcessHost* host)
|
| + : ipc_fd_(host->TakeClientFileDescriptor()) {}
|
| +
|
| + ~DownloadSandboxedProcessLauncherDelegate() override {}
|
| +
|
| + base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); }
|
| +
|
| + private:
|
| + base::ScopedFD ipc_fd_;
|
| +};
|
| +
|
| +DownloadProcessHost::DownloadProcessHost() : started_(false) {}
|
| +
|
| +DownloadProcessHost::~DownloadProcessHost() {}
|
| +
|
| +bool DownloadProcessHost::StartProcess() {
|
| + if (started_)
|
| + return true;
|
| + started_ = true;
|
| +
|
| + process_.reset(content::BrowserChildProcessHost::Create(
|
| + content::PROCESS_TYPE_DOWNLOAD, this));
|
| + process_->SetName(base::UTF8ToUTF16(switches::kDownloadProcess));
|
| +
|
| + std::string channel_id = process_->GetHost()->CreateChannel();
|
| + if (channel_id.empty())
|
| + return false;
|
| +
|
| + const base::CommandLine& browser_command_line =
|
| + *base::CommandLine::ForCurrentProcess();
|
| +
|
| + base::FilePath exe_path = content::ChildProcessHost::GetChildPath(
|
| + content::ChildProcessHost::CHILD_NORMAL);
|
| + if (exe_path.empty()) {
|
| + NOTREACHED() << "Unable to get download process binary name.";
|
| + return false;
|
| + }
|
| +
|
| + base::CommandLine* cmd_line = new base::CommandLine(exe_path);
|
| + cmd_line->AppendSwitchASCII(switches::kProcessType,
|
| + switches::kDownloadProcess);
|
| + cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
|
| + cmd_line->AppendSwitch(switches::kNoSandbox);
|
| +
|
| + process_->Launch(
|
| + new DownloadSandboxedProcessLauncherDelegate(process_->GetHost()),
|
| + cmd_line, false);
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool DownloadProcessHost::OnMessageReceived(const IPC::Message& message) {
|
| + NOTIMPLEMENTED();
|
| + return true;
|
| +}
|
| +
|
| +void DownloadProcessHost::OnProcessLaunchFailed() {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +void DownloadProcessHost::OnProcessCrashed(int exit_code) {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +void DownloadProcessHost::OnProcessLaunched() {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +} // namespace content
|
|
|