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" |
11 #include "base/process/launch.h" | 11 #include "base/process/launch.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 | 13 |
14 class CommandLine; | 14 class CommandLine; |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 class SandboxedProcessLauncherDelegate; | 17 class SandboxedProcessLauncherDelegate; |
18 | 18 |
19 // Launches a process asynchronously and notifies the client of the process | 19 // Launches a process asynchronously and notifies the client of the process |
20 // handle when it's available. It's used to avoid blocking the calling thread | 20 // handle when it's available. It's used to avoid blocking the calling thread |
21 // on the OS since often it can take > 100 ms to create the process. | 21 // on the OS since often it can take > 100 ms to create the process. |
22 class CONTENT_EXPORT ChildProcessLauncher { | 22 class CONTENT_EXPORT ChildProcessLauncher { |
23 public: | 23 public: |
24 // An interface for receiving callbacks with process-launching status. Will | |
25 // be called on the thread that the ChildProcessLauncher was constructed on. | |
26 // Note that only OnProcessLaunched is required. | |
24 class CONTENT_EXPORT Client { | 27 class CONTENT_EXPORT Client { |
25 public: | 28 public: |
26 // Will be called on the thread that the ChildProcessLauncher was | 29 // Called when the process is launched. |
27 // constructed on. | |
28 virtual void OnProcessLaunched() = 0; | 30 virtual void OnProcessLaunched() = 0; |
29 | 31 |
32 // Called if an error occurs launching the process. | |
33 virtual void OnProcessLaunchFailure() {}; | |
34 | |
30 protected: | 35 protected: |
31 virtual ~Client() {} | 36 virtual ~Client() {} |
32 }; | 37 }; |
33 | 38 |
34 // Launches the process asynchronously, calling the client when the result is | 39 // Launches the process asynchronously, calling the client when the result is |
35 // ready. Deleting this object before the process is created is safe, since | 40 // 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 | 41 // the callback won't be called. If the process is still running by the time |
37 // this object destructs, it will be terminated. | 42 // this object destructs, it will be terminated. |
mef
2014/01/17 16:57:06
I think this comment is out of date, especially re
Drew Haven
2014/01/22 23:14:25
Right. This is an interface now, so it doesn't ta
| |
38 // Takes ownership of cmd_line. | 43 // Takes ownership of cmd_line. |
39 ChildProcessLauncher( | 44 ChildProcessLauncher() {}; |
40 #if defined(OS_WIN) | 45 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 | 46 |
52 // True if the process is being launched and so the handle isn't available. | 47 // True if the process is being launched and so the handle isn't available. |
53 bool IsStarting(); | 48 virtual bool IsStarting() = 0; |
54 | 49 |
55 // Getter for the process handle. Only call after the process has started. | 50 // Getter for the process handle. Only call after the process has started. |
56 base::ProcessHandle GetHandle(); | 51 virtual base::ProcessHandle GetHandle() = 0; |
57 | 52 |
58 // Call this when the child process exits to know what happened to it. | 53 // 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 | 54 // |known_dead| can be true if we already know the process is dead as it can |
60 // help the implemention figure the proper TerminationStatus. | 55 // help the implemention figure the proper TerminationStatus. |
61 // On Linux, the use of |known_dead| is subtle and can be crucial if an | 56 // 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 | 57 // 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 | 58 // 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 | 59 // process will be killed if it was still running. See ZygoteHostImpl for |
65 // more discussion of Linux implementation details. | 60 // more discussion of Linux implementation details. |
66 // |exit_code| is the exit code of the process if it exited (e.g. status from | 61 // |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 | 62 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may |
68 // be NULL. | 63 // be NULL. |
69 base::TerminationStatus GetChildTerminationStatus(bool known_dead, | 64 virtual base::TerminationStatus GetChildTerminationStatus(bool known_dead, |
70 int* exit_code); | 65 int* exit_code) = 0; |
71 | 66 |
72 // Changes whether the process runs in the background or not. Only call | 67 // Changes whether the process runs in the background or not. Only call |
73 // this after the process has started. | 68 // this after the process has started. |
74 void SetProcessBackgrounded(bool background); | 69 virtual void SetProcessBackgrounded(bool background) = 0; |
75 | 70 |
76 // Controls whether the child process should be terminated on browser | 71 // Controls whether the child process should be terminated on browser |
77 // shutdown. | 72 // shutdown. |
78 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 73 virtual void SetTerminateChildOnShutdown(bool terminate_on_shutdown) = 0; |
74 | |
75 // Create a standard ChildProcessLauncher. | |
76 static ChildProcessLauncher* Create( | |
77 #if defined(OS_WIN) | |
78 SandboxedProcessLauncherDelegate* delegate, | |
79 #elif defined(OS_POSIX) | |
80 bool use_zygote, | |
81 const base::EnvironmentMap& environ, | |
82 int ipcfd, | |
83 #endif | |
84 CommandLine* cmd_line, | |
85 int child_process_id, | |
86 Client* client); | |
87 | |
88 #if defined(OS_WIN) | |
89 // Create a ChildProcessLauncher that attempts to create an elevated process. | |
90 static ChildProcessLauncher* CreateElevated( | |
91 CommandLine* cmd_line, | |
92 int child_process_id, | |
93 Client* client); | |
94 #endif | |
79 | 95 |
80 private: | 96 private: |
81 class Context; | |
82 | |
83 scoped_refptr<Context> context_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | 97 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); |
86 }; | 98 }; |
87 | 99 |
88 } // namespace content | 100 } // namespace content |
89 | 101 |
90 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 102 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
OLD | NEW |