Chromium Code Reviews| 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..040adbd4b648239e885478335fd55842d5d33407 |
| --- /dev/null |
| +++ b/content/browser/android/download_process_host.cc |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 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 |
|
svaldez
2016/01/25 15:33:43
Is this actually a Sandboxed process? (We're creat
qinmin
2016/01/25 22:48:23
No. Unfortunately, BrowserChildProcessHost::Launch
|
| + : 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_) |
|
svaldez
2016/01/25 15:33:43
Possibly crash if StartProcess is called again.
qinmin
2016/01/25 22:48:23
This function will be called when the first time a
|
| + 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(); |
|
asanka
2016/01/25 16:44:50
Do you intend for more than one browser process in
qinmin
2016/01/25 22:48:23
Yes, the download process can outlive chrome. As a
|
| + 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 |