| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 5 #ifndef CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
| 6 #define CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 6 #define CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
| 7 | 7 |
| 8 #include <unistd.h> | |
| 9 | |
| 10 #include <string> | 8 #include <string> |
| 11 #include <vector> | 9 #include <vector> |
| 12 | 10 |
| 11 #include <unistd.h> |
| 12 |
| 13 #include "base/global_descriptors_posix.h" | 13 #include "base/global_descriptors_posix.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 | 15 |
| 16 template<typename Type> | 16 template<typename Type> |
| 17 struct DefaultSingletonTraits; | 17 struct DefaultSingletonTraits; |
| 18 | 18 |
| 19 static const char kZygoteMagic[] = "ZYGOTE_OK"; | |
| 20 | |
| 21 // http://code.google.com/p/chromium/wiki/LinuxZygote | 19 // http://code.google.com/p/chromium/wiki/LinuxZygote |
| 22 | 20 |
| 23 // The zygote host is the interface, in the browser process, to the zygote | 21 // The zygote host is the interface, in the browser process, to the zygote |
| 24 // process. | 22 // process. |
| 25 class ZygoteHost { | 23 class ZygoteHost { |
| 26 public: | 24 public: |
| 27 void Init(const std::string& sandbox_cmd); | 25 ~ZygoteHost(); |
| 28 | 26 |
| 29 pid_t ForkRenderer(const std::vector<std::string>& command_line, | 27 pid_t ForkRenderer(const std::vector<std::string>& command_line, |
| 30 const base::GlobalDescriptors::Mapping& mapping); | 28 const base::GlobalDescriptors::Mapping& mapping); |
| 31 void EnsureProcessTerminated(pid_t process); | 29 void EnsureProcessTerminated(pid_t process); |
| 32 | 30 |
| 33 // Get the termination status (exit code) of the process and return true if | 31 // Get the termination status (exit code) of the process and return true if |
| 34 // the status indicates the process crashed. |child_exited| is set to true | 32 // the status indicates the process crashed. |child_exited| is set to true |
| 35 // iff the child process has terminated. (|child_exited| may be NULL.) | 33 // iff the child process has terminated. (|child_exited| may be NULL.) |
| 36 bool DidProcessCrash(base::ProcessHandle handle, bool* child_exited); | 34 bool DidProcessCrash(base::ProcessHandle handle, bool* child_exited); |
| 37 | 35 |
| 38 // These are the command codes used on the wire between the browser and the | 36 // These are the command codes used on the wire between the browser and the |
| 39 // zygote. | 37 // zygote. |
| 40 enum { | 38 enum { |
| 41 kCmdFork = 0, // Fork off a new renderer. | 39 kCmdFork = 0, // Fork off a new renderer. |
| 42 kCmdReap = 1, // Reap a renderer child. | 40 kCmdReap = 1, // Reap a renderer child. |
| 43 kCmdDidProcessCrash = 2, // Check if child process crashed. | 41 kCmdDidProcessCrash = 2, // Check if child process crashed. |
| 44 }; | 42 }; |
| 45 | 43 |
| 46 pid_t pid() const { return pid_; } | 44 pid_t pid() const { return pid_; } |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 friend struct DefaultSingletonTraits<ZygoteHost>; | 47 friend struct DefaultSingletonTraits<ZygoteHost>; |
| 50 ZygoteHost(); | 48 ZygoteHost(); |
| 51 ~ZygoteHost(); | 49 void LaunchZygoteProcess(); |
| 52 | 50 |
| 53 int control_fd_; // the socket to the zygote | 51 int control_fd_; // the socket to the zygote |
| 54 pid_t pid_; | 52 pid_t pid_; |
| 55 bool init_; | |
| 56 }; | 53 }; |
| 57 | 54 |
| 58 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 55 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
| OLD | NEW |