IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / zygote_host / zygote_host_impl_linux.h
blob95591a4b1be800295d375de9bd734fa50cbf5167
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_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
6 #define CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
8 #include <string>
9 #include <vector>
11 #include "base/pickle.h"
12 #include "base/process/kill.h"
13 #include "base/synchronization/lock.h"
14 #include "content/public/browser/file_descriptor_info.h"
15 #include "content/public/browser/zygote_host_linux.h"
17 template<typename Type>
18 struct DefaultSingletonTraits;
20 namespace content {
22 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost {
23 public:
24 // Returns the singleton instance.
25 static ZygoteHostImpl* GetInstance();
27 void Init(const std::string& sandbox_cmd);
29 // Tries to start a process of type indicated by process_type.
30 // Returns its pid on success, otherwise
31 // base::kNullProcessHandle;
32 pid_t ForkRequest(const std::vector<std::string>& command_line,
33 const std::vector<FileDescriptorInfo>& mapping,
34 const std::string& process_type);
35 void EnsureProcessTerminated(pid_t process);
37 // Get the termination status (and, optionally, the exit code) of
38 // the process. |exit_code| is set to the exit code of the child
39 // process. (|exit_code| may be NULL.)
40 // Unfortunately the Zygote can not accurately figure out if a process
41 // is already dead without waiting synchronously for it.
42 // |known_dead| should be set to true when we already know that the process
43 // is dead. When |known_dead| is false, processes could be seen as
44 // still running, even when they're not. When |known_dead| is true, the
45 // process will be SIGKILL-ed first (which should have no effect if it was
46 // really dead). This is to prevent a waiting waitpid() from blocking in
47 // a single-threaded Zygote. See crbug.com/157458.
48 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle,
49 bool known_dead,
50 int* exit_code);
52 // ZygoteHost implementation:
53 virtual pid_t GetPid() const OVERRIDE;
54 virtual pid_t GetSandboxHelperPid() const OVERRIDE;
55 virtual int GetSandboxStatus() const OVERRIDE;
56 virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
57 int score) OVERRIDE;
59 private:
60 friend struct DefaultSingletonTraits<ZygoteHostImpl>;
62 ZygoteHostImpl();
63 virtual ~ZygoteHostImpl();
65 // Sends |data| to the zygote via |control_fd_|. If |fds| is non-NULL, the
66 // included file descriptors will also be passed. The caller is responsible
67 // for acquiring |control_lock_|.
68 bool SendMessage(const Pickle& data, const std::vector<int>* fds);
70 ssize_t ReadReply(void* buf, size_t buflen);
72 int control_fd_; // the socket to the zygote
73 // A lock protecting all communication with the zygote. This lock must be
74 // acquired before sending a command and released after the result has been
75 // received.
76 base::Lock control_lock_;
77 pid_t pid_;
78 bool init_;
79 bool using_suid_sandbox_;
80 std::string sandbox_binary_;
81 bool have_read_sandbox_status_word_;
82 int sandbox_status_;
85 } // namespace content
87 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_