OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ |
| 6 #define CONTENT_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <unistd.h> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 |
| 13 class ZygoteForkDelegate { |
| 14 public: |
| 15 // A ZygoteForkDelegate is created during Chrome linux zygote |
| 16 // initialization, and provides "fork()" functionality with |
| 17 // as an alternative to forking the zygote. A new delegate is |
| 18 // passed in as an argument to ZygoteMain(). |
| 19 ZygoteForkDelegate() {} |
| 20 virtual ~ZygoteForkDelegate() {} |
| 21 // Initialization happens in the zygote after it has been |
| 22 // started by ZygoteMain. |
| 23 virtual void Init(const bool sandboxed, |
| 24 const int browserdesc, |
| 25 const int sandboxdesc) = 0; |
| 26 // Returns 'true' if the delegate would like to handle a given |
| 27 // fork request. Otherwise returns false. |
| 28 virtual bool CanHelp(const std::string& process_type) = 0; |
| 29 // Delegate forks, returning a -1 on failure. Outside the |
| 30 // suid sandbox, Fork() returns the Linux process ID. Inside |
| 31 // the sandbox, returns a positive integer, with PID discovery |
| 32 // handled by the sandbox. |
| 33 virtual pid_t Fork(const std::vector<int>& fds) = 0; |
| 34 // After a successful for, signal the child to indicate that |
| 35 // the child's PID has been received. Also communicate the |
| 36 // channel switch as a part of acknowledgement message. |
| 37 virtual bool AckChild(const int fd, const std::string& channel_switch) = 0; |
| 38 }; |
| 39 |
| 40 class NullForkDelegate : public ZygoteForkDelegate { |
| 41 public: |
| 42 NullForkDelegate() {} |
| 43 ~NullForkDelegate() {} |
| 44 virtual void Init(const bool sandboxed, |
| 45 const int browserdesc, |
| 46 const int sandboxdesc) {} |
| 47 virtual bool CanHelp(const std::string& process_type) { return false; } |
| 48 virtual pid_t Fork(const std::vector<int>& fds) { return -1; } |
| 49 virtual bool AckChild(const int fd, const std::string& channel_switch) { |
| 50 return false; |
| 51 } |
| 52 }; |
| 53 |
| 54 #endif // CONTENT_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ |
OLD | NEW |