1 // Copyright (c) 2012 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_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ 6 #define CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ 7 8 #include <unistd.h> 9 10 #include <string> 11 #include <vector> 12 13 namespace content { 14 15 // The ZygoteForkDelegate allows the Chrome Linux zygote to delegate 16 // fork operations to another class that knows how to do some 17 // specialized version of fork. 18 class ZygoteForkDelegate { 19 public: 20 // A ZygoteForkDelegate is created during Chrome linux zygote 21 // initialization, and provides "fork()" functionality as an 22 // alternative to forking the zygote. A new delegate is passed in 23 // as an argument to ZygoteMain(). 24 virtual ~ZygoteForkDelegate() {} 25 26 // Initialization happens in the zygote after it has been 27 // started by ZygoteMain. 28 virtual void Init(int sandboxdesc) = 0; 29 30 // After Init, supply a UMA_HISTOGRAM_ENUMERATION the delegate 31 // would like to supply on the first fork. 32 virtual void InitialUMA(std::string* uma_name, 33 int* uma_sample, 34 int* uma_boundary_value) = 0; 35 36 // Returns 'true' if the delegate would like to handle a given fork 37 // request. Otherwise returns false. Optionally, fills in uma_name et al 38 // with a report the helper wants to make via UMA_HISTOGRAM_ENUMERATION. 39 virtual bool CanHelp(const std::string& process_type, std::string* uma_name, 40 int* uma_sample, int* uma_boundary_value) = 0; 41 42 // Delegate forks, returning a -1 on failure. Outside the 43 // suid sandbox, Fork() returns the Linux process ID. Inside 44 // the sandbox, returns a positive integer, with PID discovery 45 // handled by the sandbox. 46 virtual pid_t Fork(const std::vector<int>& fds) = 0; 47 48 // After a successful for, signal the child to indicate that 49 // the child's PID has been received. Also communicate the 50 // channel switch as a part of acknowledgement message. 51 virtual bool AckChild(int fd, const std::string& channel_switch) = 0; 52 }; 53 54 } // namespace content 55 56 #endif // CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_ 57