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/memory/scoped_ptr.h" | |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 | 13 |
13 class CommandLine; | 14 class CommandLine; |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 class SandboxedProcessLauncherDelegate; | 17 class SandboxedProcessLauncherDelegate; |
17 | 18 |
18 // Launches a process asynchronously and notifies the client of the process | 19 // Launches a process asynchronously and notifies the client of the process |
19 // 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 |
20 // 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 // | |
23 // Call NewChildProcessLauncher to get the default implementation, | |
24 // which launches a real process. | |
21 class CONTENT_EXPORT ChildProcessLauncher { | 25 class CONTENT_EXPORT ChildProcessLauncher { |
22 public: | 26 public: |
23 class CONTENT_EXPORT Client { | 27 class CONTENT_EXPORT Client { |
24 public: | 28 public: |
25 // Will be called on the thread that the ChildProcessLauncher was | 29 // Will be called on the thread that the ChildProcessLauncher was |
26 // constructed on. | 30 // constructed on. |
27 virtual void OnProcessLaunched() = 0; | 31 virtual void OnProcessLaunched() = 0; |
28 | 32 |
29 protected: | 33 protected: |
30 virtual ~Client() {} | 34 virtual ~Client() {} |
31 }; | 35 }; |
32 | 36 |
33 // Launches the process asynchronously, calling the client when the result is | 37 virtual ~ChildProcessLauncher(); |
34 // ready. Deleting this object before the process is created is safe, since | |
35 // the callback won't be called. If the process is still running by the time | |
36 // this object destructs, it will be terminated. | |
37 // Takes ownership of cmd_line. | |
38 ChildProcessLauncher( | |
39 #if defined(OS_WIN) | |
40 SandboxedProcessLauncherDelegate* delegate, | |
41 #elif defined(OS_POSIX) | |
42 bool use_zygote, | |
43 const base::EnvironmentVector& environ, | |
44 int ipcfd, | |
45 #endif | |
46 CommandLine* cmd_line, | |
47 int child_process_id, | |
48 Client* client); | |
49 ~ChildProcessLauncher(); | |
50 | 38 |
51 // True if the process is being launched and so the handle isn't available. | 39 // True if the process is being launched and so the handle isn't available. |
52 bool IsStarting(); | 40 virtual bool IsStarting() = 0; |
53 | 41 |
54 // Getter for the process handle. Only call after the process has started. | 42 // Getter for the process handle. Only call after the process has started. |
55 base::ProcessHandle GetHandle(); | 43 virtual base::ProcessHandle GetHandle() = 0; |
56 | 44 |
57 // Call this when the child process exits to know what happened to it. | 45 // Call this when the child process exits to know what happened to it. |
58 // |known_dead| can be true if we already know the process is dead as it can | 46 // |known_dead| can be true if we already know the process is dead as it can |
59 // help the implemention figure the proper TerminationStatus. | 47 // help the implemention figure the proper TerminationStatus. |
60 // |exit_code| is the exit code of the process if it exited (e.g. status from | 48 // |exit_code| is the exit code of the process if it exited (e.g. status from |
61 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may | 49 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may |
62 // be NULL. | 50 // be NULL. |
63 base::TerminationStatus GetChildTerminationStatus(bool known_dead, | 51 virtual base::TerminationStatus GetChildTerminationStatus(bool known_dead, |
64 int* exit_code); | 52 int* exit_code) = 0; |
65 | 53 |
66 // Changes whether the process runs in the background or not. Only call | 54 // Changes whether the process runs in the background or not. Only call |
67 // this after the process has started. | 55 // this after the process has started. |
68 void SetProcessBackgrounded(bool background); | 56 virtual void SetProcessBackgrounded(bool background) = 0; |
69 | 57 |
70 // Controls whether the child process should be terminated on browser | 58 // Controls whether the child process should be terminated on browser |
71 // shutdown. | 59 // shutdown. |
72 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 60 virtual void SetTerminateChildOnShutdown(bool terminate_on_shutdown) = 0; |
61 }; | |
73 | 62 |
74 private: | 63 // Launches the process asynchronously, calling the client when the result is |
75 class Context; | 64 // ready. Deleting this object before the process is created is safe, since |
76 | 65 // the callback won't be called. If the process is still running by the time |
77 scoped_refptr<Context> context_; | 66 // this object destructs, it will be terminated. |
78 | 67 // Takes ownership of cmd_line. |
79 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | 68 scoped_ptr<ChildProcessLauncher> NewChildProcessLauncher( |
Matt Perry
2013/06/06 21:01:27
nit: I generally prefer factory methods like this
Jeffrey Yasskin
2013/06/06 21:06:56
I have no problem with doing this, but I'd like ja
| |
80 }; | 69 #if defined(OS_WIN) |
70 SandboxedProcessLauncherDelegate* delegate, | |
71 #elif defined(OS_POSIX) | |
72 bool use_zygote, | |
73 const base::EnvironmentVector& environ, | |
74 int ipcfd, | |
75 #endif | |
76 CommandLine* cmd_line, | |
77 int child_process_id, | |
78 ChildProcessLauncher::Client* client); | |
81 | 79 |
82 } // namespace content | 80 } // namespace content |
83 | 81 |
84 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 82 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
OLD | NEW |