Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: content/browser/zygote_host_impl_linux.h

Issue 9463029: Add an API around zygoteHost so that chrome doesn't reach into the internal content implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix clang Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/child_process_launcher.cc ('k') | content/browser/zygote_host_impl_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_ 5 #ifndef CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_
6 #define CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_ 6 #define CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_
7 #pragma once 7 #pragma once
8 8
9 #include <unistd.h>
10
11 #include <string> 9 #include <string>
12 #include <vector> 10 #include <vector>
13 11
14 #include "base/global_descriptors_posix.h" 12 #include "base/global_descriptors_posix.h"
15 #include "base/process.h"
16 #include "base/process_util.h" 13 #include "base/process_util.h"
17 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
18 #include "content/common/content_export.h" 15 #include "content/public/browser/zygote_host_linux.h"
19 16
20 template<typename Type> 17 template<typename Type>
21 struct DefaultSingletonTraits; 18 struct DefaultSingletonTraits;
22 19
23 static const char kZygoteMagic[] = "ZYGOTE_OK"; 20 static const char kZygoteMagic[] = "ZYGOTE_OK";
24 21
25 // http://code.google.com/p/chromium/wiki/LinuxZygote 22 class CONTENT_EXPORT ZygoteHostImpl : public content::ZygoteHost {
26
27 // The zygote host is the interface, in the browser process, to the zygote
28 // process.
29 class CONTENT_EXPORT ZygoteHost {
30 public: 23 public:
31 // Returns the singleton instance. 24 // Returns the singleton instance.
32 static ZygoteHost* GetInstance(); 25 static ZygoteHostImpl* GetInstance();
33 26
34 void Init(const std::string& sandbox_cmd); 27 void Init(const std::string& sandbox_cmd);
35 28
36 // Tries to start a process of type indicated by process_type. 29 // Tries to start a process of type indicated by process_type.
37 // Returns its pid on success, otherwise 30 // Returns its pid on success, otherwise
38 // base::kNullProcessHandle; 31 // base::kNullProcessHandle;
39 pid_t ForkRequest(const std::vector<std::string>& command_line, 32 pid_t ForkRequest(const std::vector<std::string>& command_line,
40 const base::GlobalDescriptors::Mapping& mapping, 33 const base::GlobalDescriptors::Mapping& mapping,
41 const std::string& process_type); 34 const std::string& process_type);
42 void EnsureProcessTerminated(pid_t process); 35 void EnsureProcessTerminated(pid_t process);
43 36
44 // Get the termination status (and, optionally, the exit code) of 37 // Get the termination status (and, optionally, the exit code) of
45 // the process. |exit_code| is set to the exit code of the child 38 // the process. |exit_code| is set to the exit code of the child
46 // process. (|exit_code| may be NULL.) 39 // process. (|exit_code| may be NULL.)
47 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, 40 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle,
48 int* exit_code); 41 int* exit_code);
49 42
50 // These are the command codes used on the wire between the browser and the 43 // These are the command codes used on the wire between the browser and the
51 // zygote. 44 // zygote.
52 enum { 45 enum {
53 kCmdFork = 0, // Fork off a new renderer. 46 kCmdFork = 0, // Fork off a new renderer.
54 kCmdReap = 1, // Reap a renderer child. 47 kCmdReap = 1, // Reap a renderer child.
55 kCmdGetTerminationStatus = 2, // Check what happend to a child process. 48 kCmdGetTerminationStatus = 2, // Check what happend to a child process.
56 kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox* 49 kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox*
57 }; 50 };
58 51
59 // These form a bitmask which describes the conditions of the sandbox that 52 // ZygoteHost implementation:
60 // the zygote finds itself in. 53 virtual pid_t GetPid() const OVERRIDE;
61 enum { 54 virtual int GetSandboxStatus() const OVERRIDE;
62 kSandboxSUID = 1 << 0, // SUID sandbox active 55 virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
63 kSandboxPIDNS = 1 << 1, // SUID sandbox is using the PID namespace 56 int score) OVERRIDE;
64 kSandboxNetNS = 1 << 2, // SUID sandbox is using the network namespace
65 kSandboxSeccomp = 1 << 3, // seccomp sandbox active.
66 };
67
68 pid_t pid() const { return pid_; }
69
70 // Returns an int which is a bitmask of kSandbox* values. Only valid after
71 // the first render has been forked.
72 int sandbox_status() const {
73 if (have_read_sandbox_status_word_)
74 return sandbox_status_;
75 return 0;
76 }
77
78 // Adjust the OOM score of the given renderer's PID. The allowed
79 // range for the score is [0, 1000], where higher values are more
80 // likely to be killed by the OOM killer.
81 void AdjustRendererOOMScore(base::ProcessHandle process_handle, int score);
82 57
83 private: 58 private:
84 friend struct DefaultSingletonTraits<ZygoteHost>; 59 friend struct DefaultSingletonTraits<ZygoteHostImpl>;
85 ZygoteHost(); 60 ZygoteHostImpl();
86 ~ZygoteHost(); 61 virtual ~ZygoteHostImpl();
87 62
88 ssize_t ReadReply(void* buf, size_t buflen); 63 ssize_t ReadReply(void* buf, size_t buflen);
89 64
90 int control_fd_; // the socket to the zygote 65 int control_fd_; // the socket to the zygote
91 // A lock protecting all communication with the zygote. This lock must be 66 // A lock protecting all communication with the zygote. This lock must be
92 // acquired before sending a command and released after the result has been 67 // acquired before sending a command and released after the result has been
93 // received. 68 // received.
94 base::Lock control_lock_; 69 base::Lock control_lock_;
95 pid_t pid_; 70 pid_t pid_;
96 bool init_; 71 bool init_;
97 bool using_suid_sandbox_; 72 bool using_suid_sandbox_;
98 std::string sandbox_binary_; 73 std::string sandbox_binary_;
99 bool have_read_sandbox_status_word_; 74 bool have_read_sandbox_status_word_;
100 int sandbox_status_; 75 int sandbox_status_;
101 }; 76 };
102 77
103 #endif // CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_ 78 #endif // CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.cc ('k') | content/browser/zygote_host_impl_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698