Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/browser/zygote_host/zygote_host_impl_linux.h

Issue 148443006: Linux: tear down Zygote at browser shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't call TearDown() while holding child_tracking_lock_. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ 5 #ifndef CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
6 #define CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ 6 #define CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
7 7
8 #include <set>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/pickle.h" 12 #include "base/pickle.h"
12 #include "base/process/kill.h" 13 #include "base/process/kill.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "content/public/browser/file_descriptor_info.h" 15 #include "content/public/browser/file_descriptor_info.h"
15 #include "content/public/browser/zygote_host_linux.h" 16 #include "content/public/browser/zygote_host_linux.h"
16 17
17 template<typename Type> 18 template<typename Type>
18 struct DefaultSingletonTraits; 19 struct DefaultSingletonTraits;
19 20
20 namespace content { 21 namespace content {
21 22
22 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost { 23 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost {
23 public: 24 public:
24 // Returns the singleton instance. 25 // Returns the singleton instance.
25 static ZygoteHostImpl* GetInstance(); 26 static ZygoteHostImpl* GetInstance();
26 27
27 void Init(const std::string& sandbox_cmd); 28 void Init(const std::string& sandbox_cmd);
28 29
30 // After the last known Zygote child exits, notify the Zygote to exit.
31 void TearDownAfterLastChild();
32
29 // Tries to start a process of type indicated by process_type. 33 // Tries to start a process of type indicated by process_type.
30 // Returns its pid on success, otherwise 34 // Returns its pid on success, otherwise
31 // base::kNullProcessHandle; 35 // base::kNullProcessHandle;
32 pid_t ForkRequest(const std::vector<std::string>& command_line, 36 pid_t ForkRequest(const std::vector<std::string>& command_line,
33 const std::vector<FileDescriptorInfo>& mapping, 37 const std::vector<FileDescriptorInfo>& mapping,
34 const std::string& process_type); 38 const std::string& process_type);
35 void EnsureProcessTerminated(pid_t process); 39 void EnsureProcessTerminated(pid_t process);
36 40
37 // Get the termination status (and, optionally, the exit code) of 41 // Get the termination status (and, optionally, the exit code) of
38 // the process. |exit_code| is set to the exit code of the child 42 // the process. |exit_code| is set to the exit code of the child
(...skipping 16 matching lines...) Expand all
55 virtual int GetSandboxStatus() const OVERRIDE; 59 virtual int GetSandboxStatus() const OVERRIDE;
56 virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle, 60 virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
57 int score) OVERRIDE; 61 int score) OVERRIDE;
58 62
59 private: 63 private:
60 friend struct DefaultSingletonTraits<ZygoteHostImpl>; 64 friend struct DefaultSingletonTraits<ZygoteHostImpl>;
61 65
62 ZygoteHostImpl(); 66 ZygoteHostImpl();
63 virtual ~ZygoteHostImpl(); 67 virtual ~ZygoteHostImpl();
64 68
69 // Notify the Zygote to exit immediately. This object should not be
70 // used afterwards.
71 void TearDown();
72
73 // Should be called every time a Zygote child is born.
74 void ZygoteChildBorn(pid_t process);
75
76 // Should be called every time a Zygote child died.
77 void ZygoteChildDied(pid_t process);
78
65 // Sends |data| to the zygote via |control_fd_|. If |fds| is non-NULL, the 79 // 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 80 // included file descriptors will also be passed. The caller is responsible
67 // for acquiring |control_lock_|. 81 // for acquiring |control_lock_|.
68 bool SendMessage(const Pickle& data, const std::vector<int>* fds); 82 bool SendMessage(const Pickle& data, const std::vector<int>* fds);
69 83
70 ssize_t ReadReply(void* buf, size_t buflen); 84 ssize_t ReadReply(void* buf, size_t buflen);
71 85
72 int control_fd_; // the socket to the zygote 86 int control_fd_; // the socket to the zygote
73 // A lock protecting all communication with the zygote. This lock must be 87 // 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 88 // acquired before sending a command and released after the result has been
75 // received. 89 // received.
76 base::Lock control_lock_; 90 base::Lock control_lock_;
77 pid_t pid_; 91 pid_t pid_;
78 bool init_; 92 bool init_;
79 bool using_suid_sandbox_; 93 bool using_suid_sandbox_;
80 std::string sandbox_binary_; 94 std::string sandbox_binary_;
81 bool have_read_sandbox_status_word_; 95 bool have_read_sandbox_status_word_;
82 int sandbox_status_; 96 int sandbox_status_;
97 // A lock protecting list_of_running_zygote_children_ and
98 // should_teardown_after_last_child_exits_.
99 base::Lock child_tracking_lock_;
100 std::set<pid_t> list_of_running_zygote_children_;
101 bool should_teardown_after_last_child_exits_;
83 }; 102 };
84 103
85 } // namespace content 104 } // namespace content
86 105
87 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ 106 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/zygote_host/zygote_host_impl_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698