Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / zygote / zygote_linux.h
blobffea49a0da1081c1335816e82019edfe6d31d2c0
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_ZYGOTE_ZYGOTE_H_
6 #define CONTENT_ZYGOTE_ZYGOTE_H_
8 #include <string>
9 #include <vector>
11 #include "base/containers/small_map.h"
12 #include "base/process/kill.h"
13 #include "base/process/process.h"
15 class Pickle;
16 class PickleIterator;
18 namespace content {
20 class ZygoteForkDelegate;
22 // This is the object which implements the zygote. The ZygoteMain function,
23 // which is called from ChromeMain, simply constructs one of these objects and
24 // runs it.
25 class Zygote {
26 public:
27 Zygote(int sandbox_flags,
28 ZygoteForkDelegate* helper);
29 ~Zygote();
31 bool ProcessRequests();
33 private:
34 struct ZygoteProcessInfo {
35 // Pid from inside the Zygote's PID namespace.
36 base::ProcessHandle internal_pid;
37 // Keeps track of whether or not a process was started from a fork
38 // delegate helper.
39 bool started_from_helper;
41 typedef base::SmallMap< std::map<base::ProcessHandle, ZygoteProcessInfo> >
42 ZygoteProcessMap;
44 // Retrieve a ZygoteProcessInfo from the process_info_map_.
45 // Returns true and write to process_info if |pid| can be found, return
46 // false otherwise.
47 bool GetProcessInfo(base::ProcessHandle pid,
48 ZygoteProcessInfo* process_info);
50 // Returns true if the SUID sandbox is active.
51 bool UsingSUIDSandbox() const;
53 // ---------------------------------------------------------------------------
54 // Requests from the browser...
56 // Read and process a request from the browser. Returns true if we are in a
57 // new process and thus need to unwind back into ChromeMain.
58 bool HandleRequestFromBrowser(int fd);
60 void HandleReapRequest(int fd, const Pickle& pickle, PickleIterator iter);
62 // Get the termination status of |real_pid|. |real_pid| is the PID as it
63 // appears outside of the sandbox.
64 // Return true if it managed to get the termination status and return the
65 // status in |status| and the exit code in |exit_code|.
66 bool GetTerminationStatus(base::ProcessHandle real_pid, bool known_dead,
67 base::TerminationStatus* status,
68 int* exit_code);
70 void HandleGetTerminationStatus(int fd,
71 const Pickle& pickle,
72 PickleIterator iter);
74 // This is equivalent to fork(), except that, when using the SUID sandbox, it
75 // returns the real PID of the child process as it appears outside the
76 // sandbox, rather than returning the PID inside the sandbox. Optionally, it
77 // fills in uma_name et al with a report the helper wants to make via
78 // UMA_HISTOGRAM_ENUMERATION.
79 int ForkWithRealPid(const std::string& process_type,
80 std::vector<int>& fds,
81 const std::string& channel_switch,
82 std::string* uma_name,
83 int* uma_sample,
84 int* uma_boundary_value);
86 // Unpacks process type and arguments from |pickle| and forks a new process.
87 // Returns -1 on error, otherwise returns twice, returning 0 to the child
88 // process and the child process ID to the parent process, like fork().
89 base::ProcessId ReadArgsAndFork(const Pickle& pickle,
90 PickleIterator iter,
91 std::vector<int>& fds,
92 std::string* uma_name,
93 int* uma_sample,
94 int* uma_boundary_value);
96 // Handle a 'fork' request from the browser: this means that the browser
97 // wishes to start a new renderer. Returns true if we are in a new process,
98 // otherwise writes the child_pid back to the browser via |fd|. Writes a
99 // child_pid of -1 on error.
100 bool HandleForkRequest(int fd,
101 const Pickle& pickle,
102 PickleIterator iter,
103 std::vector<int>& fds);
105 bool HandleGetSandboxStatus(int fd,
106 const Pickle& pickle,
107 PickleIterator iter);
109 // The Zygote needs to keep some information about each process. Most
110 // notably what the PID of the process is inside the PID namespace of
111 // the Zygote and whether or not a process was started by the
112 // ZygoteForkDelegate helper.
113 ZygoteProcessMap process_info_map_;
115 const int sandbox_flags_;
116 ZygoteForkDelegate* helper_;
118 // These might be set by helper_->InitialUMA. They supply a UMA enumeration
119 // sample we should report on the first fork.
120 std::string initial_uma_name_;
121 int initial_uma_sample_;
122 int initial_uma_boundary_value_;
125 } // namespace content
127 #endif // CONTENT_ZYGOTE_ZYGOTE_H_