OLD | NEW |
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_CHILD_PROCESS_LAUNCHER_H_ | 5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 protected: | 30 protected: |
31 virtual ~Client() {} | 31 virtual ~Client() {} |
32 }; | 32 }; |
33 | 33 |
34 // Launches the process asynchronously, calling the client when the result is | 34 // Launches the process asynchronously, calling the client when the result is |
35 // ready. Deleting this object before the process is created is safe, since | 35 // ready. Deleting this object before the process is created is safe, since |
36 // the callback won't be called. If the process is still running by the time | 36 // the callback won't be called. If the process is still running by the time |
37 // this object destructs, it will be terminated. | 37 // this object destructs, it will be terminated. |
38 // Takes ownership of cmd_line. | 38 // Takes ownership of cmd_line. |
39 ChildProcessLauncher( | 39 ChildProcessLauncher() {}; |
40 #if defined(OS_WIN) | 40 virtual ~ChildProcessLauncher() {}; |
41 SandboxedProcessLauncherDelegate* delegate, | |
42 #elif defined(OS_POSIX) | |
43 bool use_zygote, | |
44 const base::EnvironmentMap& environ, | |
45 int ipcfd, | |
46 #endif | |
47 CommandLine* cmd_line, | |
48 int child_process_id, | |
49 Client* client); | |
50 ~ChildProcessLauncher(); | |
51 | 41 |
52 // True if the process is being launched and so the handle isn't available. | 42 // True if the process is being launched and so the handle isn't available. |
53 bool IsStarting(); | 43 virtual bool IsStarting() = 0; |
54 | 44 |
55 // Getter for the process handle. Only call after the process has started. | 45 // Getter for the process handle. Only call after the process has started. |
56 base::ProcessHandle GetHandle(); | 46 virtual base::ProcessHandle GetHandle() = 0; |
57 | 47 |
58 // Call this when the child process exits to know what happened to it. | 48 // Call this when the child process exits to know what happened to it. |
59 // |known_dead| can be true if we already know the process is dead as it can | 49 // |known_dead| can be true if we already know the process is dead as it can |
60 // help the implemention figure the proper TerminationStatus. | 50 // help the implemention figure the proper TerminationStatus. |
61 // On Linux, the use of |known_dead| is subtle and can be crucial if an | 51 // On Linux, the use of |known_dead| is subtle and can be crucial if an |
62 // accurate status is important. With |known_dead| set to false, a dead | 52 // accurate status is important. With |known_dead| set to false, a dead |
63 // process could be seen as running. With |known_dead| set to true, the | 53 // process could be seen as running. With |known_dead| set to true, the |
64 // process will be killed if it was still running. See ZygoteHostImpl for | 54 // process will be killed if it was still running. See ZygoteHostImpl for |
65 // more discussion of Linux implementation details. | 55 // more discussion of Linux implementation details. |
66 // |exit_code| is the exit code of the process if it exited (e.g. status from | 56 // |exit_code| is the exit code of the process if it exited (e.g. status from |
67 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may | 57 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may |
68 // be NULL. | 58 // be NULL. |
69 base::TerminationStatus GetChildTerminationStatus(bool known_dead, | 59 virtual base::TerminationStatus GetChildTerminationStatus(bool known_dead, |
70 int* exit_code); | 60 int* exit_code) = 0; |
71 | 61 |
72 // Changes whether the process runs in the background or not. Only call | 62 // Changes whether the process runs in the background or not. Only call |
73 // this after the process has started. | 63 // this after the process has started. |
74 void SetProcessBackgrounded(bool background); | 64 virtual void SetProcessBackgrounded(bool background) = 0; |
75 | 65 |
76 // Controls whether the child process should be terminated on browser | 66 // Controls whether the child process should be terminated on browser |
77 // shutdown. | 67 // shutdown. |
78 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 68 virtual void SetTerminateChildOnShutdown(bool terminate_on_shutdown) = 0; |
| 69 |
| 70 // Create a standard ChildProcessLauncher. |
| 71 static ChildProcessLauncher* Create( |
| 72 #if defined(OS_WIN) |
| 73 SandboxedProcessLauncherDelegate* delegate, |
| 74 #elif defined(OS_POSIX) |
| 75 bool use_zygote, |
| 76 const base::EnvironmentMap& environ, |
| 77 int ipcfd, |
| 78 #endif |
| 79 CommandLine* cmd_line, |
| 80 int child_process_id, |
| 81 Client* client); |
| 82 |
| 83 #if defined(OS_WIN) |
| 84 // Create a ChildProcessLauncher that attempts to create an elevated process. |
| 85 static ChildProcessLauncher* CreateElevated( |
| 86 CommandLine* cmd_line, |
| 87 int child_process_id, |
| 88 Client* client); |
| 89 #endif |
79 | 90 |
80 private: | 91 private: |
81 class Context; | |
82 | |
83 scoped_refptr<Context> context_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | 92 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); |
86 }; | 93 }; |
87 | 94 |
88 } // namespace content | 95 } // namespace content |
89 | 96 |
90 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 97 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
OLD | NEW |