OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/android/download_process_host.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "content/public/common/child_process_host.h" | |
12 #include "content/public/common/content_switches.h" | |
13 #include "content/public/common/process_type.h" | |
14 #include "content/public/common/sandbox_type.h" | |
15 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
16 #include "ipc/ipc_switches.h" | |
17 | |
18 namespace content { | |
19 | |
20 // Delegate to launch the download child process. | |
21 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
| |
22 : public content::SandboxedProcessLauncherDelegate { | |
23 public: | |
24 DownloadSandboxedProcessLauncherDelegate(content::ChildProcessHost* host) | |
25 : ipc_fd_(host->TakeClientFileDescriptor()) {} | |
26 | |
27 ~DownloadSandboxedProcessLauncherDelegate() override {} | |
28 | |
29 base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); } | |
30 | |
31 private: | |
32 base::ScopedFD ipc_fd_; | |
33 }; | |
34 | |
35 DownloadProcessHost::DownloadProcessHost() : started_(false) {} | |
36 | |
37 DownloadProcessHost::~DownloadProcessHost() {} | |
38 | |
39 bool DownloadProcessHost::StartProcess() { | |
40 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
| |
41 return true; | |
42 started_ = true; | |
43 | |
44 process_.reset(content::BrowserChildProcessHost::Create( | |
45 content::PROCESS_TYPE_DOWNLOAD, this)); | |
46 process_->SetName(base::UTF8ToUTF16(switches::kDownloadProcess)); | |
47 | |
48 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
| |
49 if (channel_id.empty()) | |
50 return false; | |
51 | |
52 const base::CommandLine& browser_command_line = | |
53 *base::CommandLine::ForCurrentProcess(); | |
54 | |
55 base::FilePath exe_path = content::ChildProcessHost::GetChildPath( | |
56 content::ChildProcessHost::CHILD_NORMAL); | |
57 if (exe_path.empty()) { | |
58 NOTREACHED() << "Unable to get download process binary name."; | |
59 return false; | |
60 } | |
61 | |
62 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | |
63 cmd_line->AppendSwitchASCII(switches::kProcessType, | |
64 switches::kDownloadProcess); | |
65 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | |
66 cmd_line->AppendSwitch(switches::kNoSandbox); | |
67 | |
68 process_->Launch( | |
69 new DownloadSandboxedProcessLauncherDelegate(process_->GetHost()), | |
70 cmd_line, false); | |
71 | |
72 return true; | |
73 } | |
74 | |
75 bool DownloadProcessHost::OnMessageReceived(const IPC::Message& message) { | |
76 NOTIMPLEMENTED(); | |
77 return true; | |
78 } | |
79 | |
80 void DownloadProcessHost::OnProcessLaunchFailed() { | |
81 NOTIMPLEMENTED(); | |
82 } | |
83 | |
84 void DownloadProcessHost::OnProcessCrashed(int exit_code) { | |
85 NOTIMPLEMENTED(); | |
86 } | |
87 | |
88 void DownloadProcessHost::OnProcessLaunched() { | |
89 NOTIMPLEMENTED(); | |
90 } | |
91 | |
92 } // namespace content | |
OLD | NEW |