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.
5 #ifndef CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_
6 #define CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_
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
{
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() {}
26 // Initialization happens in the zygote after it has been
27 // started by ZygoteMain.
28 virtual void Init(bool sandboxed
,
32 // After Init, supply a UMA_HISTOGRAM_ENUMERATION the delegate
33 // would like to supply on the first fork.
34 virtual void InitialUMA(std::string
* uma_name
,
36 int* uma_boundary_value
) = 0;
38 // Returns 'true' if the delegate would like to handle a given fork
39 // request. Otherwise returns false. Optionally, fills in uma_name et al
40 // with a report the helper wants to make via UMA_HISTOGRAM_ENUMERATION.
41 virtual bool CanHelp(const std::string
& process_type
, std::string
* uma_name
,
42 int* uma_sample
, int* uma_boundary_value
) = 0;
44 // Delegate forks, returning a -1 on failure. Outside the
45 // suid sandbox, Fork() returns the Linux process ID. Inside
46 // the sandbox, returns a positive integer, with PID discovery
47 // handled by the sandbox.
48 virtual pid_t
Fork(const std::vector
<int>& fds
) = 0;
50 // After a successful for, signal the child to indicate that
51 // the child's PID has been received. Also communicate the
52 // channel switch as a part of acknowledgement message.
53 virtual bool AckChild(int fd
, const std::string
& channel_switch
) = 0;
56 } // namespace content
58 #endif // CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_