[email protected] | 232ed46 | 2012-05-03 20:30:43 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_ |
| 6 | #define CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/global_descriptors_posix.h" |
| 13 | #include "base/process_util.h" |
| 14 | #include "base/synchronization/lock.h" |
| 15 | #include "content/public/browser/zygote_host_linux.h" |
| 16 | |
| 17 | template<typename Type> |
| 18 | struct DefaultSingletonTraits; |
| 19 | |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 20 | class CONTENT_EXPORT ZygoteHostImpl : public content::ZygoteHost { |
| 21 | public: |
| 22 | // Returns the singleton instance. |
| 23 | static ZygoteHostImpl* GetInstance(); |
| 24 | |
| 25 | void Init(const std::string& sandbox_cmd); |
| 26 | |
| 27 | // Tries to start a process of type indicated by process_type. |
| 28 | // Returns its pid on success, otherwise |
| 29 | // base::kNullProcessHandle; |
| 30 | pid_t ForkRequest(const std::vector<std::string>& command_line, |
| 31 | const base::GlobalDescriptors::Mapping& mapping, |
| 32 | const std::string& process_type); |
| 33 | void EnsureProcessTerminated(pid_t process); |
| 34 | |
| 35 | // Get the termination status (and, optionally, the exit code) of |
| 36 | // the process. |exit_code| is set to the exit code of the child |
| 37 | // process. (|exit_code| may be NULL.) |
| 38 | base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, |
| 39 | int* exit_code); |
| 40 | |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 41 | // ZygoteHost implementation: |
| 42 | virtual pid_t GetPid() const OVERRIDE; |
[email protected] | 52356d2 | 2012-02-29 18:34:20 | [diff] [blame] | 43 | virtual pid_t GetSandboxHelperPid() const OVERRIDE; |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 44 | virtual int GetSandboxStatus() const OVERRIDE; |
| 45 | virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle, |
| 46 | int score) OVERRIDE; |
[email protected] | 232ed46 | 2012-05-03 20:30:43 | [diff] [blame] | 47 | virtual void AdjustLowMemoryMargin(int64 margin_mb) OVERRIDE; |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | friend struct DefaultSingletonTraits<ZygoteHostImpl>; |
| 51 | ZygoteHostImpl(); |
| 52 | virtual ~ZygoteHostImpl(); |
| 53 | |
| 54 | ssize_t ReadReply(void* buf, size_t buflen); |
| 55 | |
| 56 | int control_fd_; // the socket to the zygote |
| 57 | // A lock protecting all communication with the zygote. This lock must be |
| 58 | // acquired before sending a command and released after the result has been |
| 59 | // received. |
| 60 | base::Lock control_lock_; |
| 61 | pid_t pid_; |
| 62 | bool init_; |
| 63 | bool using_suid_sandbox_; |
| 64 | std::string sandbox_binary_; |
| 65 | bool have_read_sandbox_status_word_; |
| 66 | int sandbox_status_; |
| 67 | }; |
| 68 | |
| 69 | #endif // CONTENT_BROWSER_ZYGOTE_HOST_IMPL_LINUX_H_ |